sc-docs 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,200 +1,200 @@
1
1
  /** Called automatically by JsDoc Toolkit. */
2
2
  function publish(symbolSet) {
3
- publish.conf = { // trailing slash expected for dirs
4
- ext: ".html",
5
- outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
6
- templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
7
- symbolsDir: "symbols/",
8
- srcDir: "symbols/src/"
9
- };
10
-
11
- // is source output is suppressed, just display the links to the source file
12
- if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
13
- Link.prototype._makeSrcLink = function(srcFilePath) {
14
- return "<"+srcFilePath+">";
15
- }
16
- }
17
-
18
- // create the folders and subfolders to hold the output
19
- IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
20
-
21
- // used to allow Link to check the details of things being linked to
22
- Link.symbolSet = symbolSet;
23
-
24
- // create the required templates
25
- try {
26
- var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl");
27
- var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
28
- }
29
- catch(e) {
30
- print("Couldn't create the required templates: "+e);
31
- quit();
32
- }
33
-
34
- // some ustility filters
35
- function hasNoParent($) {return ($.memberOf == "")}
36
- function isaFile($) {return ($.is("FILE"))}
37
- function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)}
38
-
39
- // get an array version of the symbolset, useful for filtering
40
- var symbols = symbolSet.toArray();
41
-
42
- // create the hilited source code files
43
- var files = JSDOC.opt.srcFiles;
44
- for (var i = 0, l = files.length; i < l; i++) {
45
- var file = files[i];
46
- var srcDir = publish.conf.outDir + "symbols/src/";
47
- makeSrcFile(file, srcDir);
48
- }
49
-
50
- // get a list of all the classes in the symbolset
51
- var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
52
-
53
- // create a filemap in which outfiles must be to be named uniquely, ignoring case
54
- if (JSDOC.opt.u) {
55
- var filemapCounts = {};
56
- Link.filemap = {};
57
- for (var i = 0, l = classes.length; i < l; i++) {
58
- var lcAlias = classes[i].alias.toLowerCase();
59
-
60
- if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1;
61
- else filemapCounts[lcAlias]++;
62
-
63
- Link.filemap[classes[i].alias] =
64
- (filemapCounts[lcAlias] > 1)?
65
- lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
66
- }
67
- }
68
-
69
- // create a class index, displayed in the left-hand column of every class page
70
- Link.base = "../";
71
- publish.classesIndex = classesTemplate.process(classes); // kept in memory
72
-
73
- // create each of the class pages
74
- for (var i = 0, l = classes.length; i < l; i++) {
75
- var symbol = classes[i];
76
-
77
- symbol.events = symbol.getEvents(); // 1 order matters
78
- symbol.methods = symbol.getMethods(); // 2
79
-
80
- var output = "";
81
- output = classTemplate.process(symbol);
82
-
83
- IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output);
84
- }
85
-
86
- // regenerate the index with different relative links, used in the index pages
87
- Link.base = "";
88
- publish.classesIndex = classesTemplate.process(classes);
89
-
90
- // create the class index page
91
- try {
92
- var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
93
- }
94
- catch(e) { print(e.message); quit(); }
95
-
96
- var classesIndex = classesindexTemplate.process(classes);
97
- IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
98
- classesindexTemplate = classesIndex = classes = null;
99
-
100
- // create the file index page
101
- try {
102
- var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
103
- }
104
- catch(e) { print(e.message); quit(); }
105
-
106
- var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
107
- var allFiles = []; // not all files have file-level docs, but we need to list every one
108
-
109
- for (var i = 0; i < files.length; i++) {
110
- allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
111
- }
112
-
113
- for (var i = 0; i < documentedFiles.length; i++) {
114
- var offset = files.indexOf(documentedFiles[i].alias);
115
- allFiles[offset] = documentedFiles[i];
116
- }
117
-
118
- allFiles = allFiles.sort(makeSortby("name"));
119
-
120
- // output the file index page
121
- var filesIndex = fileindexTemplate.process(allFiles);
122
- IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex);
123
- fileindexTemplate = filesIndex = files = null;
3
+ publish.conf = { // trailing slash expected for dirs
4
+ ext: ".html",
5
+ outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
6
+ templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
7
+ symbolsDir: "symbols/",
8
+ srcDir: "symbols/src/"
9
+ };
10
+
11
+ // is source output is suppressed, just display the links to the source file
12
+ if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
13
+ Link.prototype._makeSrcLink = function(srcFilePath) {
14
+ return "&lt;"+srcFilePath+"&gt;";
15
+ }
16
+ }
17
+
18
+ // create the folders and subfolders to hold the output
19
+ IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
20
+
21
+ // used to allow Link to check the details of things being linked to
22
+ Link.symbolSet = symbolSet;
23
+
24
+ // create the required templates
25
+ try {
26
+ var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl");
27
+ var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
28
+ }
29
+ catch(e) {
30
+ print("Couldn't create the required templates: "+e);
31
+ quit();
32
+ }
33
+
34
+ // some ustility filters
35
+ function hasNoParent($) {return ($.memberOf == "")}
36
+ function isaFile($) {return ($.is("FILE"))}
37
+ function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)}
38
+
39
+ // get an array version of the symbolset, useful for filtering
40
+ var symbols = symbolSet.toArray();
41
+
42
+ // create the hilited source code files
43
+ var files = JSDOC.opt.srcFiles;
44
+ for (var i = 0, l = files.length; i < l; i++) {
45
+ var file = files[i];
46
+ var srcDir = publish.conf.outDir + "symbols/src/";
47
+ makeSrcFile(file, srcDir);
48
+ }
49
+
50
+ // get a list of all the classes in the symbolset
51
+ var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
52
+
53
+ // create a filemap in which outfiles must be to be named uniquely, ignoring case
54
+ if (JSDOC.opt.u) {
55
+ var filemapCounts = {};
56
+ Link.filemap = {};
57
+ for (var i = 0, l = classes.length; i < l; i++) {
58
+ var lcAlias = classes[i].alias.toLowerCase();
59
+
60
+ if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1;
61
+ else filemapCounts[lcAlias]++;
62
+
63
+ Link.filemap[classes[i].alias] =
64
+ (filemapCounts[lcAlias] > 1)?
65
+ lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
66
+ }
67
+ }
68
+
69
+ // create a class index, displayed in the left-hand column of every class page
70
+ Link.base = "../";
71
+ publish.classesIndex = classesTemplate.process(classes); // kept in memory
72
+
73
+ // create each of the class pages
74
+ for (var i = 0, l = classes.length; i < l; i++) {
75
+ var symbol = classes[i];
76
+
77
+ symbol.events = symbol.getEvents(); // 1 order matters
78
+ symbol.methods = symbol.getMethods(); // 2
79
+
80
+ var output = "";
81
+ output = classTemplate.process(symbol);
82
+
83
+ IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output);
84
+ }
85
+
86
+ // regenerate the index with different relative links, used in the index pages
87
+ Link.base = "";
88
+ publish.classesIndex = classesTemplate.process(classes);
89
+
90
+ // create the class index page
91
+ try {
92
+ var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
93
+ }
94
+ catch(e) { print(e.message); quit(); }
95
+
96
+ var classesIndex = classesindexTemplate.process(classes);
97
+ IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
98
+ classesindexTemplate = classesIndex = classes = null;
99
+
100
+ // create the file index page
101
+ try {
102
+ var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
103
+ }
104
+ catch(e) { print(e.message); quit(); }
105
+
106
+ var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
107
+ var allFiles = []; // not all files have file-level docs, but we need to list every one
108
+
109
+ for (var i = 0; i < files.length; i++) {
110
+ allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
111
+ }
112
+
113
+ for (var i = 0; i < documentedFiles.length; i++) {
114
+ var offset = files.indexOf(documentedFiles[i].alias);
115
+ allFiles[offset] = documentedFiles[i];
116
+ }
117
+
118
+ allFiles = allFiles.sort(makeSortby("name"));
119
+
120
+ // output the file index page
121
+ var filesIndex = fileindexTemplate.process(allFiles);
122
+ IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex);
123
+ fileindexTemplate = filesIndex = files = null;
124
124
  }
125
125
 
126
126
 
127
127
  /** Just the first sentence (up to a full stop). Should not break on dotted variable names. */
128
128
  function summarize(desc) {
129
- if (typeof desc != "undefined")
130
- return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i)? RegExp.$1 : desc;
129
+ if (typeof desc != "undefined")
130
+ return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i)? RegExp.$1 : desc;
131
131
  }
132
132
 
133
133
  /** Make a symbol sorter by some attribute. */
134
134
  function makeSortby(attribute) {
135
- return function(a, b) {
136
- if (a[attribute] != undefined && b[attribute] != undefined) {
137
- a = a[attribute].toLowerCase();
138
- b = b[attribute].toLowerCase();
139
- if (a < b) return -1;
140
- if (a > b) return 1;
141
- return 0;
142
- }
143
- }
135
+ return function(a, b) {
136
+ if (a[attribute] != undefined && b[attribute] != undefined) {
137
+ a = a[attribute].toLowerCase();
138
+ b = b[attribute].toLowerCase();
139
+ if (a < b) return -1;
140
+ if (a > b) return 1;
141
+ return 0;
142
+ }
143
+ }
144
144
  }
145
145
 
146
146
  /** Pull in the contents of an external file at the given path. */
147
147
  function include(path) {
148
- var path = publish.conf.templatesDir+path;
149
- return IO.readFile(path);
148
+ var path = publish.conf.templatesDir+path;
149
+ return IO.readFile(path);
150
150
  }
151
151
 
152
152
  /** Turn a raw source file into a code-hilited page in the docs. */
153
153
  function makeSrcFile(path, srcDir, name) {
154
- if (JSDOC.opt.s) return;
155
-
156
- if (!name) {
157
- name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
158
- name = name.replace(/\:/g, "_");
159
- }
160
-
161
- var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
162
-
163
- if (defined(JSDOC.PluginManager)) {
164
- JSDOC.PluginManager.run("onPublishSrc", src);
165
- }
166
-
167
- if (src.hilited) {
168
- IO.saveFile(srcDir, name+publish.conf.ext, src.hilited);
169
- }
154
+ if (JSDOC.opt.s) return;
155
+
156
+ if (!name) {
157
+ name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
158
+ name = name.replace(/\:/g, "_");
159
+ }
160
+
161
+ var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
162
+
163
+ if (defined(JSDOC.PluginManager)) {
164
+ JSDOC.PluginManager.run("onPublishSrc", src);
165
+ }
166
+
167
+ if (src.hilited) {
168
+ IO.saveFile(srcDir, name+publish.conf.ext, src.hilited);
169
+ }
170
170
  }
171
171
 
172
172
  /** Build output for displaying function parameters. */
173
173
  function makeSignature(params) {
174
- if (!params) return "()";
175
- var signature = "("
176
- +
177
- params.filter(
178
- function($) {
179
- return $.name.indexOf(".") == -1; // don't show config params in signature
180
- }
181
- ).map(
182
- function($) {
183
- return $.name;
184
- }
185
- ).join(", ")
186
- +
187
- ")";
188
- return signature;
174
+ if (!params) return "()";
175
+ var signature = "("
176
+ +
177
+ params.filter(
178
+ function($) {
179
+ return $.name.indexOf(".") == -1; // don't show config params in signature
180
+ }
181
+ ).map(
182
+ function($) {
183
+ return $.name;
184
+ }
185
+ ).join(", ")
186
+ +
187
+ ")";
188
+ return signature;
189
189
  }
190
190
 
191
191
  /** Find symbol {@link ...} strings in text and turn into html links */
192
192
  function resolveLinks(str, from) {
193
- str = str.replace(/\{@link ([^} ]+) ?\}/gi,
194
- function(match, symbolName) {
195
- return new Link().toSymbol(symbolName);
196
- }
197
- );
198
-
199
- return str;
193
+ str = str.replace(/\{@link ([^} ]+) ?\}/gi,
194
+ function(match, symbolName) {
195
+ return new Link().toSymbol(symbolName);
196
+ }
197
+ );
198
+
199
+ return str;
200
200
  }
@@ -1,4 +1,4 @@
1
1
  module ScDocs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
4
4
 
@@ -0,0 +1,23 @@
1
+ IO.include("plugins/smartdown/smartdown.js");
2
+
3
+ JSDOC.useSmartdown = false;
4
+
5
+ JSDOC.PluginManager.registerPlugin(
6
+ "JSDOC.smartdown",
7
+ {
8
+ onInit: function(opts){
9
+ if (opts.smartdown) { JSDOC.useSmartdown = true; }
10
+ },
11
+ onDocTag: function(docTag) {
12
+ if (!JSDOC.useSmartdown) { return; }
13
+
14
+ var exclude = "type param see inherits lends extends scope link base augments memberOf".split(' ');
15
+ if (exclude.indexOf(docTag.title) < 0) {
16
+ var desc = docTag.desc.trim();
17
+ desc = Smartdown.render(desc);
18
+ docTag.desc = desc;
19
+ }
20
+ }
21
+ }
22
+ );
23
+
@@ -0,0 +1,46 @@
1
+
2
+ // Koala - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
+ /*global IO*/
4
+
5
+ var Koala = {
6
+
7
+ /**
8
+ * Version.
9
+ */
10
+ version: '0.0.1',
11
+
12
+ lexers: {},
13
+ formatters: {},
14
+
15
+
16
+
17
+
18
+ /**
19
+ * Render _str_ as _type_, with optional _formatter_
20
+ * defaulting to HTML. _str_ should be a filename or
21
+ * extension such as '.js'.
22
+ *
23
+ * @param {string} type
24
+ * @param {string} str
25
+ * @param {Formatter} formatter
26
+ * @return {string}
27
+ * @api public
28
+ */
29
+
30
+ render: function(type, str, formatter) {
31
+ var grammar = this.lexers[type];
32
+ formatter = formatter || this.formatters.HTML;
33
+
34
+ if (!grammar) throw new Error("syntax highlighting for `" + type + "' is not supported");
35
+ return formatter.render(grammar, str);
36
+ }
37
+
38
+ };
39
+
40
+ IO.include('plugins/smartdown/koala/formatter.js');
41
+ IO.include('plugins/smartdown/koala/lexer.js');
42
+ IO.include('plugins/smartdown/koala/formatters/html.js');
43
+ IO.include('plugins/smartdown/koala/grammars/javascript.js');
44
+ IO.include('plugins/smartdown/koala/grammars/ruby.js');
45
+
46
+
@@ -0,0 +1,28 @@
1
+
2
+ // Koala - Formatter - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
+ /*global Koala*/
4
+ /**
5
+ * Initialize with formatter function.
6
+ */
7
+
8
+ Koala.Formatter = function(fn) {
9
+ if (typeof fn !== 'function') throw new TypeError('Formatter requires a function');
10
+ this.fn = fn;
11
+ };
12
+
13
+ /**
14
+ * Render _str_ using the given _lexer_.
15
+ *
16
+ * @param {Lexer} lexer
17
+ * @param {string} str
18
+ * @return {string}
19
+ * @api public
20
+ */
21
+
22
+ Koala.Formatter.prototype.render = function(lexer, str) {
23
+ var self = this;
24
+ if (typeof lexer.scan !== 'function') throw new TypeError('Formatter#render() requires a lexer to be passed');
25
+ return lexer.scan(str).map(function(token){
26
+ return self.fn.call(self, token[0], token[1]);
27
+ }).join('');
28
+ };