diff --git a/.gitignore b/.gitignore index 7283991..4385c06 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ site/static/build/ site/static/dist/ site/templates/ test/tmp -.idea/ \ No newline at end of file +.idea/ +.vscode +.DS_Store diff --git a/build/build_test.js b/build/build_test.js index efc40e1..1343a6d 100644 --- a/build/build_test.js +++ b/build/build_test.js @@ -1,42 +1,40 @@ -require("./make_default_helpers_test"); - +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); +var Q = require('q'); +var rimraf = require('rimraf'); var getRenderer = require('./get_renderer'); var getPartials = require('./get_partials'); var build = require("./build"); -var assert = require('assert'); -var Q = require('q'); -var path = require('path'); -var rmdir = require('rimraf'); -var fs = require('fs'); + +var rmdir = Q.denodeify(rimraf); var read = Q.denodeify(fs.readFile); -describe("documentjs/lib/generators/html/build",function(){ +require("./make_default_helpers_test"); + +describe("documentjs/lib/generators/html/build", function(){ - beforeEach(function(done){ - rmdir(path.join(__dirname,"..","site","static"), function(e){ - rmdir(path.join(__dirname,"..","site","templates"), done); + beforeEach(function(){ + return rmdir(path.join(__dirname, "..", "site", "static")).then(function(){ + return rmdir(path.join(__dirname, "..", "site", "templates")); }); }); - it("get_renderer and get_partial work",function(done){ - Q.all([ + it("get_renderer and get_partial work", function(){ + return Q.all([ getRenderer('build/test/templates'), getPartials('build/test/templates') ]).then(function(results){ - var renderer = results[0]; - var result = renderer({subject: "World"}); assert.equal(result, "
static
"); - done(); - },done).catch(done); + }); }); @@ -116,7 +108,7 @@ describe("documentjs/lib/generators/html/build",function(){ } } }).then(function(result){ - return read(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js")); + return read(path.join(__dirname, "..", result.distFolder, "bundles", "bit-docs-site", "static.js")); }).then(function(res){ assert.ok(/can-component/.test(res), "got static.js with component"); }); @@ -154,9 +146,11 @@ describe("documentjs/lib/generators/html/build",function(){ }); }); - it("makes linked content",function(done){ + it("makes linked content", function(){ var options = { - html: { templates: path.join(__dirname,"test","escaped") }, + html: { + templates: path.join(__dirname, "test", "escaped") + }, dest: "XXXXYYYZZZ", forceBuild: true, pageConfig: { @@ -181,18 +175,14 @@ describe("documentjs/lib/generators/html/build",function(){ something: {name: "something", title: "first<\/code>/.test(""+data), "got first" );
- done();
- });
-
- },done);
+ return html.generate(docMap,options);
+ }).then(function(){
+ return readFile(path.join(__dirname, "test", "tmp", "index.html"));
+ }).then(function(data){
+ assert.ok(/first<\/code>/.test(""+data), "got first");
});
});
it("closing script tags are properly escaped", function() {
this.timeout(40000);
- return Q.denodeify(rmdir)(path.join(__dirname,"test","tmp"))
- .then(function() {
- var options = {
- dest: path.join(__dirname, "test","tmp"),
- parent: "index",
- templateRender: true
- };
-
- var docMap = Q.Promise(function(resolve){
- resolve(_.assign({
- index: {
- name: "index",
- type: "page",
- body: [
- "Hello `{{thing.params.0.script}}`",
- "Load steal using \n\n `{{thing.params.1.script}}`"
- ].join("\n")
- },
- thing: {
- name: "thing",
- params: [
- {script: ""},
- {script: ""}
- ]
- }
- }));
- });
-
- return html.generate(docMap, options);
- })
- .then(function() {
- return readFile(path.join(__dirname, "test", "tmp", "index.html"));
- })
- .then(function(data) {
- var index = data.toString();
-
- assert.ok(
- index.includes("<script>function() {return true; }<\/script><\/code>"),
- "script closing tag escaped"
- );
- })
- .then(function() {
- return readFile(path.join(__dirname, "test", "tmp", "thing.html"));
- })
- .then(function(data) {
- var content = data.toString();
- var rx = /<\/script>/g;
-
- var docObject = content.substring(
- content.indexOf("var docObject = "),
- content.indexOf("};", content.indexOf("var docObject = "))
- );
+ return rmdir(path.join(__dirname, "test", "tmp")).then(function() {
+ var options = {
+ dest: path.join(__dirname, "test", "tmp"),
+ parent: "index",
+ templateRender: true
+ };
- assert.ok(
- !rx.test(docObject),
- "docObject should not have unscaped closing script tags"
- );
+ var docMap = Q.Promise(function(resolve){
+ resolve(_.assign({
+ index: {
+ name: "index",
+ type: "page",
+ body: [
+ "Hello `{{thing.params.0.script}}`",
+ "Load steal using \n\n `{{thing.params.1.script}}`"
+ ].join("\n")
+ },
+ thing: {
+ name: "thing",
+ params: [
+ {script: ""},
+ {script: ""}
+ ]
+ }
+ }));
});
+
+ return html.generate(docMap, options);
+ })
+ .then(function() {
+ return readFile(path.join(__dirname, "test", "tmp", "index.html"));
+ })
+ .then(function(data) {
+ var index = data.toString();
+ assert.ok(
+ index.includes("<script>function() {return true; }<\/script><\/code>"),
+ "script closing tag escaped"
+ );
+ })
+ .then(function() {
+ return readFile(path.join(__dirname, "test", "tmp", "thing.html"));
+ })
+ .then(function(data) {
+ var content = data.toString();
+ var rx = /<\/script>/g;
+ var docObject = content.substring(
+ content.indexOf("var docObject = "),
+ content.indexOf("};", content.indexOf("var docObject = "))
+ );
+
+ assert.ok(
+ !rx.test(docObject),
+ "docObject should not have unscaped closing script tags"
+ );
+ });
});
- it("slashes get put in a folder and can link correctly", function(done){
- this.timeout(40000);
- rmdir(path.join(__dirname,"test","tmp"), function(e){
- if(e) {
- return done(e);
- }
+ it("slashes get put in a folder and can link correctly", function(){
+ this.timeout(240000);
+ return rmdir(path.join(__dirname, "test", "tmp")).then(function(){
var options = {
- dest: path.join(__dirname, "test","tmp"),
+ dest: path.join(__dirname, "test", "tmp"),
parent: "index"
};
-
var docMap = Q.Promise(function(resolve){
resolve(_.assign({
index: {
@@ -185,38 +166,24 @@ describe("documentjs/lib/generators/html",function(){
}));
});
- html.generate(docMap,options).then(function(){
- fs.readFile(
- path.join(__dirname,"test","tmp","module","name.html"),
- function(err, data){
- if(err) {
- done(err);
- }
-
-
- assert.ok( (""+data).indexOf('src="../static/node_modules/steal/steal.production.js"') !== -1, "got the right path to scripts" );
- assert.ok( (""+data).indexOf('href="../static/bundles/bit-docs-site/static.css"') !== -1, "got the right path to styles" );
- assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" );
-
- done();
- });
-
- },done);
+ return html.generate(docMap,options);
+ }).then(function(){
+ return readFile(path.join(__dirname, "test", "tmp", "module", "name.html"));
+ }).then(function(data){
+ assert.ok((""+data).indexOf('src="../static/steal.production.js"') !== -1, "got the right path to scripts");
+ assert.ok((""+data).indexOf('href="../static/bundles/bit-docs-site/static.css"') !== -1, "got the right path to styles");
+ assert.ok((""+data).indexOf('index') !== -1, "got the right thing to index");
});
});
- it("dest on docObject works", function(done){
- this.timeout(40000);
- rmdir(path.join(__dirname,"test","tmp"), function(e){
- if(e) {
- return done(e);
- }
+ it("dest on docObject works", function(){
+ this.timeout(240000);
+ return rmdir(path.join(__dirname, "test", "tmp")).then(function(){
var options = {
- dest: path.join(__dirname, "test","tmp","deep"),
+ dest: path.join(__dirname, "test", "tmp", "deep"),
parent: "index"
};
-
var docMap = Q.Promise(function(resolve){
resolve(_.assign({
index: {
@@ -232,37 +199,23 @@ describe("documentjs/lib/generators/html",function(){
}));
});
- html.generate(docMap,options).then(function(){
- fs.readFile(
- path.join(__dirname,"test","tmp","deep","module","name.html"),
- function(err, data){
- if(err) {
- done(err);
- }
-
-
- assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" );
-
- done();
- });
-
- },done);
+ return html.generate(docMap,options);
+ }).then(function(){
+ return readFile(path.join(__dirname, "test", "tmp", "deep", "module", "name.html"));
+ }).then(function(data){
+ assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" );
});
});
- it("basic sidebar works", function(done){
- this.timeout(40000);
- rmdir(path.join(__dirname,"test","tmp"), function(e){
- if(e) {
- return done(e);
- }
+ it("basic sidebar works", function(){
+ this.timeout(240000);
+ return rmdir(path.join(__dirname, "test", "tmp")).then(function(){
var options = {
- dest: path.join(__dirname, "test","tmp","sidebar"),
+ dest: path.join(__dirname, "test", "tmp", "sidebar"),
parent: "earth",
forceBuild: true
};
-
var docMap = Q.Promise(function(resolve){
resolve(_.assign({
earth: {
@@ -270,32 +223,32 @@ describe("documentjs/lib/generators/html",function(){
type: "page",
body: "Welcome to earth"
},
- "Americas": {
+ Americas: {
parent: "earth",
name: "Americas",
body: "Americas"
},
- "USA": {
+ USA: {
parent: "Americas",
name: "USA",
body: "USA"
},
- "Mexico": {
+ Mexico: {
parent: "Americas",
name: "Mexico",
body: "Mexico"
},
- "Asia": {
+ Asia: {
parent: "earth",
name: "Asia",
body: "Asia"
},
- "China": {
+ China: {
parent: "Asia",
name: "China",
body: "China"
},
- "India": {
+ India: {
parent: "Asia",
name: "India",
body: "India"
@@ -303,23 +256,12 @@ describe("documentjs/lib/generators/html",function(){
}));
});
- html.generate(docMap,options).then(function(){
- fs.readFile(
- path.join(__dirname,"test","tmp","sidebar","India.html"),
- function(err, data){
- if(err) {
- done(err);
- }
-
- assert.ok( (""+data).indexOf('href="Asia.html"') !== -1, "link to asia" );
- assert.ok( (""+data).indexOf('href="China.html"') !== -1, "link to china" );
-
- done();
- });
-
- },done);
+ return html.generate(docMap,options);
+ }).then(function(){
+ return readFile(path.join(__dirname, "test", "tmp", "sidebar", "India.html"));
+ }).then(function(data){
+ assert.ok( (""+data).indexOf('href="Asia.html"') !== -1, "link to asia" );
+ assert.ok( (""+data).indexOf('href="China.html"') !== -1, "link to china" );
});
});
-
-
});
diff --git a/package.json b/package.json
index ff066bd..f0e7c54 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,8 @@
"handlebars": "1.X",
"lodash": "~4.13.1",
"md5": "2.1.0",
- "steal-tools": "0.16.X",
+ "q": "^1.5.0",
+ "steal-tools": "^1.8.0",
"striptags": "^2.1.1",
"unescape-html": "^1.0.0"
},
diff --git a/site/default/static/build.js b/site/default/static/build.js
index e57e7ac..ac36628 100644
--- a/site/default/static/build.js
+++ b/site/default/static/build.js
@@ -44,7 +44,7 @@ module.exports = function(options, folders){
if(options.debug) {
console.log("BUILD: Copying build to dist.");
}
-
+
staticDistPromises.push(fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist)));
return Q.all(staticDistPromises);
diff --git a/site/default/static/package.json b/site/default/static/package.json
index 11f3fbc..27d5328 100644
--- a/site/default/static/package.json
+++ b/site/default/static/package.json
@@ -6,10 +6,15 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
+ "steal": {
+ "plugins": [
+ "steal-less"
+ ]
+ },
"author": "Bitovi",
"license": "MIT",
"dependencies": {
- "steal": "0.16.X"
- },
- "system": {"npmAlgorithm": "flat"}
+ "steal-less": "^1.2.0",
+ "steal-tools": "^1.8.0"
+ }
}
diff --git a/site/default/templates/layout.mustache b/site/default/templates/layout.mustache
index 2dc4c0d..3dcb3f3 100644
--- a/site/default/templates/layout.mustache
+++ b/site/default/templates/layout.mustache
@@ -32,7 +32,7 @@
+ src="{{pathToDest}}/static/steal.production.js">
{{/if}}