Skip to content

Commit

Permalink
Merge branch 'master' into locals
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	tasks/jade.js
  • Loading branch information
surjikal committed Nov 26, 2012
2 parents 797753f + a9cd458 commit 2dcab51
Show file tree
Hide file tree
Showing 30 changed files with 929 additions and 6 deletions.
19 changes: 18 additions & 1 deletion README.md
Expand Up @@ -115,6 +115,7 @@ jade: {
```

For locals, add:

```javascript
jade: {
locals: {
Expand All @@ -129,7 +130,22 @@ jade: {
}
```

For custom extension, add:

```javascript
jade: {
custom_extension: {
src: ['path/to/src/*.jade'],
dest: 'dest/path/',
options: {
extension: '.xml',
}
}
}
```

Or alternatively, use a function:

```javascript
jade: {
locals: {
Expand All @@ -154,7 +170,8 @@ options: {
client: true,
runtime: true,
compileDebug: false,
locals: {}
locals: {},
extension: null
}

wrapper: {
Expand Down
9 changes: 9 additions & 0 deletions example/grunt.js
@@ -1,4 +1,5 @@
module.exports = function(grunt) {
'use strict';

// Project configuration.
grunt.initConfig({
Expand Down Expand Up @@ -65,6 +66,14 @@ module.exports = function(grunt) {
node: true,
dependencies: 'runtime'
}
},
custom_extension: {
src: ['templates/src/*.jade'],
dest: 'templates/custom_extension/',
options: {
client: false,
extension: '.xml'
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions example/templates/custom_extension/_layout.xml
@@ -0,0 +1 @@
<!DOCTYPE html><html lang="en"><head></head><body><div id="container"></div></body></html>
1 change: 1 addition & 0 deletions example/templates/custom_extension/include.xml
@@ -0,0 +1 @@
<h1>test</h1><h2>include</h2>
1 change: 1 addition & 0 deletions example/templates/custom_extension/test-3.xml
@@ -0,0 +1 @@
<h1>test</h1>
1 change: 1 addition & 0 deletions example/templates/custom_extension/test-extends.xml
@@ -0,0 +1 @@
<!DOCTYPE html><html lang="en"><head></head><body><div id="container"></div><p>Hi</p></body></html>
1 change: 1 addition & 0 deletions example/templates/custom_extension/test.xml
@@ -0,0 +1 @@
<h1>test</h1>
1 change: 1 addition & 0 deletions example/templates/custom_extension/test2.xml
@@ -0,0 +1 @@
<h1>test</h1>
1 change: 1 addition & 0 deletions example/templates/custom_extension/test_4.xml
@@ -0,0 +1 @@
<h1>test</h1>
45 changes: 45 additions & 0 deletions grunt.js
@@ -1,4 +1,5 @@
module.exports = function(grunt) {
'use strict';

// Project configuration.
grunt.initConfig({
Expand All @@ -10,6 +11,50 @@ module.exports = function(grunt) {
node: true,
dependencies: 'runtime'
}
},
amd: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-amd/',
wrapper: {
amd: true,
dependencies: 'runtime'
}
},
debug: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-debug/',
options: {
compileDebug: true
}
},
html: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-html/',
options: {
client: false
}
},
no_wrap: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-no_wrap/',
wrapper: {
wrap: false
}
},
no_runtime: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-no_runtime/',
options: {
runtime: false
}
},
custom_extension: {
src: ['test/fixtures/**/*.jade'],
dest: 'tmp/jade-custom_extension/',
options: {
client: false,
extension: '.xml'
}
}
},
clean: ['tmp/'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-jade",
"description": "Compile jade templates with grunt.",
"version": "0.3.7",
"version": "0.3.8",
"homepage": "https://github.com/phated/grunt-jade",
"author": {
"name": "Blaine Bublitz",
Expand Down
6 changes: 5 additions & 1 deletion tasks/jade.js
Expand Up @@ -7,6 +7,7 @@
*/

module.exports = function(grunt) {
'use strict';

var jade = require('jade')
, path = require('path')
Expand All @@ -23,6 +24,7 @@ module.exports = function(grunt) {
runtime: true,
compileDebug: false,
locals: {},
extension: null
}, this.data.options);

var wrapper = grunt.utils._.extend({
Expand All @@ -38,12 +40,14 @@ module.exports = function(grunt) {
// Make the dest dir if it doesn't exist
grunt.file.mkdir(dest);

var outputExtension = (options.extension !== null)? options.extension
: (options.client? '.js' : '.html');

// Loop through all files and write them to files
files.forEach(function(filepath) {
var fileExtname = path.extname(filepath)
, src = grunt.file.read(filepath)
, outputFilename = path.basename(filepath, fileExtname)
, outputExtension = options.client ? '.js' : '.html'
, outputFilepath = dest + outputFilename + outputExtension
, compiled = grunt.helper('compile', src, options, wrapper, outputFilename, filepath);
grunt.file.write(outputFilepath, compiled);
Expand Down
39 changes: 39 additions & 0 deletions test/amd_test.js
@@ -0,0 +1,39 @@
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['jade-amd'] = function (test){
'use strict';

test.expect(2);

var actual, expected;
// Test the runtime output
actual = grunt.file.read('tmp/jade-amd/runtime.js');
expected = grunt.file.read('test/fixtures/amd/runtime_expected.js');
test.equal(actual, expected, 'should generate an AMD module for the runtime');
// Test helloworld.jade output
actual = grunt.file.read('tmp/jade-amd/helloworld.js');
expected = grunt.file.read('test/fixtures/amd/helloworld_expected.js');
test.equal(actual, expected, 'should generate an AMD module for the template');

test.done();
};
42 changes: 42 additions & 0 deletions test/custom_extension_test.js
@@ -0,0 +1,42 @@
var grunt = require('grunt');
var fs = require('fs');
var path = require('path');
// In Nodejs 0.8.0, existsSync moved from path -> fs.
var existsSync = fs.existsSync || path.existsSync;

/*
======== 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['jade-custom_extension'] = function (test){
'use strict';

test.expect(2);

var actual, expected, runtimeExists;
// Test there is no runtime output
runtimeExists = existsSync('tmp/jade-custom_extension/runtime.xml') || existsSync('tmp/jade-html/runtime.js');
test.equal(runtimeExists, false, 'should NOT generate a module for the runtime');
// Test helloworld.jade output
actual = grunt.file.read('tmp/jade-custom_extension/helloworld.xml');
expected = grunt.file.read('test/fixtures/custom_extension/helloworld_expected.xml');
test.equal(actual, expected, 'should generate an XML file for the template');

test.done();
};
39 changes: 39 additions & 0 deletions test/debug_test.js
@@ -0,0 +1,39 @@
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['jade-debug'] = function (test){
'use strict';

test.expect(2);

var actual, expected;
// Test the runtime output
actual = grunt.file.read('tmp/jade-debug/runtime.js');
expected = grunt.file.read('test/fixtures/debug/runtime_expected.js');
test.equal(actual, expected, 'should generate a global module for the runtime');
// Test helloworld.jade output
actual = grunt.file.read('tmp/jade-debug/helloworld.js');
expected = grunt.file.read('test/fixtures/debug/helloworld_expected.js');
test.equal(actual, expected, 'should generate a global module (with debug) for the template');

test.done();
};
11 changes: 11 additions & 0 deletions test/fixtures/amd/helloworld_expected.js
@@ -0,0 +1,11 @@
define(['runtime'], function(jade){
return function anonymous(locals, attrs, escape, rethrow, merge) {
attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
var buf = [];
with (locals || {}) {
var interp;
buf.push('<h1>Hello, tester!</h1>');
}
return buf.join("");
};
});

0 comments on commit 2dcab51

Please sign in to comment.