Skip to content

Commit 494f9b7

Browse files
authored
Merge branch 'master' into new-functionality
2 parents 9263a3a + a095f73 commit 494f9b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1043
-612
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
package-lock.json
12
node_modules
23
site/static/
34
site/static/build/
45
site/static/dist/
56
site/templates/
67
test/tmp
7-
.idea/
8+
.idea/
9+
.vscode
10+
.DS_Store

bit-docs.js

Lines changed: 27 additions & 5 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

@@ -14,13 +17,31 @@ var mergeOnto = function(prop, dest, source){
1417
* @group bit-docs-generate-html/modules modules
1518
* @group bit-docs-generate-html/static static
1619
* @group bit-docs-generate-html/templates templates
20+
* @group bit-docs-generate-html/generated generated
1721
* @group bit-docs-generate-html/types types
1822
*
19-
* @description Generates HTML for a docMap. Supports plugins.
23+
* @description Generates HTML for a docMap and handles the `html` hook.
2024
*
2125
* @body
2226
*
23-
* TBD
27+
* This plugin registers onto these hooks:
28+
* - `tags`
29+
* - `generator`
30+
*
31+
* Registering the `tags` hook adds the `@templaterender` tag.
32+
*
33+
* Registering the `generator` hook makes it so this plugin can generate the
34+
* HTML output from the provided [bit-docs/types/docMap]. The entry point for
35+
* this generator is [bit-docs-generate-html/html].
36+
*
37+
* This plugin handles the `html` hook, which allows other plugins to hook into
38+
* the generation process, to do things like include their own static assets,
39+
* or provide their own mustache templates.
40+
*
41+
* This plugin provides a default set of mustache templates and static assets.
42+
* These mustache templates and less styles can be copied over into a theme
43+
* plugin and customized. Any custom mustache template will override a default
44+
* of the same name.
2445
*/
2546
module.exports = function(bitDocs){
2647
bitDocs.register("generator", generator);
@@ -32,12 +53,13 @@ module.exports = function(bitDocs){
3253
siteConfig.html = {
3354
dependencies: {},
3455
static: [],
35-
templates: []
56+
templates: [],
57+
staticDist: []
3658
};
3759
}
3860
var html = siteConfig.html;
3961
_.assign(html.dependencies, htmlConfig.dependencies || {});
40-
62+
mergeOnto("staticDist", html, htmlConfig);
4163
mergeOnto("static", html, htmlConfig);
4264
mergeOnto("templates", html, htmlConfig);
4365
});

build/build.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
/**
2-
* @property {{}} documentjs.generators.html.build
3-
* @parent documentjs.generators.html.properties
2+
* @parent bit-docs-generate-html/modules
3+
* @module {{}} bit-docs-generate-html/build/build
44
*
5-
* @group documentjs.generators.html.build.methods 0 methods
6-
* @group documentjs.generators.html.build.types 1 types
7-
*
8-
* A collection of helpers used to build and compile the templates
9-
* used to render each [documentjs.process.docObject docObject] into
10-
* HTML and build the static JS and CSS used by that HTML.
5+
* A collection of helpers used to build and compile the templates used to
6+
* render each [bit-docs/types/docObject] into HTML and build the static JS and
7+
* CSS used by that HTML.
118
*
129
* @body
1310
*
11+
* Requires and exports these other modules:
12+
* - [bit-docs-generate-html/build/renderer] as `renderer`.
13+
* - [bit-docs-generate-html/build/static_dist] as `staticDist`.
14+
* - [bit-docs-generate-html/build/templates] as `templates`.
15+
* - [bit-docs-generate-html/build/helpers] as `helpers`.
1416
*/
15-
16-
17-
1817
exports.renderer = require("./renderer");
1918
exports.staticDist = require("./static_dist");
2019
exports.templates = require("./templates");
21-
exports.helpers = require("./helpers");
20+
exports.helpers = require("./helpers");

build/build_hash.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
var md5 = require('md5');
22

33
/**
4-
* @function documentjs.generators.html.build.buildHash
5-
* @parent documentjs.generators.html.build.methods
4+
* @parent bit-docs-generate-html/modules
5+
* @module {function} bit-docs-generate-html/build/build_hash
66
*
77
* Returns a unique hash for the options that control the build.
88
*
9-
* @signature `.build.buildHash(options)`
9+
* @signature `buildHash(options)`
1010
*
1111
* @param {{}} options Options that might change the characteristic of the build:
1212
*
13-
* @option {Boolean} [minifyBuild=true] If set to `false` the build will not
14-
* be minified. This behavior should be implemented by the "build" module.
13+
* @option {Boolean} [minifyBuild=true] If set to `false` the build will not be
14+
* minified. This behavior should be implemented by the "build" module.
15+
*
16+
* @option {Boolean} [devBuild=false] If set to `true` the build will not be
17+
* built and copied in "development" mode.
18+
*
19+
* @option {String} static The location of static content used to overwrite or
20+
* add to the default static content.
21+
*
22+
* @option {String} [templates] The location of templates used to overwrite or
23+
* add to the default templates.
1524
*
16-
* @option {Boolean} [devBuild=false] If set to `true` the build will not be built
17-
* and copied in "development" mode.
18-
*
19-
* @option {String} static The location of static content used to overwrite or
20-
* add to the default static content.
21-
*
22-
* @option {String} [templates] The location of templates used to overwrite or
23-
* add to the default templates.
25+
* @return {String} a hash that represents this build.
2426
*
27+
* @body
2528
*
26-
* @return {String} a hash that represents this build.
29+
* The generated hash will be something like `917c51373c902dc4a003c7fd949774c5`.
2730
*/
2831
module.exports = function(options){
2932
var values = {};

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/builder.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)