mirror of
				https://github.com/JuanCanham/HackMyResume.git
				synced 2025-10-30 20:57:26 +00:00 
			
		
		
		
	Class-ify Underscore/Handlebars engine.
This commit is contained in:
		| @@ -17,9 +17,11 @@ Definition of the HandlebarsGenerator class. | |||||||
|  |  | ||||||
|   /** |   /** | ||||||
|   Perform template-based resume generation using Handlebars.js. |   Perform template-based resume generation using Handlebars.js. | ||||||
|   @method generate |   @class HandlebarsGenerator | ||||||
|   */ |   */ | ||||||
|   module.exports = function( json, jst, format, cssInfo, opts, theme ) { |   var HandlebarsGenerator = module.exports = { | ||||||
|  |  | ||||||
|  |     generate: function( json, jst, format, cssInfo, opts, 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 ) { | ||||||
| @@ -34,14 +36,15 @@ Definition of the HandlebarsGenerator class. | |||||||
|       // Compile and run the Handlebars template. |       // Compile and run the Handlebars template. | ||||||
|       var template = HANDLEBARS.compile(jst); |       var template = HANDLEBARS.compile(jst); | ||||||
|       return template({ |       return template({ | ||||||
|       r: json, |         r: format === 'html' || format === 'pdf' ? json.markdownify() : json, | ||||||
|  |         RAW: json, | ||||||
|         filt: opts.filters, |         filt: opts.filters, | ||||||
|         cssInfo: cssInfo, |         cssInfo: cssInfo, | ||||||
|         headFragment: opts.headFragment || '' |         headFragment: opts.headFragment || '' | ||||||
|       }); |       }); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -1,13 +1,24 @@ | |||||||
| /** | /** | ||||||
| Definition of the UnderscoreGenerator class. | Definition of the UnderscoreGenerator class. | ||||||
| @license MIT. Copyright (c) 2015 James Devlin / FluentDesk. | @license MIT. Copyright (c) 2015 James Devlin / FluentDesk. | ||||||
|  | @module underscore-generator.js | ||||||
| */ | */ | ||||||
|  |  | ||||||
| (function() { | (function() { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   var _ = require('underscore'); |   var _ = require('underscore'); | ||||||
|  |  | ||||||
|   module.exports = function( json, jst, format, cssInfo, opts, theme ) { |  | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |   Perform template-based resume generation using Underscore.js. | ||||||
|  |   @class UnderscoreGenerator | ||||||
|  |   */ | ||||||
|  |   var UnderscoreGenerator = module.exports = { | ||||||
|  |  | ||||||
|  |     generate: function( json, jst, format, cssInfo, opts, theme ) { | ||||||
|  |  | ||||||
|       // Tweak underscore's default template delimeters |       // Tweak underscore's default template delimeters | ||||||
|       var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template; |       var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template; | ||||||
| @@ -20,6 +31,7 @@ Definition of the UnderscoreGenerator class. | |||||||
|  |  | ||||||
|       // Strip {# comments #} |       // Strip {# comments #} | ||||||
|       jst = jst.replace( delims.comment, ''); |       jst = jst.replace( delims.comment, ''); | ||||||
|  |  | ||||||
|       // Compile and run the template. TODO: avoid unnecessary recompiles. |       // Compile and run the template. TODO: avoid unnecessary recompiles. | ||||||
|       var compiled = _.template(jst); |       var compiled = _.template(jst); | ||||||
|       var ret = compiled({ |       var ret = compiled({ | ||||||
| @@ -31,7 +43,10 @@ Definition of the UnderscoreGenerator class. | |||||||
|         headFragment: opts.headFragment || '' |         headFragment: opts.headFragment || '' | ||||||
|       }); |       }); | ||||||
|       return ret; |       return ret; | ||||||
|  |     } | ||||||
|  |  | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |    | ||||||
|  |  | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -143,7 +143,7 @@ Definition of the TemplateGenerator class. | |||||||
|     single: function( json, jst, format, cssInfo, opts, theme ) { |     single: function( json, jst, format, cssInfo, opts, theme ) { | ||||||
|       this.opts.freezeBreaks && ( jst = freeze(jst) ); |       this.opts.freezeBreaks && ( jst = freeze(jst) ); | ||||||
|       var eng = require( '../eng/' + theme.engine  + '-generator' ); |       var eng = require( '../eng/' + theme.engine  + '-generator' ); | ||||||
|       var result = eng( json, jst, format, cssInfo, opts, theme ); |       var result = eng.generate( json, jst, format, cssInfo, opts, theme ); | ||||||
|       this.opts.freezeBreaks && ( result = unfreeze(result) ); |       this.opts.freezeBreaks && ( result = unfreeze(result) ); | ||||||
|       return result; |       return result; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user