Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1940128

Browse files
Di PengIgorMinar
Di Peng
authored andcommitted
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
1 parent 08a33e7 commit 1940128

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

docs/spec/writerSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,20 @@ describe('writer', function(){
1515
expect(toString(['abc',{}])).toEqual('abc{}');
1616
});
1717
});
18+
19+
describe('replace method', function() {
20+
var content,
21+
replacements;
22+
23+
beforeEach(function() {
24+
content = 'angular super jQuery manifest';
25+
});
26+
27+
it('should replace placeholders', function() {
28+
replacements = {'angular': 'ng', 'jQuery': 'jqlite','notHere': 'here'};
29+
30+
content = writer.replace(content, replacements);
31+
expect(content).toBe('ng super jqlite manifest');
32+
});
33+
});
1834
});

docs/src/gen-docs.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@ function writeTheRest(writesFuture) {
4242

4343
writesFuture.push(writer.copyDir('img'));
4444
writesFuture.push(writer.copyDir('examples'));
45-
writesFuture.push(writer.copyTpl('index.html'));
46-
writesFuture.push(writer.copy('docs/src/templates/index.html',
47-
'build/docs/index-jq.html',
48-
'<!-- jquery place holder -->',
49-
'<script src=\"jquery.min.js\"><\/script>'));
45+
46+
var manifest = 'manifest="appcache.manifest"',
47+
jq = '<script src="jquery.min.js"></script>',
48+
ngMin = '<script src="../angular.min.js" ng:autobind></script>',
49+
ng = '<script src="../angular.js" ng:autobind></script>'
50+
51+
writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index.html',
52+
writer.replace, {'doc:manifest': manifest,
53+
'<!-- angular script place holder -->': ngMin}));
54+
55+
writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html',
56+
writer.replace, {'doc:manifest': manifest,
57+
'<!-- angular script place holder -->': ngMin,
58+
'<!-- jquery place holder -->': jq}));
59+
60+
writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-debug.html',
61+
writer.replace, {'doc:manifest': '',
62+
'<!-- angular script place holder -->': ng}));
63+
64+
writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq-debug.html',
65+
writer.replace, {'doc:manifest': '',
66+
'<!-- angular script place holder -->': ng,
67+
'<!-- jquery place holder -->': jq}));
68+
5069
writesFuture.push(writer.copyTpl('offline.html'));
5170
writesFuture.push(writer.copyTpl('docs-scenario.html'));
5271
writesFuture.push(writer.copyTpl('jquery.min.js'));

docs/src/templates/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns:ng="http://angularjs.org/"
33
xmlns:doc="http://docs.angularjs.org/"
44
ng:controller="DocsController"
5-
manifest="appcache.manifest">
5+
doc:manifest>
66
<head>
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
88
<title ng:bind-template="AngularJS: {{partialTitle}}">AngularJS</title>
@@ -103,7 +103,7 @@ <h2>Would you like full offline support for this AngularJS Docs App?</h2>
103103

104104
<script src="syntaxhighlighter/syntaxhighlighter-combined.js"></script>
105105
<!-- jquery place holder -->
106-
<script src="../angular.min.js" ng:autobind></script>
106+
<!-- angular script place holder -->
107107
<script src="docs-combined.js"></script>
108108
<script src="docs-keywords.js"></script>
109109
</body>

docs/src/writer.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,35 @@ exports.copyTpl = function(filename) {
4444
return exports.copy('docs/src/templates/' + filename, OUTPUT_DIR + filename);
4545
};
4646

47-
exports.copy = function (from, to, replacementKey, replacement) {
48-
// Have to use rb (read binary), char 'r' is infered by library.
49-
return qfs.read(from,'b').then(function(content) {
50-
if(replacementKey && replacement) {
51-
content = content.toString().replace(replacementKey, replacement);
47+
/* Copy files from one place to another.
48+
* @param from{string} path of the source file to be copied
49+
* @param to{string} path of where the copied file should be stored
50+
* @param transform{function=} transfromation function to be applied before return
51+
*/
52+
exports.copy = function(from, to, transform) {
53+
var args = Array.prototype.slice.call(arguments, 3);
54+
55+
// We have to use binary reading, Since some characters are unicode.
56+
return qfs.read(from, 'b').then(function(content) {
57+
if (transform) {
58+
args.unshift(content.toString());
59+
content = transform.apply(null, args);
5260
}
5361
qfs.write(to, content);
5462
});
5563
}
5664

65+
/* Replace placeholders in content accordingly
66+
* @param content{string} content to be modified
67+
* @param replacements{obj} key and value pairs in which key will be replaced with value in content
68+
*/
69+
exports.replace = function(content, replacements) {
70+
for(key in replacements) {
71+
content = content.replace(key, replacements[key]);
72+
}
73+
return content;
74+
}
75+
5776
exports.copyDir = function copyDir(dir) {
5877
return qfs.listDirectoryTree('docs/' + dir).then(function(dirs) {
5978
var done;

0 commit comments

Comments
 (0)