aboutsummaryrefslogtreecommitdiffstats
path: root/docs/src/writer.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/writer.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/writer.js')
-rw-r--r--docs/src/writer.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/docs/src/writer.js b/docs/src/writer.js
new file mode 100644
index 00000000..eb1b190f
--- /dev/null
+++ b/docs/src/writer.js
@@ -0,0 +1,61 @@
+/**
+ * All writing 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');
+var OUTPUT_DIR = "build/docs/";
+
+function output(docs, content, callback){
+ callback();
+}
+
+exports.output = function(file, content, callback){
+ //console.log('writing', OUTPUT_DIR + file, '...');
+ fs.writeFile(
+ OUTPUT_DIR + file,
+ exports.toString(content),
+ callback);
+};
+
+
+exports.toString = function toString(obj){
+ switch (typeof obj) {
+ case 'string':
+ return obj;
+ case 'object':
+ if (obj instanceof Array) {
+ obj.forEach(function (value, key){
+ obj[key] = toString(value);
+ });
+ return obj.join('');
+ } else {
+ return JSON.stringify(obj);
+ }
+ }
+ return obj;
+};
+
+exports.makeDir = function (path, callback) {
+ var parts = path.split(/\//);
+ path = '.';
+ (function next(){
+ if (parts.length) {
+ path += '/' + parts.shift();
+ fs.mkdir(path, 0777, next);
+ } else {
+ callback();
+ }
+ })();
+};
+
+exports.copy = function(filename, callback){
+ //console.log('writing', OUTPUT_DIR + filename, '...');
+ fs.readFile('docs/src/templates/' + filename, function(err, content){
+ if (err) return callback.error(err);
+ fs.writeFile(
+ OUTPUT_DIR + filename,
+ content,
+ callback);
+ });
+};