Skip to content

Commit 9ac1e31

Browse files
committed
tests pass
2 parents 484c9b3 + 7104748 commit 9ac1e31

File tree

13 files changed

+323
-250
lines changed

13 files changed

+323
-250
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ site/static/dist/
66
site/templates/
77
test/tmp
88
.idea/
9+
.vscode
10+
.DS_Store

bit-docs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ var _ = require("lodash");
33
var tags = require("./tags/tags");
44

55
var mergeOnto = function(prop, dest, source){
6+
if(!dest[prop]) {
7+
dest[prop] = [];
8+
}
69
if(source[prop]) {
7-
dest[prop] = dest[prop].concat(source[prop])
10+
dest[prop] = dest[prop].concat(source[prop]);
811
}
912
};
1013

@@ -50,12 +53,13 @@ module.exports = function(bitDocs){
5053
siteConfig.html = {
5154
dependencies: {},
5255
static: [],
53-
templates: []
56+
templates: [],
57+
staticDist: []
5458
};
5559
}
5660
var html = siteConfig.html;
5761
_.assign(html.dependencies, htmlConfig.dependencies || {});
58-
62+
mergeOnto("staticDist", html, htmlConfig);
5963
mergeOnto("static", html, htmlConfig);
6064
mergeOnto("templates", html, htmlConfig);
6165
});

build/build_test.js

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
var assert = require('assert');
4+
var Q = require('q');
5+
var rimraf = require('rimraf');
6+
var getRenderer = require('./get_renderer');
7+
var getPartials = require('./get_partials');
8+
var build = require("./build");
19

10+
var rmdir = Q.denodeify(rimraf);
11+
var read = Q.denodeify(fs.readFile);
212

3-
var getRenderer = require('./get_renderer'),
4-
getPartials = require('./get_partials'),
5-
build = require("./build"),
6-
assert = require('assert'),
7-
Q = require('q'),
8-
path = require('path'),
9-
rmdir = require('rimraf'),
10-
fs = require('fs');
13+
require("./make_default_helpers_test");
1114

12-
describe("documentjs/lib/generators/html/build",function(){
15+
describe("documentjs/lib/generators/html/build", function(){
1316

14-
beforeEach(function(done){
15-
rmdir(path.join(__dirname,"..","site","static"), function(e){
16-
rmdir(path.join(__dirname,"..","site","templates"), done);
17+
beforeEach(function(){
18+
return rmdir(path.join(__dirname, "..", "site", "static")).then(function(){
19+
return rmdir(path.join(__dirname, "..", "site", "templates"));
1720
});
1821
});
1922

20-
it("get_renderer and get_partial work",function(done){
21-
Q.all([
23+
it("get_renderer and get_partial work", function(){
24+
return Q.all([
2225
getRenderer('build/test/templates'),
2326
getPartials('build/test/templates')
2427
]).then(function(results){
25-
2628
var renderer = results[0];
27-
2829
var result = renderer({subject: "World"});
2930

3031
assert.equal(result, "<html><h1>Hello World</h1></html>");
31-
done();
32-
},done).catch(done);
32+
});
3333
});
3434

35-
it("build.renderer build.templates build.helpers",function(done){
36-
35+
it("build.renderer build.templates build.helpers", function(){
3736
var options = {
38-
html: { templates: path.join(__dirname,"test","templates_with_helpers") },
37+
html: { templates: path.join(__dirname, "test", "templates_with_helpers") },
3938
dest: "XXXXYYYZZZ",
4039
forceBuild: true,
4140
pageConfig: {
@@ -52,13 +51,11 @@ describe("documentjs/lib/generators/html/build",function(){
5251
};
5352

5453

55-
Q.all([
54+
return Q.all([
5655
build.renderer(buildTemplatesPromise, options),
5756
build.helpers(buildTemplatesPromise, {}, options, getCurrent)
5857
]).then(function(results){
59-
6058
var renderer = results[0];
61-
6259
var result = renderer({
6360
subject: "World",
6461
src: "./index.js",
@@ -67,14 +64,13 @@ describe("documentjs/lib/generators/html/build",function(){
6764
});
6865

6966
assert.equal(result, "<html><h1>HELLO World</h1>\n</html>");
70-
done();
71-
},done).catch(done);
67+
});
7268

7369
});
7470

75-
it("Does ignoreTemplateRender",function(done){
71+
it("Does ignoreTemplateRender", function(){
7672
var options = {
77-
html: {templates: path.join(__dirname,"test","render_body_option")},
73+
html: {templates: path.join(__dirname, "test", "render_body_option")},
7874
dest: "XXXXYYYZZZ",
7975
forceBuild: true,
8076
pageConfig: {
@@ -90,41 +86,71 @@ describe("documentjs/lib/generators/html/build",function(){
9086
return data;
9187
};
9288

93-
Q.all([
89+
return Q.all([
9490
build.renderer(buildTemplatesPromise, options),
9591
build.helpers(buildTemplatesPromise, {}, options, getCurrent)
9692
]).then(function(results){
97-
9893
var renderer = results[0];
99-
10094
var result = renderer({body: "{{message}} stuff"});
10195

10296
assert.equal(result, "<html><h1>{{message}} stuff</h1>\n<p>static</p></html>");
103-
done();
104-
},done).catch(done);
97+
});
10598

10699
});
107100

108-
it("builds the static dist", function(done){
101+
it("builds the static dist", function(){
109102
this.timeout(120000);
110-
build.staticDist({
103+
return build.staticDist({
111104
forceBuild: true,
112-
html: {dependencies: {"can-component": "3.0.0-pre.9"}}
113-
}).then(function(result){
114-
fs.readFile(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js"), function(err, res){
115-
if(err) {
116-
done(err);
117-
} else {
118-
assert.ok(/can-component/.test(res), "got static.js with component");
119-
done();
105+
html: {
106+
dependencies: {
107+
"can-component": "3.0.0-pre.9"
120108
}
121-
});
122-
}, done);
109+
}
110+
}).then(function(result){
111+
return read(path.join(__dirname, "..", result.distFolder, "bundles", "bit-docs-site", "static.js"));
112+
}).then(function(res){
113+
assert.ok(/can-component/.test(res), "got static.js with component");
114+
});
123115
});
124116

125-
it("makes linked content",function(done){
117+
it("copy absolute staticDist folders to static dist", function(){
118+
this.timeout(120000);
119+
return build.staticDist({
120+
forceBuild: true,
121+
html: {
122+
staticDist: [
123+
path.join(__dirname, '..', 'test-static-dist')
124+
]
125+
},
126+
}).then(function(result){
127+
return read(path.join(__dirname, "..", result.distFolder, "test.css"));
128+
}).then(function(res){
129+
assert.ok(/#TestID/.test(res), "got test.css file");
130+
});
131+
});
132+
133+
it("copy relative staticDist folders to static dist", function(){
134+
this.timeout(120000);
135+
return build.staticDist({
136+
forceBuild: true,
137+
html: {
138+
staticDist: [
139+
'./test-static-dist'
140+
]
141+
},
142+
}).then(function(result){
143+
return read(path.join(__dirname, "..", result.distFolder, "test.css"));
144+
}).then(function(res){
145+
assert.ok(/#TestID/.test(res), "got test.css file");
146+
});
147+
});
148+
149+
it("makes linked content", function(){
126150
var options = {
127-
html: { templates: path.join(__dirname,"test","escaped") },
151+
html: {
152+
templates: path.join(__dirname, "test", "escaped")
153+
},
128154
dest: "XXXXYYYZZZ",
129155
forceBuild: true,
130156
pageConfig: {
@@ -149,18 +175,14 @@ describe("documentjs/lib/generators/html/build",function(){
149175
something: {name: "something", title: "<something/>"}
150176
};
151177

152-
153-
Q.all([
178+
return Q.all([
154179
build.renderer(buildTemplatesPromise, options),
155180
build.helpers(buildTemplatesPromise, docMap, options, getCurrent)
156181
]).then(function(results){
157-
158182
var renderer = results[0];
159-
160183
var result = renderer(docObject);
184+
161185
assert.equal(result, "<html><p>This is <a href=\"something.html\" title=\"something\"><something/></a></p>\n\n</html>");
162-
done();
163-
},done).catch(done);
186+
});
164187
});
165-
166188
});

build/make_default_helpers.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
138138

139139
// Sort by docObject "ordered" property
140140
ordered.sort(function(x,y) {
141-
return x.docObject.order > y.docObject.order;
141+
return x.docObject.order - y.docObject.order;
142142
});
143143

144144
// Insert ordered items to their index in the alphabetical array
@@ -224,7 +224,7 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
224224
return "<!--####################################################################\n" +
225225
"\tTHIS IS A GENERATED FILE -- ANY CHANGES MADE WILL BE OVERWRITTEN\n\n" +
226226
'\tINSTEAD CHANGE:\n' +
227-
"\tsource: " + current.src +
227+
"\tsource: " + (current.src ? current.src.path : 'unknown') +
228228
(current.type ? '\n\t@' + current.type + " " + current.name : '') +
229229
"\n######################################################################## -->";
230230
},
@@ -267,23 +267,34 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
267267
var replacer = function (match, content) {
268268
var parts = content.match(linkRegExp),
269269
name,
270+
hashParts,
270271
description,
271272
linkText,
272-
docObject;
273+
docObject,
274+
href;
273275

274276
name = parts ? parts[1].replace('::', '.prototype.') : content;
275277

278+
//the name can be something like 'some-name#someId'
279+
//this allows linking to a specific section with the hash syntax (#27)
280+
hashParts = name.split("#");
281+
name = hashParts.shift();
282+
276283
docObject = docMap[name]
277284
if (docObject) {
278285
linkText = parts && parts[2] ? parts[2] : docObject.title || name;
279286
description = docObject.description || name;
280287

281-
return '<a href="' + urlTo(name) + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
288+
//if there is anything in the hashParts, append it to the end of the url
289+
href = urlTo(name) + (hashParts.length >= 1 ? ("#" + hashParts.join("#")) : "");
290+
291+
return '<a href="' + href + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
282292
}
283293

284294
if (httpRegExp.test(name)) {
285295
linkText = parts && parts[2] ? parts[2] : name;
286-
return '<a href="' + name + '" title="' + escape(linkText) + '">' + linkText + '</a>';
296+
href = name;
297+
return '<a href="' + href + '" title="' + escape(linkText) + '">' + linkText + '</a>';
287298
}
288299

289300
return match;
@@ -397,7 +408,9 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
397408
},
398409
docObjectString: function(){
399410
this.pathToRoot = pathToRoot(this.name);
400-
return JSON.stringify(deepExtendWithoutBody(this)).replace("</script>", "<\\/script>");
411+
412+
return JSON.stringify(deepExtendWithoutBody(this))
413+
.replace(/<\/script>/g, "<\\/script>");
401414
},
402415
pathToDest: function(){
403416
var currentDir = path.dirname( path.join(config.dest, docsFilename( getCurrent(), config)) );

0 commit comments

Comments
 (0)