1+ var  _  =  require ( 'lodash' ) ; 
2+ var  path  =  require ( 'canonical-path' ) ; 
3+ 
4+ var  titleCase  =  function ( text )  { 
5+  return  text . replace ( / ( .) ( .* ) / ,  function ( _ ,  first ,  rest )  { 
6+  return  first . toUpperCase ( )  +  rest ; 
7+  } ) ; 
8+ } ; 
9+ 
10+ /* 
11+ * Create _data.json file for Harp pages 
12+ * 
13+ * http://harpjs.com/docs/development/metadata 
14+ * 
15+ * This method creates the meta data required for each page 
16+ * such as the title, description, etc. This meta data is used 
17+ * in the harp static site generator to create the title for headers 
18+ * and the navigation used in the API docs 
19+ * 
20+ */ 
21+ 
22+ module . exports  =  function  addJadeDataDocsProcessor ( EXPORT_DOC_TYPES )  { 
23+  return  { 
24+  $runAfter : [ 'adding-extra-docs' ,  'cloneExportedFromDocs' ] , 
25+  $runBefore : [ 'extra-docs-added' ] , 
26+  $process : function ( docs )  { 
27+  var  extraDocs  =  [ ] ; 
28+  var  modules  =  [ ] ; 
29+ 
30+ 
31+  /* 
32+  * Create Data for Modules 
33+  * 
34+  * Modules must be public and have content 
35+  */ 
36+ 
37+  _ . forEach ( docs ,  function ( doc )  { 
38+  if  ( doc . docType  ===  'module'  &&  doc . exports . length )  { 
39+  modules . push ( doc ) ; 
40+ 
41+  // GET DATA FOR INDEX PAGE OF MODULE SECTION 
42+  var  indexPageInfo  =  [ { 
43+  name : 'index' , 
44+  title : _ . map ( path . basename ( doc . fileInfo . baseName ) . split ( '_' ) ,  function ( part )  { 
45+  return  titleCase ( part ) ; 
46+  } ) . join ( ' ' ) , 
47+  intro : doc . description . replace ( '"' ,  '\"' ) . replace ( / \r ? \n | \r / g, "" ) 
48+  } ] ; 
49+ 
50+  // GET DATA FOR EACH PAGE (CLASS, VARS, FUNCTIONS) 
51+  var  modulePageInfo  =  _ . map ( doc . exports ,  function ( exportDoc )  { 
52+  return  { 
53+  name : exportDoc . name  +  '-'  +  exportDoc . docType , 
54+  title : exportDoc . name  +  ' '  +  titleCase ( exportDoc . docType ) 
55+  } ; 
56+  } ) ; 
57+ 
58+  //COMBINE PAGE DATA 
59+  var  allPageData  =  indexPageInfo . concat ( modulePageInfo ) ; 
60+ 
61+  // PUSH DATA TO EXTRA DOCS ARRAY 
62+  extraDocs . push ( { 
63+  id : doc . id  +  "-data" , 
64+  docType : 'jade-data' , 
65+  originalDoc : doc , 
66+  data : allPageData 
67+  } ) ; 
68+  } 
69+  } ) ; 
70+ 
71+ 
72+  return  docs . concat ( extraDocs ) ; 
73+  } 
74+  } ; 
75+ } ; 
0 commit comments