Skip to content

Commit

Permalink
Name and documentation udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Weiss committed Dec 25, 2012
1 parent 262dc53 commit a445f9a
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ tmp
.metdata*
*.tgz
.project
.git*
.gitignore
.gitattributes
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Tim Branyen, contributors
Copyright (c) 2012 Terry Weiss, grunt-contrib authors. All rights reserved.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
91 changes: 55 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This is an awful lot like the existing [grunt-contrib-jst](https://github.com/gruntjs/grunt-contrib-jst) grunt task. But it has a few
differences. One is that it supports <code>underscore</code>, <code>lodash</code> and <code>ejs</code> template providers. The real
key feature is that it allows you to compile these templates into a module that exposes each compiled template from an <code>exports</code> property.
What this means is that if you provide the following configuration:
key feature is that it allows you to compile these templates into a module that exposes each compiled template from an <code>exports</code>
property. What this means is that if you provide the following configuration:

compile_module: {
files: {
Expand All @@ -20,9 +20,9 @@ You would end up with an entry in <code>module_jst.js</code> that looks like:

exports["tmp/module_jst.js"] = function(obj){...

I know. You're wondering why do such a thing? Doesn't the <code>contrib-jst</code> offer an AMD wrapper? Yes, it does, but that doesn't help if you want
to get at the template from the server. As well, if you use [browserify](https://github.com/substack/node-browserify), this will play much better with
the compiled browserified (is that word?) output.
I know. You're wondering why do such a thing? Doesn't <code>contrib-jst</code> offer an AMD wrapper? Yes, it does, but it is a very noisy way
to get at it on the server. As well, if you use [browserify](https://github.com/substack/node-browserify), this will play much better with
the compiled browserified (is that a word?) output.

So there you have it. Browserify and server happiness for underscore/lodash and EJS templates. And backward compatibility with <code>contrib-jst</code>.

Expand All @@ -34,19 +34,34 @@ now uses [node-beautify](https://github.com/fshost/node-beautify).
If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:

```shell
npm install grunt-template-module --save-dev
npm install grunt-template-module
```

[grunt]: http://gruntjs.com/
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md


## template-module task
_Run this task with the `grunt template-module` command._
Run this task with `grunt template-module` at the command line.

_This task is a [multi task][] so any targets, files and options should be specified according to the [multi task][] documentation._
[multi task]: https://github.com/gruntjs/grunt/wiki/Configuring-tasks

### Usage

```js
template-module: {
compile: {
options: {
module: true.
provider: 'lodash'
},
files: {
"path/to/compiled/templates.js": ["path/to/source/**/*.html"]
}
}
}
```

### Options

Expand All @@ -62,6 +77,38 @@ Default: underscore

The name of the template engine to use. Allowable values are <code>*underscore*</code> <code>*lodash*</code> and <code>*ejs*</code>



#### prettify
Type: ```boolean```
Default: false

When doing a quick once-over of your compiled template file, it's nice to see
an easy-to-read format. This will accomplish
that.

```javascript
options: {
prettify: true
}
```

#### prettifyOptions
Type: ```object```

When you set prettify to `true`, you can pass options to the [beautify module](https://github.com/fshost/node-beautify) in this object.

```javascript
options: {
prettify: true,
prettifyOptions:{
indentSize: 4,
indentChar: '\t',
maxPreserveNewlines: 1
}
}
```

#### namespace
Type: `String`
Default: 'JST'
Expand Down Expand Up @@ -103,20 +150,6 @@ template-module: {
}
```

#### prettify
Type: ```boolean```
Default: false

When doing a quick once-over of your compiled template file, it's nice to see
an easy-to-read format. This will accomplish
that.

```javascript
options: {
prettify: true
}
```

#### amdWrapper
Type: ```boolean```
Default: false
Expand All @@ -140,23 +173,9 @@ options: {

* This is not used when module is set to true.*

### Usage Examples

```js
template-module: {
compile: {
options: {
templateSettings: {
interpolate : /\{\{(.+?)\}\}/g
}
},
files: {
"path/to/compiled/templates.js": ["path/to/source/**/*.html"]
}
}
}
```


## Release History
* 2012-12-24 v0.1.0 Initial release
* 2012-12-25 v0.1.0 Fixed documentation and clarified names
12 changes: 7 additions & 5 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function (grunt) {

//
// Configuration to be run (and then tested).
"jst-module": {
"template-module": {
compile: {
files: {
"tmp/jst.js": ["test/fixtures/template.html"]
Expand Down Expand Up @@ -126,7 +126,7 @@ module.exports = function (grunt) {
//
// Unit tests.
nodeunit: {
tests: ['test/jst_test.js']
tests: ['test/template-test.js']
}
});

Expand All @@ -138,9 +138,11 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-beautify');


grunt.registerTask('test', ['jst-module', 'nodeunit']);
grunt.registerTask('test', ['template-module', 'nodeunit']);
grunt.registerTask("publish", ["lint", "beautify", "test"]);

// By default, lint and run all tests.
grunt.registerTask('default', ['lint']);
grunt.registerTask('default', ['test']);

};

};
91 changes: 44 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
{
"name" : "grunt-template-module",
"description" : "Precompile Underscore templates to file with option to expose templates from a module.",
"version" : "0.1.0",
"homepage" : "https://github.com/terryweiss/grunt-template-module",
"contributors" : [
{
"name" : "Grunt Team",
"url" : "http://gruntjs.com/"
},
{
"name" : "Terry Weiss",
"url" : "http://terryweiss.net"
}
],
"repository" : {
"type" : "git",
"url" : "git://github.com/terryweiss/grunt-template-module.git"
},
"bugs" : {
"url" : "https://github.com/terryweiss/grunt-template-module/issues"
},
"licenses" : [
{
"type" : "MIT",
"url" : "https://github.com/terryweiss/grunt-template-module/blob/master/LICENSE-MIT"
}
],
"main" : "grunt.js",
"engines" : {
"node" : ">= 0.8.0"
},
"scripts" : {
"test" : "grunt test"
},
"dependencies" : {
"lodash" : "~1.0.0",
"grunt-lib-contrib" : "~0.3.0",
"underscore" : "~1.4.0",
"ejs" : "~0.8.3",
"grunt-beautify" : "~0.1.1"
},
"devDependencies" : {
"grunt" : "~0.3.0",
"grunt-contrib-nodeunit" : "~0.1.0"
"name": "grunt-template-module",
"description": "Precompile templates to a file with option to expose templates as a node/commonjs module.",
"version": "0.1.0",
"homepage": "https://github.com/terryweiss/grunt-template-module",
"contributors": [

},
"keywords" : ["gruntplugin", "jst", "ejs", "lodash", "underscore", "templates"]
}
{
"name": "Terry Weiss",
"url": "http://terryweiss.net"
},
{
"name": "Grunt Team",
"url": "http://gruntjs.com/"
}],
"repository": {
"type": "git",
"url": "git://github.com/terryweiss/grunt-template-module.git"
},
"bugs": {
"url": "https://github.com/terryweiss/grunt-template-module/issues"
},
"licenses": [{
"type": "MIT",
"url": "https://github.com/terryweiss/grunt-template-module/blob/master/LICENSE-MIT"
}],
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"lodash": "~1.0.0",
"grunt-lib-contrib": ">=0.3.0",
"underscore": "~1.4.0",
"ejs": "~0.8.3",
"grunt-beautify": "~0.1.1"
},
"devDependencies": {
"grunt": ">=0.3.0",
"grunt-contrib-nodeunit": "~0.1.0"

},
"keywords": ["gruntplugin", "jst", "ejs", "lodash", "underscore", "templates"]
}
21 changes: 14 additions & 7 deletions tasks/jst-module.js → tasks/template-module.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* @fileOverview This is a grunt task to precompile JST files with the option to
* expose the result into module.exports rather than a namespace.
Expand All @@ -12,12 +13,17 @@
* @module tasks\grunt-jst-module
* @see http://gruntjs.com/
* @see https://github.com/gruntjs/grunt-contrib-jst
* @copyright Copyright (c) 2012 Tim Branyen, contributors, Terry Weiss
* @copyright Copyright &copy; 2012 Terry Weiss, Tim Branyen, grunt-contrib contributers. All rights reserved.
* @license MIT.
*/

'use strict';

/**
* Figures out what the full namespace declaration looks like when rendered.
*
* @param {string} ns The namespace specification
* @return {Object} And object with two components: <code>namespace</code> - the namespace specification and
* <code>declaration</code>: the component declarations to make sure the namespace is valid at runtime.
*/
var getNamespaceDeclaration = function (ns) {
var output = [];
var curPath = 'this';
Expand All @@ -36,7 +42,10 @@ var getNamespaceDeclaration = function (ns) {
declaration: output.join('\n')
};
};

/**
* The task itself
* @param {Grunt} grunt The grunt object
*/
module.exports = function (grunt) {

// filename conversion for templates
Expand Down Expand Up @@ -68,8 +77,6 @@ module.exports = function (grunt) {
var options = sys.extend({}, defaultOptions, this.data.options);
var templateProvider = require(options.provider);

var helpers = require('grunt-lib-contrib').init(grunt);

grunt.verbose.writeflags(options, 'Options');

var nsInfo;
Expand Down Expand Up @@ -136,4 +143,4 @@ module.exports = function (grunt) {


});
};
};
49 changes: 0 additions & 49 deletions test/jst_test.js

This file was deleted.

Loading

0 comments on commit a445f9a

Please sign in to comment.