diff --git a/src/core/error-handler.js b/src/core/error-handler.js index ac4efe4..2c84d74 100644 --- a/src/core/error-handler.js +++ b/src/core/error-handler.js @@ -29,7 +29,7 @@ Error-handling routines for HackMyResume. err: function( ex, shouldExit ) { - var msg = '', exitCode, log = console.log, showStack = false; + var msg = '', exitCode, log = console.log, showStack = ex.showStack; // If the exception has been handled elsewhere and shouldExit is true, // let's get out of here, otherwise silently return. diff --git a/src/core/jrs-theme.js b/src/core/jrs-theme.js index 4f2942a..6f4993e 100644 --- a/src/core/jrs-theme.js +++ b/src/core/jrs-theme.js @@ -16,8 +16,7 @@ Definition of the JRSTheme class. /** - The JRSTheme class is a representation of a JSON Resume - theme asset. See also: FRESHTheme. + The JRSTheme class is a representation of a JSON Resume theme asset. @class JRSTheme */ function JRSTheme() { @@ -41,12 +40,31 @@ Definition of the JRSTheme class. // Open and parse the theme's package.json file. var pkgJsonPath = PATH.join( thFolder, 'package.json' ); if( pathExists( pkgJsonPath )) { + var thApi = require( thFolder ) , thPkg = require( pkgJsonPath ); + this.name = thPkg.name; this.render = (thApi && thApi.render) || undefined; + this.engine = 'jrs'; + + // Create theme formats (HTML and PDF) this.formats = { - html: { title:'html', outFormat:'html', ext:'html' } + html: { outFormat: 'html', files: [ + { + action: 'transform', + render: this.render, + //path: absPath, + major: true, + //orgPath: PATH.relative(thFolder, absPath), + ext: pathInfo.extname.slice(1), + //title: friendlyName( outFmt ), + //pre: outFmt, + // outFormat: outFmt || pathInfo.name, + //data: FS.readFileSync( absPath, 'utf8' ), + css: null + } + ]} }; } else { diff --git a/src/eng/jrs-generator.js b/src/eng/jrs-generator.js new file mode 100644 index 0000000..17d26fe --- /dev/null +++ b/src/eng/jrs-generator.js @@ -0,0 +1,76 @@ +/** +Definition of the JRSGenerator class. +@license MIT. See LICENSE.md for details. +@module jrs-generator.js +*/ + + + +(function() { + + + + var _ = require('underscore') + , HANDLEBARS = require('handlebars') + , FS = require('fs') + , registerHelpers = require('./handlebars-helpers') + , PATH = require('path') + , parsePath = require('parse-filepath') + , READFILES = require('recursive-readdir-sync') + , SLASH = require('slash') + , MD = require('marked'); + + + + /** + Perform template-based resume generation for JSON Resume themes. + @class JRSGenerator + */ + var JRSGenerator = module.exports = { + + + + + generate: function( json, jst, format, cssInfo, opts, theme ) { + + // JSON Resume themes don't have a specific structure, so the safest thing + // to do is copy all files from source to dest. + // var COPY = require('copy'); + // var globs = [ '*.css', '*.js', '*.png', '*.jpg', '*.gif', '*.bmp' ]; + // COPY.sync( globs , outFolder, { + // cwd: theme.folder, nodir: true, + // ignore: ['node_modules/','node_modules/**'] + // // rewrite: function(p1, p2) { + // // return PATH.join(p2, p1); + // // } + // }); + + // Disable JRS theme chatter (console.log, console.error, etc.) + var off = ['log', 'error', 'dir'], org = off.map(function(c){ + var ret = console[c]; console[c] = function(){}; return ret; + }); + + // Freeze and render + var rezHtml = theme.render( json.harden() ); + + // Turn logging back on + off.forEach(function(c, idx){ console[c] = org[idx]; }); + + // Unfreeze and apply Markdown + rezHtml = rezHtml.replace( /@@@@~.*?~@@@@/gm, function(val){ + return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) ); + }); + + return rezHtml; + } + + + }; + + + function MDIN(txt) { // TODO: Move this + return MD(txt || '' ).replace(/^\s*
|<\/p>\s*$/gi, ''); + } + + +}()); diff --git a/src/gen/html-pdf-cli-generator.js b/src/gen/html-pdf-cli-generator.js index ad360e1..c5921a5 100644 --- a/src/gen/html-pdf-cli-generator.js +++ b/src/gen/html-pdf-cli-generator.js @@ -20,7 +20,8 @@ Definition of the HtmlPdfCLIGenerator class. /** An HTML-driven PDF resume generator for HackMyResume. Talks to Phantom, - wkhtmltopdf, and other PDF libraries over a CLI. + wkhtmltopdf, and other PDF engines over a CLI (command-line interface). + If an engine isn't installed for a particular platform, error out gracefully. */ var HtmlPdfCLIGenerator = module.exports = TemplateGenerator.extend({ @@ -36,6 +37,7 @@ Definition of the HtmlPdfCLIGenerator class. Generate the binary PDF. */ onBeforeSave: function( info ) { + console.log('Called'); try { var safe_eng = info.opts.pdf || 'wkhtmltopdf'; engines[ safe_eng ].call( this, info.mk, info.outputFile ); @@ -50,16 +52,23 @@ Definition of the HtmlPdfCLIGenerator class. } } + + }); + // TODO: Move each engine to a separate module var engines = { /** - Generate a PDF from HTML using wkhtmltopdf. + Generate a PDF from HTML using wkhtmltopdf's CLI interface. + Spawns a child process with `wkhtmltopdf