aboutsummaryrefslogtreecommitdiffstats
path: root/docs/src/reader.js
diff options
context:
space:
mode:
authorMisko Hevery2010-12-23 00:44:27 +0100
committerMisko Hevery2011-01-10 11:50:11 -0800
commit4f22d6866c052fb5b770ce4f377cecacacd9e6d8 (patch)
tree6bdb1c5eb70cfd7e6bcf143c121c53025a0489a4 /docs/src/reader.js
parentaab3df7aeaf79908e8b6212288b283adb42b1ce6 (diff)
downloadangular.js-4f22d6866c052fb5b770ce4f377cecacacd9e6d8.tar.bz2
complete rewrite of documentation generation
- romeved mustache.js - unified templates - improved testability of the code
Diffstat (limited to 'docs/src/reader.js')
-rw-r--r--docs/src/reader.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/docs/src/reader.js b/docs/src/reader.js
new file mode 100644
index 00000000..8f9f22c3
--- /dev/null
+++ b/docs/src/reader.js
@@ -0,0 +1,91 @@
+/**
+ * All reading related code here. This is so that we can separate the async code from sync code
+ * for testability
+ */
+require.paths.push(__dirname);
+var fs = require('fs'),
+ callback = require('callback');
+
+var NEW_LINE = /\n\r?/;
+
+function collect(callback){
+ findJsFiles('src', callback.waitMany(function(file) {
+ //console.log('reading', file, '...');
+ findNgDocInJsFile(file, callback.waitMany(function(doc, line) {
+ callback(doc, file, line);
+ }));
+ }));
+ findNgDocInDir('docs/', callback.waitMany(callback));
+ callback.done();
+}
+
+function findJsFiles(dir, callback){
+ fs.readdir(dir, callback.waitFor(function(err, files){
+ if (err) return this.error(err);
+ files.forEach(function(file){
+ var path = dir + '/' + file;
+ fs.lstat(path, callback.waitFor(function(err, stat){
+ if (err) return this.error(err);
+ if (stat.isDirectory())
+ findJsFiles(path, callback.waitMany(callback));
+ else if (/\.js$/.test(path))
+ callback(path);
+ }));
+ });
+ callback.done();
+ }));
+}
+
+function findNgDocInDir(directory, docNotify) {
+ fs.readdir(directory, docNotify.waitFor(function(err, files){
+ if (err) return this.error(err);
+ files.forEach(function(file){
+ //console.log('reading', directory + file, '...');
+ if (!file.match(/\.ngdoc$/)) return;
+ fs.readFile(directory + file, docNotify.waitFor(function(err, content){
+ if (err) return this.error(err);
+ docNotify(content.toString(), directory + file, 1);
+ }));
+ });
+ docNotify.done();
+ }));
+}
+
+function findNgDocInJsFile(file, callback) {
+ fs.readFile(file, callback.waitFor(function(err, content){
+ var lines = content.toString().split(NEW_LINE);
+ var text;
+ var startingLine ;
+ var match;
+ var inDoc = false;
+ lines.forEach(function(line, lineNumber){
+ lineNumber++;
+ // is the comment starting?
+ if (!inDoc && (match = line.match(/^\s*\/\*\*\s*(.*)$/))) {
+ line = match[1];
+ inDoc = true;
+ text = [];
+ startingLine = lineNumber;
+ }
+ // are we done?
+ if (inDoc && line.match(/\*\//)) {
+ text = text.join('\n');
+ text = text.replace(/^\n/, '');
+ if (text.match(/@ngdoc/)){
+ callback(text, startingLine);
+ }
+ doc = null;
+ inDoc = false;
+ }
+ // is the comment add text
+ if (inDoc){
+ text.push(line.replace(/^\s*\*\s?/, ''));
+ }
+ });
+ callback.done();
+ }));
+}
+
+
+
+exports.collect = collect; \ No newline at end of file