mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 12:27:08 +01:00
Support global theme partials (interim).
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
/**
|
||||
Definition of the HandlebarsGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module handlebars-generator.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
@ -11,7 +13,11 @@ Definition of the HandlebarsGenerator class.
|
||||
var _ = require('underscore')
|
||||
, HANDLEBARS = require('handlebars')
|
||||
, 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 = {
|
||||
|
||||
|
||||
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 ) {
|
||||
|
||||
this.init( format, theme );
|
||||
|
||||
// Pre-compile any partials present in the theme.
|
||||
_.each( theme.partials, function( el ) {
|
||||
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
|
||||
var tFolder = PATH.join(
|
||||
parsePath( require.resolve('fresh-themes') ).dirname,
|
||||
'/themes/',
|
||||
this.opts.theme
|
||||
);
|
||||
|
||||
|
@ -307,6 +307,7 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
function verify_theme( themeNameOrPath ) {
|
||||
var tFolder = PATH.join(
|
||||
parsePath ( require.resolve('fresh-themes') ).dirname,
|
||||
'/themes/',
|
||||
themeNameOrPath
|
||||
);
|
||||
var exists = require('path-exists').sync;
|
||||
|
Reference in New Issue
Block a user