Skip to content
Browse files

intial commit

  • Loading branch information...
0 parents commit 2199785206eb735ca3a72b941a434f295e30acb6 @patrickkettner committed Oct 10, 2012
Showing with 194 additions and 0 deletions.
  1. +1 −0 .npmignore
  2. +22 −0 LICENSE-MIT
  3. +38 −0 README.md
  4. +2 −0 bin/grunt-compile-handlebars
  5. +40 −0 grunt.js
  6. +38 −0 package.json
  7. +53 −0 tasks/compile-handlebars.js
1 .npmignore
@@ -0,0 +1 @@
+/node_modules/
22 LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Patrick Kettner
+
+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.
38 README.md
@@ -0,0 +1,38 @@
+# grunt-compile-handlebars
+
+Compiles handlebar templates, outputs static HTML
+
+## Getting Started
+Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-compile-handlebars`
+
+Then add this line to your project's `grunt.js` gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-compile-handlebars');
+```
+
+[grunt]: https://github.com/gruntjs/grunt
+[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md
+
+## Documentation
+### Who
+patrick kettner - a web developer who consistently worked with large static data sets.
+
+### What
+grunt-compile-handlebars takes in a handlebars tempalte (and optionally static pre and post html), runs a dataset over it, and outputs static html.
+
+### Where
+inside of a grunt task. I assume you know what gruntjs is, but if not - gruntjs.com
+
+### When
+this questions doesn't even make sense
+
+## Why
+I had to work with several hundred repeated data structures that never changed. Keeping them all in html was silly, but pushing out a template engine for the end user to compile the same information multiple times was even sillier. This allows you to have your templated cake and eat it too.
+
+## Release History
+0.0.1 - Dudley
+
+## License
+Copyright (c) 2012 Patrick Kettner
+Licensed under the MIT license.
2 bin/grunt-compile-handlebars
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('grunt').npmTasks('grunt-compile-handlebars').cli();
40 grunt.js
@@ -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');
+
+};
38 package.json
@@ -0,0 +1,38 @@
+{
+ "name": "grunt-compile-handlebars",
+ "description": "Compile handlebar templates, outputting static HTML",
+ "version": "0.1.0",
+ "homepage": "https://github.com/patrickkettner/grunt-compile-handlebars",
+ "author": {
+ "name": "Patrick Kettner",
+ "email": "patrick@patrickkettner.com",
+ "url": "https://github.com/patrickkettner"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/patrickkettner/grunt-compile-handlebars.git"
+ },
+ "bugs": {
+ "url": "https://github.com/patrickkettner/grunt-compile-handlebars/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/patrickkettner/grunt-compile-handlebars/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "grunt.js",
+ "bin": "bin/grunt-compile-handlebars",
+ "engines": {
+ "node": "*"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.15"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
+}
53 tasks/compile-handlebars.js
@@ -0,0 +1,53 @@
+/*
+* grunt-compile-handlebars
+* https://github.com/patrickkettner/grunt-compile-handlebars
+*
+* Copyright (c) 2012 Patrick Kettner
+* Licensed under the MIT license.
+*/
+
+module.exports = function(grunt) {
+
+ // Please see the grunt documentation for more information regarding task and
+ // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
+
+ // ==========================================================================
+ // TASKS
+ // ==========================================================================
+
+ grunt.registerMultiTask('compile-handlebars', 'Compile Handlebars templates ', function() {
+ grunt.log.write(grunt.helper('compile-handlebars'));
+
+ compiledHTML = grunt.helper('compile-handlebars', this.data);
+ grunt.file.write(this.data.output, compiledHTML)
+
+ });
+
+ // ==========================================================================
+ // HELPERS
+ // ==========================================================================
+
+ grunt.registerHelper('compile-handlebars', function(data) {
+ if (data) {
+ var handlebars = require('handlebars');
+ var template = grunt.file.read(data.template);
+ var templateData = eval(grunt.file.read(data.templateData));
+ var compiledTemplate = handlebars.compile(template);
+ var html = '';
+
+ if (data.preHTML) {
+ html += grunt.file.read(data.preHTML)
+ }
+
+ html += compiledTemplate(templateData);
+
+ if (data.postHTML) {
+ html += grunt.file.read(data.postHTML)
+ }
+
+ return html
+
+ };
+ });
+
+};

0 comments on commit 2199785

Please sign in to comment.
Something went wrong with that request. Please try again.