Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rough in 0.4

  • Loading branch information...
commit edf3dc325bebe9906c4faf07c39c881736c3c493 1 parent 8a5e74e
@tkellen tkellen authored
View
14 .jshintrc
@@ -0,0 +1,14 @@
+{
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "sub": true,
+ "undef": true,
+ "boss": true,
+ "eqnull": true,
+ "node": true,
+ "es5": true
+}
View
73 CONTRIBUTING.md
@@ -0,0 +1,73 @@
+[Grunt homepage](http://gruntjs.com/) | [Documentation table of contents](https://github.com/gruntjs/grunt/blob/devel/docs/toc.md)
+
+# Contributing to grunt
+
+There are a number of grunt projects.
+
+* [grunt](https://github.com/gruntjs/grunt) - the main grunt project
+* [gruntjs.com](https://github.com/gruntjs/gruntjs.com) - the gruntjs.com website
+* [grunt-contrib collection](https://github.com/gruntjs/grunt-contrib) - a collection of all grunt "contrib" plugins
+
+In addition, each individual grunt-contrib plugin is a separate repository listed on the [gruntjs org homepage](https://github.com/gruntjs).
+
+## Filing issues
+If something isn't working like you think it should, please read the documentation first. If you'd like to chat with someone, [pop into IRC](#discussing-grunt) and ask your question there.
+
+The best way to ensure an issue gets addressed is to file it in the appropriate issues tracker.
+
+**If there's an issue with a specific grunt-contrib plugin:**
+Please file an issue on that plugin's issues tracker.
+
+**If you'd like to contribute a new plugin:**
+Please file an issue on the [grunt-contrib collection issues tracker](https://github.com/gruntjs/grunt-contrib/issues). We don't accept all plugins, but we'll certainly consider yours.
+
+**If there's an issue with the [website](http://gruntjs.com/):**
+Please file an issue on the [gruntjs.com website issues tracker](https://github.com/gruntjs/gruntjs.com/issues).
+
+**If there's an issue that isn't specific to any of the above:**
+Please file an issue on the [grunt issues tracker](https://github.com/gruntjs/grunt/issues).
+
+### Simplify the issue
+Try to [reduce your code](http://www.webkit.org/quality/reduction.html) to the bare minimum required to reproduce the issue. This makes it much easier (and much faster) to isolate and fix the issue.
+
+### Explain the issue
+If we can't reproduce the issue, we can't fix it. Please list the exact steps required to reproduce the issue. Include versions of your OS, Node.js, grunt, etc. Include relevant logs or sample code.
+
+## Discussing grunt
+Join the [freenode](http://freenode.net/) IRC #grunt channel. We've got a bot and everything.
+
+_No private messages, please._
+
+## Modifying grunt
+First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
+
+1. Fork and clone the repo.
+1. Check out the correct branch. Currently, grunt development happens in the `devel` branch.
+1. Run `npm install` to install all grunt dependencies.
+1. Run `npm link` to put the dev version of grunt in the system path (this is only needed for developing grunt, not for plugins or the website).
+1. Run `grunt` to grunt grunt.
+
+Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing breaks.
+
+### Submitting pull requests
+
+1. Create a new branch, please don't work in your `master` or `devel` branch directly.
+1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
+1. Fix stuff.
+1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
+1. Update the documentation to reflect any changes.
+1. Push to your fork and submit a pull request.
+
+### Syntax
+
+* Two space indents. Don't use tabs anywhere. Use `\t` if you need a tab character in a string.
+* No trailing whitespace, except in markdown files where a linebreak must be forced.
+* Don't go overboard with the whitespace.
+* No more than [one assignment](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) per `var` statement.
+* Delimit strings with single-quotes `'`, not double-quotes `"`.
+* Prefer `if` and `else` to ["clever"](http://programmers.stackexchange.com/a/25281) uses of `? :` conditional or `||`, `&&` logical operators.
+* Comments are great. Just put them _before_ the line of code, _not_ at the _end_ of the line.
+* **When in doubt, follow the conventions you see used in the source already.**
+
+### Reverting back to the "official" grunt
+If you've used `npm link` to put a dev version of grunt in the system path and, for some reason, need to revert back to the current official grunt release, just reinstall grunt globally with `npm install -g grunt`
View
42 grunt.js → Gruntfile.js
@@ -6,35 +6,26 @@
* Licensed under the MIT license.
*/
+'use strict';
+
module.exports = function(grunt) {
- 'use strict';
// Project configuration.
grunt.initConfig({
- lint: {
- all: ['grunt.js', 'tasks/*.js', '<config:nodeunit.tasks>']
- },
-
jshint: {
+ all: [
+ 'Gruntfile.js',
+ 'tasks/*.js',
+ '<%= nodeunit.tests %>'
+ ],
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
+ jshintrc: '.jshintrc'
}
},
// Before generating any new files, remove any previously-created files.
clean: {
- test: ['tmp']
+ tests: ['tmp']
},
// Configuration to be run (and then tested).
@@ -81,21 +72,24 @@ module.exports = function(grunt) {
// Unit tests.
nodeunit: {
- tasks: ['test/*_test.js']
+ tests: ['test/*_test.js']
}
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
- // The clean plugin helps in testing.
+ // These plugins provide necessary tasks.
+ grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+ grunt.loadNpmTasks('grunt-contrib-internal');
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
- grunt.renameTask('test', 'nodeunit');
- grunt.registerTask('test', 'clean handlebars nodeunit');
+ grunt.registerTask('test', ['clean', 'handlebars', 'nodeunit']);
// By default, lint and run all tests.
- grunt.registerTask('default', 'lint test');
-};
+ grunt.registerTask('default', ['jshint', 'test', 'build-contrib']);
+
+};
View
252 README.md
@@ -1,105 +1,147 @@
-# grunt-contrib-handlebars [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-handlebars.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-handlebars)
-
-> Precompile Handlebars templates to JST file.
-
-## Getting Started
-Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-handlebars`
-
-Then add this line to your project's `grunt.js` gruntfile:
-
-```javascript
-grunt.loadNpmTasks('grunt-contrib-handlebars');
-```
-
-[grunt]: https://github.com/gruntjs/grunt
-[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md
-
-### Overview
-
-Inside your `grunt.js` file, add a section named `handlebars`. This section specifies the files to compile and the options used with [handlebars](http://handlebarsjs.com/).
-
-##### files ```object```
-
-This defines what files this task will process and should contain key:value pairs.
-
-The key (destination) should be an unique filepath (supports [grunt.template](https://github.com/gruntjs/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch)).
-
-Note: Values are precompiled to the namespaced JST array in the order passed.
-
-##### options ```object```
-
-This controls how this task operates and should contain key:value pairs, see options below.
-
-#### Options
-
-##### namespace ```string```
-
-The namespace in which the precompiled templates will be assigned (default is JST). *Use dot notation (e.g. App.Templates) for nested namespaces.*
-
-Example:
-``` javascript
-options: {
- namespace: 'MyApp.Templates'
-}
-```
-
-##### wrapped ```boolean```
-
-Determine if preprocessed template functions will be wrapped in Handlebars.template function (default is false).
-
-##### processName ```function```
-
-This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.
-
-``` javascript
-options: {
- processName: function(filename) {
- return filename.toUpperCase();
- }
-}
-```
-
-##### processPartialName ```function```
-
-This option accepts a function which takes one argument (the partial filepath) and returns a string which will be used as the key for the precompiled partial object when it is registered in Handlebars.partials. The example below stores all partials using only the actual filename instead of the full path.
-
-``` javascript
-options: {
- processPartialName: function(filePath) { // input: templates/_header.hbs
- var pieces = filePath.split("/");
- return pieces[pieces.length - 1]; // output: _header.hbs
- }
-}
-````
-
-Note: If processPartialName is not provided as an option the default assumes that partials will be stored by stripping trailing underscore characters and filename extensions. For example, the path *templates/_header.hbs* will become *header* and can be referenced in other templates as *{{> header}}*.
-
-##### partialRegex ```regex```
-
-This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files. (The default is _).
-
-``` javascript
-options: {
- partialRegex: /^par_/ // assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
-}
-```
-
-#### Config Example
-
-``` javascript
-handlebars: {
- compile: {
- options: {
- namespace: "JST"
- },
- files: {
- "path/to/result.js": "path/to/source.hbs",
- "path/to/another.js": ["path/to/sources/*.hbs", "path/to/more/*.hbs"]
- }
- }
-}
-```
-
---
-
-*Task submitted by [Tim Branyen](http://github.com/tbranyen).*
+# grunt-contrib-handlebars [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-handlebars.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-handlebars)
+
+> Precompile Handlebars templates to JST file.
+
+_Note that this plugin has not yet been released, and only works with the latest bleeding-edge, in-development version of grunt. See the [When will I be able to use in-development feature 'X'?](https://github.com/gruntjs/grunt/blob/devel/docs/faq.md#when-will-i-be-able-to-use-in-development-feature-x) FAQ entry for more information._
+
+## Getting Started
+_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
+
+From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
+
+```bash
+npm install grunt-contrib-handlebars --save-dev
+```
+
+Once that's done, add this line to your project's Gruntfile:
+
+```js
+grunt.loadNpmTasks('grunt-contrib-handlebars');
+```
+
+If the plugin has been installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a `devDependency`, which ensures that it will be installed whenever the `npm install` command is run.
+
+[grunt]: http://gruntjs.com/
+[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
+[package.json]: https://npmjs.org/doc/json.html
+
+
+## The handlebars task
+
+### Overview
+
+In your project's Gruntfile, add a section named `handlebars` to the data object passed into `grunt.initConfig()`.
+
+```js
+grunt.initConfig({
+ handlebars: {
+ options: {
+ // Task-specific options go here.
+ },
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
+```
+### Options
+
+## files
+Type: `Object`
+
+This defines what files this task will process and should contain key:value pairs.
+
+The key (destination) should be an unique filepath (supports [grunt.template](https://github.com/gruntjs/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch)).
+
+Note: Values are precompiled to the namespaced JST array in the order passed.
+
+## namespace
+Type: `string`
+Default: 'jst'
+
+The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces.*
+
+Example:
+```js
+options: {
+ namespace: 'MyApp.Templates'
+}
+```
+
+## wrapped
+Type: `Boolean`
+Default: false
+
+Determine if preprocessed template functions will be wrapped in Handlebars.template function.
+
+## processName
+Type: `function`
+
+This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.
+
+```js
+options: {
+ processName: function(filename) {
+ return filename.toUpperCase();
+ }
+}
+```
+
+## processPartialName
+Type: ```function```
+
+This option accepts a function which takes one argument (the partial filepath) and returns a string which will be used as the key for the precompiled partial object when it is registered in Handlebars.partials. The example below stores all partials using only the actual filename instead of the full path.
+
+```js
+options: {
+ processPartialName: function(filePath) { // input: templates/_header.hbs
+ var pieces = filePath.split("/");
+ return pieces[pieces.length - 1]; // output: _header.hbs
+ }
+}
+````
+
+Note: If processPartialName is not provided as an option the default assumes that partials will be stored by stripping trailing underscore characters and filename extensions. For example, the path *templates/_header.hbs* will become *header* and can be referenced in other templates as *{{> header}}*.
+
+## partialRegex
+Type: `Regexp`
+Default: /^_/
+
+This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files.
+
+``` javascript
+// assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
+options: {
+ partialRegex: /^par_/
+}
+```
+
+### Examples
+
+```js
+handlebars: {
+ compile: {
+ options: {
+ namespace: "JST"
+ },
+ files: {
+ "path/to/result.js": "path/to/source.hbs",
+ "path/to/another.js": ["path/to/sources/*.hbs", "path/to/more/*.hbs"]
+ }
+ }
+}
+```
+
+## Release History
+
+ * 2012-10-11 - v0.3.2 - Rename grunt-contrib-lib dep to grunt-lib-contrib.
+ * 2012-10-02 - v0.3.1 - Bugfix default processPartialName.
+ * 2012-09-22 - v0.3.0 - Options no longer accepted from global config key.
+ * 2012-09-15 - v0.2.3 - Support for nested namespaces.
+ * 2012-09-11 - v0.2.2 - Escape single quotes in filenames.
+ * 2012-09-09 - v0.2.0 - Refactored from grunt-contrib into individual repo.
+
+--
+Task submitted by <a href="http://tbranyen.com">Tim Branyen</a>.
+
+*Generated on Thu Oct 18 2012 22:28:59.*
View
2  docs/examples.md → docs/handlebars-examples.md
@@ -1,3 +1,5 @@
+# Examples
+
```js
handlebars: {
compile: {
View
38 docs/options.md → docs/handlebars-options.md
@@ -1,4 +1,7 @@
-##### files ```object```
+# Options
+
+## files
+Type: `Object`
This defines what files this task will process and should contain key:value pairs.
@@ -6,15 +9,11 @@ The key (destination) should be an unique filepath (supports [grunt.template](ht
Note: Values are precompiled to the namespaced JST array in the order passed.
-##### options ```object```
-
-This controls how this task operates and should contain key:value pairs, see options below.
-
-#### Options
-
-##### namespace ```string```
+## namespace
+Type: `string`
+Default: 'jst'
-The namespace in which the precompiled templates will be assigned (default is JST). *Use dot notation (e.g. App.Templates) for nested namespaces.*
+The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces.*
Example:
```js
@@ -23,11 +22,14 @@ options: {
}
```
-##### wrapped ```boolean```
+## wrapped
+Type: `Boolean`
+Default: false
-Determine if preprocessed template functions will be wrapped in Handlebars.template function (default is false).
+Determine if preprocessed template functions will be wrapped in Handlebars.template function.
-##### processName ```function```
+## processName
+Type: `function`
This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.
@@ -39,7 +41,8 @@ options: {
}
```
-##### processPartialName ```function```
+## processPartialName
+Type: ```function```
This option accepts a function which takes one argument (the partial filepath) and returns a string which will be used as the key for the precompiled partial object when it is registered in Handlebars.partials. The example below stores all partials using only the actual filename instead of the full path.
@@ -54,12 +57,15 @@ options: {
Note: If processPartialName is not provided as an option the default assumes that partials will be stored by stripping trailing underscore characters and filename extensions. For example, the path *templates/_header.hbs* will become *header* and can be referenced in other templates as *{{> header}}*.
-##### partialRegex ```regex```
+## partialRegex
+Type: `Regexp`
+Default: /^_/
-This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files. (The default is _).
+This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files.
``` javascript
+// assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
options: {
- partialRegex: /^par_/ // assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
+ partialRegex: /^par_/
}
```
View
16 docs/handlebars-overview.md
@@ -0,0 +1,16 @@
+# Overview
+
+In your project's Gruntfile, add a section named `handlebars` to the data object passed into `grunt.initConfig()`.
+
+```js
+grunt.initConfig({
+ handlebars: {
+ options: {
+ // Task-specific options go here.
+ },
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
+```
View
7 package.json
@@ -32,8 +32,11 @@
"grunt-lib-contrib": "~0.3.0"
},
"devDependencies": {
- "grunt": "~0.3.15",
- "grunt-contrib-clean": "~0.3.0"
+ "grunt-contrib-jshint": "0.1.0",
+ "grunt-contrib-nodeunit": "0.1.0",
+ "grunt-contrib-clean": "0.4.0a",
+ "grunt-contrib-internal": "*",
+ "grunt": "devel"
},
"keywords": [
"gruntplugin"
View
13 tasks/handlebars.js
@@ -5,11 +5,10 @@
* Copyright (c) 2012 Tim Branyen, contributors
* Licensed under the MIT license.
*/
-module.exports = function(grunt) {
- 'use strict';
- // TODO: ditch this when grunt v0.4 is released
- grunt.util = grunt.util || grunt.utils;
+'use strict';
+
+module.exports = function(grunt) {
var _ = grunt.util._;
var helpers = require('grunt-lib-contrib').init(grunt);
@@ -26,14 +25,10 @@ module.exports = function(grunt) {
grunt.registerMultiTask('handlebars', 'Compile handlebars templates and partials.', function() {
- var helpers = require('grunt-lib-contrib').init(grunt);
- var options = helpers.options(this, {namespace: 'JST'});
+ var options = this.options({namespace: 'JST'});
grunt.verbose.writeflags(options, 'Options');
- // TODO: ditch this when grunt v0.4 is released
- this.files = this.files || helpers.normalizeMultiTaskFiles(this.data, this.target);
-
var compiled, srcFiles, src, filename;
var partials = [];
var templates = [];
Please sign in to comment.
Something went wrong with that request. Please try again.