Skip to content

Commit

Permalink
ABE-170
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Sep 4, 2016
1 parent 7d23620 commit ab245d0
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 225 deletions.
4 changes: 2 additions & 2 deletions src/cli/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Builder {

Util.getDataList(fileUtils.removeLast(json.abe_meta.link), text, json)
.then(() => {
var page = new Page(json.abe_meta.link, text, json, true)
var page = new Page(json.abe_meta.template, text, json, true)
saveHtml(fileUtils.concatPath(root, dest + json.abe_meta.link), page.html)
if(files[index + 1]) build(index + 1)
}).catch(function(e) {
Expand All @@ -50,7 +50,7 @@ class Builder {

Util.getDataList(fileUtils.removeLast(json.abe_meta.link), text, json)
.then(() => {
var page = new Page(json.abe_meta.link, text, json, true)
var page = new Page(json.abe_meta.template, text, json, true)
saveHtml(fileUtils.concatPath(root, dest + json.abe_meta.link), page.html)
if(files[index + 1]) build(index + 1)
}).catch(function(e) {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/config/abe-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ var config = {
templates: {
extension: 'html',
assets: '_files',
check: /\.hbs|\.shtml|\.html|\.htm/
check: /\.hbs|\.shtml|\.html|\.htm/,
precompile: false
}
},
log: {
Expand Down
30 changes: 27 additions & 3 deletions src/cli/models/Manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import Handlebars from 'handlebars'
import fse from 'fs-extra'
import mkdirp from 'mkdirp'
import {
FileParser
config,
FileParser,
fileUtils,
folderUtils
} from '../../cli'

let singleton = Symbol()
Expand All @@ -8,10 +14,13 @@ let singletonEnforcer = Symbol()
class Manager {

constructor(enforcer) {

if(enforcer != singletonEnforcer) throw "Cannot construct Json singleton"

this._list = FileParser.getAllFiles();
this._list[0].files.sort(FileParser.predicatBy('date',-1));
Handlebars.templates = Handlebars.templates || {};
this.loadHbsTemplates();

this.updateList()
}

static get instance() {
Expand All @@ -33,6 +42,21 @@ class Manager {

return this
}

loadHbsTemplates() {
const path = fileUtils.concatPath(config.root, config.templates.url, 'hbs');

if(!folderUtils.isFolder(path)) {
mkdirp.sync(path)
}

fse.readdirSync(path).forEach(function (file) {
if (file.indexOf(".hbs") > -1) {
var tmpl = eval("(function(){return " + fse.readFileSync(fileUtils.concatPath(path, file)) + "}());");
Handlebars.templates[file.replace('.hbs', '')] = Handlebars.template(tmpl);
}
})
}
}

export default Manager
Loading

0 comments on commit ab245d0

Please sign in to comment.