From c9ec8a81a00dc8c7185566b756ad061adbf97c45 Mon Sep 17 00:00:00 2001 From: James Devlin Date: Tue, 8 Sep 2015 23:05:12 -0400 Subject: [PATCH] Introduce "Sheet" class. Start formalizing some of the key domain nouns, starting with the concept of the "sheet" or "character sheet". --- src/scrappy.js | 14 +++++++------- src/sheet.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/sheet.js diff --git a/src/scrappy.js b/src/scrappy.js index 336d977..0cab22a 100644 --- a/src/scrappy.js +++ b/src/scrappy.js @@ -12,7 +12,8 @@ module.exports = function () { , XML = require( 'xml-escape' ) , path = require( 'path' ) , extend = require( './extend' ) - , _ = require('underscore'); + , _ = require('underscore') + , Sheet = require('./sheet'); String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; @@ -48,20 +49,19 @@ module.exports = function () { // Assemble input resumes var sheets = src.map( function( res ) { console.log( 'Reading JSON resume: ' + res ); - var raw = FS.readFileSync( res, 'utf8' ); - return JSON.parse( raw ); + return (new Sheet()).open( res ); }); // Merge input resumes rez = sheets.reduce( function( acc, elem ) { - return extend(true, acc, elem); + return extend(true, acc.rep, elem.rep); }); // Run the transformation! var finished = targets.map( gen ); return { - sheet: rez, + sheet: rez.rep, targets: targets, processed: finished }; @@ -85,11 +85,11 @@ module.exports = function () { var mk = FS.readFileSync( themeFile, 'utf8' ); // Compile and invoke the template - mk = single( rez, mk, fName, cssData ); + mk = single( rez.rep, mk, fName, cssData ); // Post-process and save the file fName === 'html' && (mk = html( mk, themeFile, fOut )); - fName === 'pdf' && pdf( mk, fOut ); + //fName === 'pdf' && pdf( mk, fOut ); fName !== 'pdf' && FS.writeFileSync( fOut, mk, 'utf8' ); return mk; diff --git a/src/sheet.js b/src/sheet.js new file mode 100644 index 0000000..37435f6 --- /dev/null +++ b/src/sheet.js @@ -0,0 +1,21 @@ +(function() { + +var FS = require('fs'); + +function Sheet() { + + this.id = null; + this.title = ""; + this.sheets = []; + this.rep = { }; + +} + +Sheet.prototype.open = function( file ) { + this.rep = JSON.parse( FS.readFileSync( file, 'utf8' ) ); + return this; +}; + +module.exports = Sheet; + +}());