Skip to content

Commit

Permalink
Integrate with HackMyResume!
Browse files Browse the repository at this point in the history
  • Loading branch information
hacksalot committed Jan 24, 2016
1 parent 2fc48e0 commit 33d8eb9
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 60 deletions.
97 changes: 74 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# grunt-hackmyresume

> Grunt plugin for HackMyResume.
> Grunt plugin for [HackMyResume](https://github.com/hacksalot/HackMyResume).
## Getting Started
This plugin requires Grunt `~0.4.5`
Expand All @@ -24,64 +24,115 @@ In your project's Gruntfile, add a section named `hackmyresume` to the data obje

```js
grunt.initConfig({

// Run HackMyResume!
hackmyresume: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
theme: 'compact'
},
},
main: {
src: 'path/to/resume.json',
dest: 'path/to/generated/resume.all'
}
}

});
```


### Options

#### options.separator
The full HackMyResume options model is supported. A few of the more commonly
used options are:

#### options.theme
Type: `String`
Default value: `', '`
Default value: `'modern'`

A string value that is used to do something with whatever.
A string describing the resume theme to use. Can be either:

#### options.punctuation
- The name of a predefined FRESH theme (`modern`, `compact`, `positive`,
`awesome`, or `basis`)
- The path to a locally-installed theme (for ex,
`node_modules/jsonresume-theme-classy`)

#### options.css
Type: `String`
Default value: `'embed'`

Whether CSS files should be linked (`link`) or embedded (`embed`) via `<link>`
or `<style>` tags, respectively.

#### options.pdf
Type: `String`
Default value: `'.'`
Default value: `'wkhtmltopdf'`

The name of the underlying PDF generation engine to use for the PDF version of
the resume (if any). Can be either `wkhtmltopdf` or `phantom`.

#### options.silent
Type: `Boolean`
Default value: `false`

A string value that is used to do something else with whatever else.
Disable HackMyResume output.

### Usage Examples

#### Default Options
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
In this example, the default options are used to generate a single resume to all
available formats using the default 'modern' theme:

```js
grunt.initConfig({
hackmyresume: {
options: {},
files: {
'dest/default_options': ['src/testing', 'src/123'],
},
options: { }, // No options? No problem.
main: {
files: {
// Will create dest/resume.html, dest/resume.pdf, dest/resume.md, etc.
'dest/resume.all': ['src/resume.json'],
}
}
},
});
```

#### Custom Options
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
In this example, custom options are used to change the resume theme and the
method of CSS embedding.

```js
grunt.initConfig({
hackmyresume: {
options: {
separator: ': ',
punctuation: ' !!!',
},
files: {
'dest/default_options': ['src/testing', 'src/123'],
theme: 'compact', // Set the 'compact' theme
css: 'link' // Use <link> for theme CSS files (HTML formats only)
},
main: {
files: {
'dest/resume.all': ['src/resume.json'],
}
}
},
});
```

You can also specify the source and destination files this way:

```js
grunt.initConfig({
hackmyresume: {
options: {
theme: 'compact',
css: 'link'
},
main: { // Using .src and .dest instead of files hash
src: 'src/resume.json',
dest: 'dest/resume.all'
}
}
});
```

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"grunt-contrib-jshint": "^0.9.2",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-nodeunit": "^0.3.3",
"hackmyresume": "~1.6.0",
"grunt": "~0.4.5"
},
"peerDependencies": {
Expand Down
136 changes: 99 additions & 37 deletions tasks/hackmyresume.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,111 @@
* grunt-hackmyresume
* https://github.com/hacksalot/grunt-hackmyresume
*
* Copyright (c) 2016 hacksalot
* Copyright (c) 2016 hacksalot <[email protected]> (github.com/hacksalot)
* Licensed under the MIT license.
*/



'use strict';



module.exports = function(grunt) {

// Please see the Grunt documentation for more information regarding task
// creation: http://gruntjs.com/creating-tasks

grunt.registerMultiTask('hackmyresume', 'Grunt plugin for HackMyResume.', function() {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
punctuation: '.',
separator: ', '
});

// Iterate over all specified file groups.
this.files.forEach(function(f) {
// Concat specified files.
var src = f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
// Read file source.
return grunt.file.read(filepath);
}).join(grunt.util.normalizelf(options.separator));

// Handle options.
src += options.punctuation;

// Write the destination file.
grunt.file.write(f.dest, src);

// Print a success message.
grunt.log.writeln('File "' + f.dest + '" created.');
});
});


// Require specific HMR modules
var HMR = require( 'hackmyresume' );
var HMROUT = require( 'hackmyresume/src/cli/out');
var HMRERR = require( 'hackmyresume/src/cli/error' );
var _out;

// Register the task
grunt.registerMultiTask(
'hackmyresume',
'Grunt plugin for HackMyResume.',
_task
);



/** The 'hackmyresume' Grunt task */
function _task() {

// Set up options and defaults
var options = this.options({
theme: 'modern',
css: 'embed'
});

// Now that we have options, set up output and error modules
_out = new HMROUT( options );
HMRERR.init( options.debug, options.assert, options.silent );

// Process incoming files. These are always in Grunt's array format.
this.files.forEach(function(f) {

// Exclude invalid files, per the Grunt sample
var src = f.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
});

// Run HackMyResume
_build( src, f.dest, options );

});
}



/** Generate resumes through the HackMyResume API. */
function _build( srcArray, destFile, options ) {

try {
grunt.log.writeln( 'Launching HackMyResume...' );

// Going through the low-level HMR interface. Set up a verb
var v = new HMR.verbs.build();

// Add error / output handlers so HMR colored output displays in Grunt.
v.on('hmr:error', function(ex) {
HMRERR.err.apply(HMRERR, arguments);
grunt.warn('An error occurred during HackMyResume resume generation.');
});
v.on('hmr:status', function() {
_out.do.apply(_out, arguments);
});
options.errHandler = v;

// Invoke the verb and kick off resume generation
v.invoke.call( v, srcArray, [destFile], options, function() { } );
if( v.errorCode ) {
grunt.warn('HackMyResume exited with error ' + v.errorCode + '.');
}

// TODO: Use grunt.file.write|read against the string version of the
// HackMyResume API.
}
catch( ex ) {

var msg = ex.toString();
if( ex.stack )
msg += ex.stack;
grunt.warn( msg );

return;
}

// Print a success message.
grunt.log.writeln('Resume(s) successfully generated to "' + destFile + '".');
}



};

0 comments on commit 33d8eb9

Please sign in to comment.