From 19401280aed9d4767faddcf58fab91ec13c556a9 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Sat, 20 Aug 2011 08:51:00 -0700 Subject: [PATCH] feat(doc): generate both normal and debug version of index.html - index.html has manifest file and angular.min.js - index-jq.html has manifest file, angular.min.js and jquery.min.js - index-debug.html has angular.js - index-jq-debug.html has angular.js and jquery.min.js --- docs/spec/writerSpec.js | 16 ++++++++++++++++ docs/src/gen-docs.js | 29 ++++++++++++++++++++++++----- docs/src/templates/index.html | 4 ++-- docs/src/writer.js | 29 ++++++++++++++++++++++++----- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/docs/spec/writerSpec.js b/docs/spec/writerSpec.js index 8354ad5df608..a44e283cd68f 100644 --- a/docs/spec/writerSpec.js +++ b/docs/spec/writerSpec.js @@ -15,4 +15,20 @@ describe('writer', function(){ expect(toString(['abc',{}])).toEqual('abc{}'); }); }); + + describe('replace method', function() { + var content, + replacements; + + beforeEach(function() { + content = 'angular super jQuery manifest'; + }); + + it('should replace placeholders', function() { + replacements = {'angular': 'ng', 'jQuery': 'jqlite','notHere': 'here'}; + + content = writer.replace(content, replacements); + expect(content).toBe('ng super jqlite manifest'); + }); + }); }); diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js index 4649bec3e9f4..93d0038eb3e6 100755 --- a/docs/src/gen-docs.js +++ b/docs/src/gen-docs.js @@ -42,11 +42,30 @@ function writeTheRest(writesFuture) { writesFuture.push(writer.copyDir('img')); writesFuture.push(writer.copyDir('examples')); - writesFuture.push(writer.copyTpl('index.html')); - writesFuture.push(writer.copy('docs/src/templates/index.html', - 'build/docs/index-jq.html', - '', - '', + ngMin = '', + ng = '' + + writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index.html', + writer.replace, {'doc:manifest': manifest, + '': ngMin})); + + writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', + writer.replace, {'doc:manifest': manifest, + '': ngMin, + '': jq})); + + writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-debug.html', + writer.replace, {'doc:manifest': '', + '': ng})); + + writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq-debug.html', + writer.replace, {'doc:manifest': '', + '': ng, + '': jq})); + writesFuture.push(writer.copyTpl('offline.html')); writesFuture.push(writer.copyTpl('docs-scenario.html')); writesFuture.push(writer.copyTpl('jquery.min.js')); diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html index 26c1eaeca705..d5cfaed2d290 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -2,7 +2,7 @@ + doc:manifest> AngularJS @@ -103,7 +103,7 @@

Would you like full offline support for this AngularJS Docs App?

- + diff --git a/docs/src/writer.js b/docs/src/writer.js index b33e41644045..5aa8f566b68b 100644 --- a/docs/src/writer.js +++ b/docs/src/writer.js @@ -44,16 +44,35 @@ exports.copyTpl = function(filename) { return exports.copy('docs/src/templates/' + filename, OUTPUT_DIR + filename); }; -exports.copy = function (from, to, replacementKey, replacement) { - // Have to use rb (read binary), char 'r' is infered by library. - return qfs.read(from,'b').then(function(content) { - if(replacementKey && replacement) { - content = content.toString().replace(replacementKey, replacement); +/* Copy files from one place to another. + * @param from{string} path of the source file to be copied + * @param to{string} path of where the copied file should be stored + * @param transform{function=} transfromation function to be applied before return + */ +exports.copy = function(from, to, transform) { + var args = Array.prototype.slice.call(arguments, 3); + + // We have to use binary reading, Since some characters are unicode. + return qfs.read(from, 'b').then(function(content) { + if (transform) { + args.unshift(content.toString()); + content = transform.apply(null, args); } qfs.write(to, content); }); } +/* Replace placeholders in content accordingly + * @param content{string} content to be modified + * @param replacements{obj} key and value pairs in which key will be replaced with value in content + */ +exports.replace = function(content, replacements) { + for(key in replacements) { + content = content.replace(key, replacements[key]); + } + return content; +} + exports.copyDir = function copyDir(dir) { return qfs.listDirectoryTree('docs/' + dir).then(function(dirs) { var done;