@@ -7,15 +7,7 @@ var delPromise = Q.denodeify(del);
7
7
var Dgeni = require ( 'dgeni' ) ;
8
8
var _ = require ( 'lodash' ) ;
9
9
10
- var createPackage = function ( shredOptions ) {
11
- var shredder = new Dgeni . Package ( 'doc-shredder' , [
12
- // require('dgeni-packages/base') - doesn't work
13
- ] ) ;
14
- shredder . options = resolveOptions ( shredOptions ) ;
15
- return configure ( shredder ) ;
16
- } ;
17
-
18
- var resolveOptions = function ( shredOptions ) {
10
+ var resolveShredOptions = function ( shredOptions ) {
19
11
return _ . defaults ( { } , shredOptions , {
20
12
basePath : path . resolve ( '.' ) ,
21
13
// read files from any subdir under here
@@ -27,9 +19,20 @@ var resolveOptions = function(shredOptions) {
27
19
} ) ;
28
20
}
29
21
22
+ var resolveMapOptions = function ( mapOptions ) {
23
+ return _ . defaults ( { } , mapOptions , {
24
+ basePath : path . resolve ( '.' ) ,
25
+ // read files from any subdir under here
26
+ sourceDir : "docs" ,
27
+ destDir : "docs" ,
28
+ // whether to include subdirectories when shredding.
29
+ includeSubdirs : true
30
+ } ) ;
31
+ }
32
+
30
33
var shred = function ( shredOptions ) {
31
34
try {
32
- var pkg = createPackage ( shredOptions ) ;
35
+ var pkg = createShredPackage ( shredOptions ) ;
33
36
var dgeni = new Dgeni ( [ pkg ] ) ;
34
37
return dgeni . generate ( ) ;
35
38
} catch ( x ) {
@@ -58,53 +61,41 @@ var shredSingleDir = function(shredOptions, filePath) {
58
61
} ) ;
59
62
}
60
63
64
+ var getShredMap = function ( shredMapOptions ) {
65
+ try {
66
+ var pkg = createShredMapPackage ( shredMapOptions ) ;
67
+ var dgeni = new Dgeni ( [ pkg ] ) ;
68
+ return dgeni . generate ( ) ;
69
+ } catch ( x ) {
70
+ console . log ( x . stack ) ;
71
+ throw x ;
72
+ }
73
+ }
74
+
75
+
61
76
module . exports = {
62
77
shred : shred ,
63
78
shredSingleDir : shredSingleDir ,
64
- createPackage : createPackage ,
65
- resolveOptions : resolveOptions
79
+ resolveShredOptions : resolveShredOptions ,
80
+ getShredMap : getShredMap
66
81
} ;
67
82
68
- function configure ( shredder ) {
69
- var options = shredder . options ;
70
- shredder
71
- . processor ( require ( 'dgeni-packages/base/processors/read-files' ) )
72
- . processor ( require ( 'dgeni-packages/base/processors/write-files' ) )
73
- . factory ( require ( 'dgeni-packages/base/services/writefile' ) )
74
-
75
- // Ugh... Boilerplate that dgeni needs to sequence operations
76
- . processor ( { name : 'reading-files' } )
77
- . processor ( { name : 'files-read' , $runAfter : [ 'reading-files' ] } )
78
- . processor ( { name : 'processing-docs' , $runAfter : [ 'files-read' ] } )
79
- . processor ( { name : 'docs-processed' , $runAfter : [ 'processing-docs' ] } )
80
- . processor ( { name : 'adding-extra-docs' , $runAfter : [ 'docs-processed' ] } )
81
- . processor ( { name : 'extra-docs-added' , $runAfter : [ 'adding-extra-docs' ] } )
82
- . processor ( { name : 'computing-ids' , $runAfter : [ 'extra-docs-added' ] } )
83
- . processor ( { name : 'ids-computed' , $runAfter : [ 'computing-ids' ] } )
84
- . processor ( { name : 'computing-paths' , $runAfter : [ 'ids-computed' ] } )
85
- . processor ( { name : 'paths-computed' , $runAfter : [ 'computing-paths' ] } )
86
- . processor ( { name : 'rendering-docs' , $runAfter : [ 'paths-computed' ] } )
87
- . processor ( { name : 'docs-rendered' , $runAfter : [ 'rendering-docs' ] } )
88
- . processor ( { name : 'writing-files' , $runAfter : [ 'docs-rendered' ] } )
89
- . processor ( { name : 'files-written' , $runAfter : [ 'writing-files' ] } )
83
+ function createShredPackage ( shredOptions ) {
84
+ var pkg = new Dgeni . Package ( 'doc-shredder' , [
85
+ // require('dgeni-packages/base') - doesn't work
86
+ ] ) ;
87
+ var options = resolveShredOptions ( shredOptions ) ;
90
88
89
+ initializePackage ( pkg )
91
90
. factory ( require ( './fileShredder' ) )
92
91
. factory ( require ( './regionExtractor' ) )
93
92
. processor ( require ( './mdWrapperProcessor' ) )
94
93
95
- . config ( function ( log ) {
96
- // Set logging level
97
- log . level = 'info' ;
98
- } )
99
-
100
-
101
94
. config ( function ( readFilesProcessor , fileShredder ) {
102
95
readFilesProcessor . fileReaders = [ fileShredder ] ;
103
96
} )
104
-
105
97
// default configs - may be overriden
106
98
. config ( function ( readFilesProcessor ) {
107
-
108
99
// Specify the base path used when resolving relative paths to source and output files
109
100
readFilesProcessor . basePath = options . basePath ;
110
101
@@ -117,20 +108,113 @@ function configure(shredder) {
117
108
return path . join ( options . sourceDir , extn ) ;
118
109
}
119
110
} ) ;
120
- readFilesProcessor . sourceFiles = [
121
- {
122
- // Process all candidate files in `src` and its subfolders ...
123
- include : includeFiles ,
124
-
125
- // When calculating the relative path to these files use this as the base path.
126
- // So `src/foo/bar.js` will have relative path of `foo/bar.js`
127
- basePath : options . sourceDir
111
+ readFilesProcessor . sourceFiles = [ {
112
+ // Process all candidate files in `src` and its subfolders ...
113
+ include : includeFiles ,
114
+ // When calculating the relative path to these files use this as the base path.
115
+ // So `src/foo/bar.js` will have relative path of `foo/bar.js`
116
+ basePath : options . sourceDir
117
+ } ] ;
118
+ } )
119
+ . config ( function ( writeFilesProcessor ) {
120
+ // Specify where the writeFilesProcessor will write our generated doc files
121
+ writeFilesProcessor . outputFolder = options . destDir ;
122
+ } ) ;
123
+ return pkg ;
124
+ }
125
+
126
+ var createShredMapPackage = function ( mapOptions ) {
127
+ var pkg = new Dgeni . Package ( 'docshred-mapper' , [
128
+ require ( 'dgeni-packages/base' ) ,
129
+ require ( 'dgeni-packages/nunjucks' )
130
+ ] ) ;
131
+ var options = resolveMapOptions ( mapOptions ) ;
132
+
133
+ initializePackage ( pkg )
134
+ . factory ( require ( './extractPathsReader' ) )
135
+ . processor ( require ( './shredMapProcessor' ) )
136
+
137
+ . config ( function ( readFilesProcessor , extractPathsReader ) {
138
+ readFilesProcessor . fileReaders = [ extractPathsReader ] ;
139
+ } )
140
+ // default configs - may be overriden
141
+ . config ( function ( readFilesProcessor ) {
142
+ // Specify the base path used when resolving relative paths to source and output files
143
+ readFilesProcessor . basePath = options . basePath ;
144
+
145
+ // Specify collections of source files that should contain the documentation to extract
146
+ var extns = [ '*.jade' ] ;
147
+ var includeFiles = extns . map ( function ( extn ) {
148
+ if ( options . includeSubdirs ) {
149
+ return path . join ( options . sourceDir , '**' , extn ) ;
150
+ } else {
151
+ return path . join ( options . sourceDir , extn ) ;
128
152
}
129
- ] ;
153
+ } ) ;
154
+ readFilesProcessor . sourceFiles = [ {
155
+ // Process all candidate files in `src` and its subfolders ...
156
+ include : includeFiles ,
157
+ // When calculating the relative path to these files use this as the base path.
158
+ // So `src/foo/bar.js` will have relative path of `foo/bar.js`
159
+ basePath : options . sourceDir
160
+ } ] ;
130
161
} )
131
162
. config ( function ( writeFilesProcessor ) {
132
163
// Specify where the writeFilesProcessor will write our generated doc files
133
164
writeFilesProcessor . outputFolder = options . destDir ;
165
+ } )
166
+ . config ( function ( templateFinder ) {
167
+ // Add a folder to search for our own templates to use when rendering docs
168
+ templateFinder . templateFolders = [ path . resolve ( __dirname ) ] ;
169
+
170
+ // Specify how to match docs to templates.
171
+ // In this case we just use the same static template for all docs
172
+ templateFinder . templatePatterns = [ '${ doc.docType }.template' ] ;
173
+ } )
174
+ . config ( function ( computePathsProcessor , computeIdsProcessor ) {
175
+ computePathsProcessor . $enabled = false ;
176
+ computeIdsProcessor . $enabled = false ;
177
+ //computePathsProcessor.pathTemplates.push({
178
+ // docTypes: ['foo'],
179
+ // pathTemplate: '',
180
+ // getOutputPath: function () {
181
+ // },
182
+ //});
183
+ //
184
+ //computeIdsProcessor.idTemplates.push({
185
+ // docTypes: ['foo'],
186
+ // getAliases: function (doc) {
187
+ // return [doc.id];
188
+ // }
189
+ //});
134
190
} ) ;
135
- return shredder ;
191
+
192
+ return pkg ;
136
193
}
194
+
195
+ function initializePackage ( pkg ) {
196
+ return pkg
197
+ . processor ( require ( 'dgeni-packages/base/processors/read-files' ) )
198
+ . processor ( require ( 'dgeni-packages/base/processors/write-files' ) )
199
+ . factory ( require ( 'dgeni-packages/base/services/writefile' ) )
200
+
201
+ // Ugh... Boilerplate that dgeni needs to sequence operations
202
+ . processor ( { name : 'reading-files' } )
203
+ . processor ( { name : 'files-read' , $runAfter : [ 'reading-files' ] } )
204
+ . processor ( { name : 'processing-docs' , $runAfter : [ 'files-read' ] } )
205
+ . processor ( { name : 'docs-processed' , $runAfter : [ 'processing-docs' ] } )
206
+ . processor ( { name : 'adding-extra-docs' , $runAfter : [ 'docs-processed' ] } )
207
+ . processor ( { name : 'extra-docs-added' , $runAfter : [ 'adding-extra-docs' ] } )
208
+ . processor ( { name : 'computing-ids' , $runAfter : [ 'extra-docs-added' ] } )
209
+ . processor ( { name : 'ids-computed' , $runAfter : [ 'computing-ids' ] } )
210
+ . processor ( { name : 'computing-paths' , $runAfter : [ 'ids-computed' ] } )
211
+ . processor ( { name : 'paths-computed' , $runAfter : [ 'computing-paths' ] } )
212
+ . processor ( { name : 'rendering-docs' , $runAfter : [ 'paths-computed' ] } )
213
+ . processor ( { name : 'docs-rendered' , $runAfter : [ 'rendering-docs' ] } )
214
+ . processor ( { name : 'writing-files' , $runAfter : [ 'docs-rendered' ] } )
215
+ . processor ( { name : 'files-written' , $runAfter : [ 'writing-files' ] } )
216
+ . config ( function ( log ) {
217
+ // Set logging level
218
+ log . level = 'info' ;
219
+ } )
220
+ }
0 commit comments