forked from el2iot2/grunt-hogan
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
262 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ logs | |
results | ||
|
||
node_modules | ||
npm-debug.log | ||
npm-debug.log | ||
.c9revisions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Elliott B. Edwards | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
grunt-hogan | ||
=========== | ||
# grunt-hogan | ||
|
||
a grunt.js plugin to compile/precompile hogan templates | ||
a grunt task to compile/precompile hogan templates | ||
|
||
## Getting Started | ||
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-hogan` | ||
|
||
Then add this line to your project's `grunt.js` gruntfile: | ||
|
||
```javascript | ||
grunt.loadNpmTasks('grunt-hogan'); | ||
``` | ||
|
||
[grunt]: http://gruntjs.com/ | ||
[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md | ||
|
||
## Documentation | ||
_(Coming soon)_ | ||
|
||
## 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][grunt]. | ||
|
||
## Release History | ||
_(Nothing yet)_ | ||
|
||
##Acknowledgements | ||
* a comment by "baz" [here](http://soenkerohde.com/2012/02/node-js-server-side-compile-hogan-js-templates/) pointed me in the right direction | ||
|
||
## License | ||
Copyright (c) 2012 Elliott B. Edwards | ||
Licensed under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('grunt').npmTasks('grunt-hogan').cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
test: { | ||
files: ['test/**/*.js'] | ||
}, | ||
lint: { | ||
files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js'] | ||
}, | ||
watch: { | ||
files: '<config:lint.files>', | ||
tasks: 'default' | ||
}, | ||
jshint: { | ||
options: { | ||
curly: true, | ||
eqeqeq: true, | ||
immed: true, | ||
latedef: true, | ||
newcap: true, | ||
noarg: true, | ||
sub: true, | ||
undef: true, | ||
boss: true, | ||
eqnull: true, | ||
node: true, | ||
es5: true | ||
}, | ||
globals: {} | ||
} | ||
}); | ||
|
||
// Load local tasks. | ||
grunt.loadTasks('tasks'); | ||
|
||
// Default task. | ||
grunt.registerTask('default', 'lint test'); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "grunt-hogan", | ||
"description": "a grunt task to compile/precompile hogan templates", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/automatonic/grunt-hogan", | ||
"author": { | ||
"name": "Elliott B. Edwards", | ||
"email": "elliott@automatonic.net", | ||
"url": "http://automatonic.net" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/automatonic/grunt-hogan.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/automatonic/grunt-hogan/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/automatonic/grunt-hogan/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"main": "grunt.js", | ||
"bin": "bin/grunt-hogan", | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.3.17" | ||
}, | ||
"keywords": [ | ||
"gruntplugin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* grunt-hogan | ||
* https://github.com/automatonic/grunt-hogan | ||
* | ||
* Copyright (c) 2012 Elliott B. Edwards | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
module.exports = function(grunt) { | ||
|
||
// ========================================================================== | ||
// TASKS | ||
// ========================================================================== | ||
|
||
grunt.registerMultiTask('hogan', 'Compile or render a hogan template.', function() { | ||
var hogan = require('hogan.js'), | ||
path = require('path'), | ||
target = this.target, | ||
data = this.data, | ||
render = this.data.render, | ||
compile = this.data.compile, | ||
result =""; | ||
|
||
if (render) { | ||
if (!render.output) { | ||
grunt.log.error("expected \"render.output\" directive"); | ||
return false; | ||
} | ||
grunt.file.write(render.output, | ||
hoganRender(render.template, render.context, render.options)); | ||
} | ||
else if (compile) { | ||
var templates = compile.templates || compile.template; | ||
if (!templates) { | ||
grunt.log.error("expected either \"compile.template\" or \"compile.templates\" directive."); | ||
return false; | ||
} | ||
if (!compile.output) { | ||
grunt.log.error("expected \"compile.output\" directive"); | ||
return false; | ||
} | ||
|
||
grunt.file.write(compile.output, | ||
hoganCompile(templates, compile.options)); | ||
return true; | ||
} | ||
else { | ||
grunt.log.error("expected either \"compile\" or \"render\" directive."); | ||
return false; | ||
} | ||
|
||
function hoganCompile(templatePatterns, options) { | ||
options = options || {}; | ||
options.binder = options.binder || require("hogan-binder-vanilla.js"); | ||
options.nameFunc = options.nameFunc || function(fileName) { | ||
path.basename(fileName, path.extname(fileName)); | ||
}; | ||
var templateFilePaths = grunt.file.expand(templatePatterns); | ||
var templates = []; | ||
|
||
templateFilePaths.forEach(function(templateFilePath) { | ||
try { | ||
template.push({ | ||
name: name, | ||
template: hogan.compile( | ||
grunt.file.read(templateFilePath).toString(), | ||
{asString:true})}); | ||
} | ||
catch (var error) { | ||
grunt.log.error(error); | ||
grunt.log.error("Error compiling template " + name + " in " + templateFilePath); | ||
throw error; | ||
} | ||
}); | ||
var context = { //build a context for the binder template to work against | ||
config: function() { //lambda that retrieves config parameters | ||
return function(text) { | ||
return grunt.config(text); | ||
}}, | ||
templates: templates} | ||
|
||
return options.binder.render(context); | ||
} | ||
|
||
function hoganRender(template, context, options) { | ||
if (!template.render) { | ||
template = hoganCompile(template, options); | ||
} | ||
return template.render(context); | ||
} | ||
|
||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var grunt = require('grunt'); | ||
|
||
/* | ||
======== A Handy Little Nodeunit Reference ======== | ||
https://github.com/caolan/nodeunit | ||
Test methods: | ||
test.expect(numAssertions) | ||
test.done() | ||
Test assertions: | ||
test.ok(value, [message]) | ||
test.equal(actual, expected, [message]) | ||
test.notEqual(actual, expected, [message]) | ||
test.deepEqual(actual, expected, [message]) | ||
test.notDeepEqual(actual, expected, [message]) | ||
test.strictEqual(actual, expected, [message]) | ||
test.notStrictEqual(actual, expected, [message]) | ||
test.throws(block, [error], [message]) | ||
test.doesNotThrow(block, [error], [message]) | ||
test.ifError(value) | ||
*/ | ||
|
||
exports['hogan'] = { | ||
setUp: function(done) { | ||
// setup here | ||
done(); | ||
}, | ||
'helper': function(test) { | ||
test.expect(1); | ||
// tests here | ||
test.equal(grunt.helper('hogan'), 'hogan!!!', 'should return the correct value.'); | ||
test.done(); | ||
} | ||
}; |