Last active
August 29, 2015 14:27
-
-
Save paulovieira/a7788e22238f46727e09 to your computer and use it in GitHub Desktop.
client states
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Fs = require("fs-extra"); | |
//var slugify = require("underscore.string/slugify"); | |
var _s = require("underscore.string"); | |
var states = require("./lib/index.js"); | |
// var Cheerio = require("cheerio"); | |
// var $ = Cheerio.load("<div id='a'><span id='b'>xyz</span><span id='b'>123</span></div>") | |
// console.log($("#b").length) | |
// states.registerEngine("nunjucks", require('nunjucks')); | |
// states.registerEngine("hogan", require('hogan.js')); | |
var Nunjucks = require('nunjucks'); | |
Nunjucks.configure(__dirname, { | |
autoescape: true, | |
watch: false | |
}); | |
var Hogan = require('hogan.js'); | |
states.registerEngine({ | |
nunjucks: Nunjucks, | |
hogan: Hogan | |
}); | |
var Nunjucks = states.getEngine("nunjucks"); | |
var Hogan = states.getEngine("hogan"); | |
[1,2,3].map(log); | |
var output = states | |
.loadDocuments("documents/*.html") | |
.loadTemplates({ | |
path: "templates/abc/*.html", | |
}) | |
.loadTemplates({ | |
path: "templates/xyz/*.html", | |
engine: "hogan" | |
}) | |
// .loadStates("states/*/state*.json") | |
// .renderStates("states/*/state*.json") | |
.loadStates("states/*/state*.json") | |
.renderStates("states/*/state*.json") | |
.getStates() | |
.map(function(s){ | |
return { | |
path: s.path, | |
description: s.description, | |
documentHtml: s.documentHtml, | |
url: "all-states/" + _s(s.path).slugify().slice(0,-5).value() + ".html" | |
} | |
}); | |
output.forEach(function(s){ | |
console.log("-------------------------"); | |
console.log("path: ", s.path); | |
console.log("description: ", s.description); | |
console.log("documentHtml:\n\n ", s.documentHtml.default); | |
}); | |
var listingState = states | |
.loadTemplates("templates/listing/listing.html") | |
.loadTemplates({ | |
path: "templates/listing/state-item.html", | |
ctx: output | |
}) | |
.loadStates("states/listing/listing.json") | |
.renderStates("states/listing/listing.json") | |
.getStates("states/listing/listing.json"); | |
Fs.ensureDirSync("states/listing/output/all-states"); | |
Fs.writeFileSync("states/listing/output/index.html", listingState[0].documentHtml.default); | |
output.forEach(function(s){ | |
var filename =_s(s.path).slugify().slice(0,-5).value() + ".html"; | |
Fs.writeFileSync("states/listing/output/all-states/" + filename, s.documentHtml.default); | |
}); | |
// .forEach(function(s){ | |
// console.log("-------------------------"); | |
// console.log("path: ", s.path); | |
// console.log("description: ", s.description); | |
// console.log("documentHtml:\n\n ", s.documentHtml.default); | |
// }); | |
/* | |
*/ | |
// .renderStates({ | |
// path: "states/123/*.json", | |
// }) | |
// .renderStates({ | |
// path: "states/123/state1.json", | |
// ctxKey: "en", | |
// documentPath: "documents/doc-lang-pt.html", | |
// insertIn: "#main-container" | |
// }) | |
// .renderStates({ | |
// path: "states/456/*", | |
// }) | |
// states.renderStates({ | |
// path: "states/123/state1.json", | |
// ctxKey: "en", | |
// documentPath: "documents/doc-lang-pt.html" | |
// }); | |
// var state1 = states.getState("states/123/state1.json"); | |
// console.log("\n\n===============\n"); | |
// console.log("State description: ", state1.description) | |
// console.log("\nFinal html (default): \n\n", state1.documentHtml.default) | |
//console.log("\nFinal html (en): \n\n", state1.documentHtml.en) | |
// var state2 = states.getState("states/123/state2.json"); | |
// console.log("\n\n===============\n"); | |
// console.log("State description: ", state2.description) | |
// console.log("\nFinal html (default): \n\n", state2.documentHtml.default) | |
// var state3 = states.getState("states/456/state3.json"); | |
// console.log("\n\n===============\n"); | |
// console.log("State description: ", state3.description) | |
// console.log("\nFinal html (default): \n\n", state3.documentHtml.default) | |
// var state1 = states.getState("states/123/state1.json"); | |
// console.log("\n\n===============\n"); | |
// console.log("State description: ", state1.description) | |
// console.log("\nFinal html (default): \n\n", state1.documentHtml.default) | |
// console.log("\nFinal html (en): \n\n", state1.documentHtml.en) | |
// var state3 = states.getState("states/456/state3.json"); | |
// console.log("\n\n===============\n"); | |
// console.log("State description: ", state3.description) | |
// console.log("\nFinal html: \n\n", state3.documentHtml.default) | |
// debugger; | |
// var t = states.getTemplate("templates/abc/name.html"); | |
// console.log(t); | |
// console.log(t.$.default.html()) | |
// var x = 1; | |
// var d = states.getDocuments("documents/*"); | |
// console.log(d) | |
// var d = states.getDocument("documents/doc-lang-fr.html"); | |
// console.log(d) | |
| fewfw | | |
| | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment