mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Support global theme partials (interim).
This commit is contained in:
parent
bc9f0d468f
commit
712b504168
@ -50,7 +50,7 @@
|
|||||||
"copy": "^0.1.3",
|
"copy": "^0.1.3",
|
||||||
"fresca": "~0.3.0",
|
"fresca": "~0.3.0",
|
||||||
"fresh-resume-empty": "^0.1.0",
|
"fresh-resume-empty": "^0.1.0",
|
||||||
"fresh-themes": "~0.11.0-beta",
|
"fresh-themes": "~0.12.0-beta",
|
||||||
"fs-extra": "^0.24.0",
|
"fs-extra": "^0.24.0",
|
||||||
"handlebars": "^4.0.5",
|
"handlebars": "^4.0.5",
|
||||||
"html": "0.0.10",
|
"html": "0.0.10",
|
||||||
@ -66,6 +66,7 @@
|
|||||||
"phantom": "^0.8.4",
|
"phantom": "^0.8.4",
|
||||||
"recursive-readdir-sync": "^1.0.6",
|
"recursive-readdir-sync": "^1.0.6",
|
||||||
"simple-html-tokenizer": "^0.2.0",
|
"simple-html-tokenizer": "^0.2.0",
|
||||||
|
"slash": "^1.0.0",
|
||||||
"string-padding": "^1.0.2",
|
"string-padding": "^1.0.2",
|
||||||
"string.prototype.startswith": "^0.2.0",
|
"string.prototype.startswith": "^0.2.0",
|
||||||
"underscore": "^1.8.3",
|
"underscore": "^1.8.3",
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
Definition of the HandlebarsGenerator class.
|
Definition of the HandlebarsGenerator class.
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
@license MIT. See LICENSE.md for details.
|
||||||
@module handlebars-generator.js
|
@module handlebars-generator.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
@ -11,7 +13,11 @@ Definition of the HandlebarsGenerator class.
|
|||||||
var _ = require('underscore')
|
var _ = require('underscore')
|
||||||
, HANDLEBARS = require('handlebars')
|
, HANDLEBARS = require('handlebars')
|
||||||
, FS = require('fs')
|
, FS = require('fs')
|
||||||
, registerHelpers = require('./handlebars-helpers');
|
, registerHelpers = require('./handlebars-helpers')
|
||||||
|
, PATH = require('path')
|
||||||
|
, parsePath = require('parse-filepath')
|
||||||
|
, READFILES = require('recursive-readdir-sync')
|
||||||
|
, SLASH = require('slash');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -21,8 +27,51 @@ Definition of the HandlebarsGenerator class.
|
|||||||
*/
|
*/
|
||||||
var HandlebarsGenerator = module.exports = {
|
var HandlebarsGenerator = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
initialized: false,
|
||||||
|
|
||||||
|
init: function( format, theme ) {
|
||||||
|
// TODO: Move .partialsInitialized to application state; shouldn't be on theme
|
||||||
|
if( !theme.partialsInitialized ) {
|
||||||
|
|
||||||
|
if( format !== 'html' && format != 'doc' )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Precompile global partials in the /partials folder
|
||||||
|
var partialsFolder = PATH.join(
|
||||||
|
parsePath( require.resolve('fresh-themes') ).dirname,
|
||||||
|
'/partials/',
|
||||||
|
format
|
||||||
|
);
|
||||||
|
|
||||||
|
_.each( READFILES( partialsFolder, function(error){ }), function( el ) {
|
||||||
|
|
||||||
|
var pathInfo = parsePath( el );
|
||||||
|
var name = SLASH( PATH.relative( partialsFolder, el )
|
||||||
|
.replace(/\.html$|\.xml$/, '') );
|
||||||
|
|
||||||
|
// section-employment, section-education, etc
|
||||||
|
if( pathInfo.dirname.endsWith('section') ) {
|
||||||
|
name = SLASH(name.replace(/\.html$|\.xml$/, ''));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var tplData = FS.readFileSync( el, 'utf8' );
|
||||||
|
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||||
|
HANDLEBARS.registerPartial( name, compiledTemplate );
|
||||||
|
theme.partialsInitialized = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
|
|
||||||
|
this.init( format, theme );
|
||||||
|
|
||||||
// Pre-compile any partials present in the theme.
|
// Pre-compile any partials present in the theme.
|
||||||
_.each( theme.partials, function( el ) {
|
_.each( theme.partials, function( el ) {
|
||||||
var tplData = FS.readFileSync( el.path, 'utf8' );
|
var tplData = FS.readFileSync( el.path, 'utf8' );
|
||||||
@ -52,6 +101,7 @@ Definition of the HandlebarsGenerator class.
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
}());
|
}());
|
||||||
|
@ -235,6 +235,7 @@ Definition of the TemplateGenerator class.
|
|||||||
// Verify the specified theme name/path
|
// Verify the specified theme name/path
|
||||||
var tFolder = PATH.join(
|
var tFolder = PATH.join(
|
||||||
parsePath( require.resolve('fresh-themes') ).dirname,
|
parsePath( require.resolve('fresh-themes') ).dirname,
|
||||||
|
'/themes/',
|
||||||
this.opts.theme
|
this.opts.theme
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -307,6 +307,7 @@ Implementation of the 'generate' verb for HackMyResume.
|
|||||||
function verify_theme( themeNameOrPath ) {
|
function verify_theme( themeNameOrPath ) {
|
||||||
var tFolder = PATH.join(
|
var tFolder = PATH.join(
|
||||||
parsePath ( require.resolve('fresh-themes') ).dirname,
|
parsePath ( require.resolve('fresh-themes') ).dirname,
|
||||||
|
'/themes/',
|
||||||
themeNameOrPath
|
themeNameOrPath
|
||||||
);
|
);
|
||||||
var exists = require('path-exists').sync;
|
var exists = require('path-exists').sync;
|
||||||
|
Loading…
Reference in New Issue
Block a user