Skip to content

Commit ebcca73

Browse files
committed
clean rendering .string
1 parent a479a4c commit ebcca73

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
BIN = ./node_modules/.bin/
2+
NODE ?= gnode
23

34
test:
45
@$(NODE) $(BIN)mocha \

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ Jade plugin for [component-builder2](https://github.com/component/builder2.js).
55
- Caches compilations
66
- Either include the runtime as a dependency or a global
77
- Compiles the debugging version in development environment
8+
- Option to compile the template to an HTML string
89

910
## Example
1011

1112
```js
13+
var fs = require('fs');
1214
var build = require('component-builder2');
1315
var jade = require('builder-jade');
1416

1517
build.scripts(nodes)
1618
.use('scripts', build.plugins.js())
1719
.use('templates', build.plugins.string())
18-
.use('templates', jade())
19-
.use('jade', jade());
20+
.use('templates', jade({
21+
string: true,
22+
}))
23+
.use('jade', jade({
24+
runtime: false,
25+
}))
26+
.build(function (err, string) {
27+
if (err) throw err;
2028

21-
build.pipe(process.stdout);
29+
fs.writeFileSync('build.js', string);
30+
})
2231
```
2332

2433
You could put your jade files in `.templates` or create your own field like `.jade`.
@@ -39,6 +48,21 @@ Without the global runtime, you have to define the `visionmedia/jade` dependency
3948

4049
If you want to avoid this as, use the global runtime.
4150

51+
## Options
52+
53+
Plugin options:
54+
55+
- `string` - compile the template as an HTML string instead of a function.
56+
- `runtime` - use the global runtime instead of using a local `jade` dependency. See below.
57+
58+
Jade options:
59+
60+
- `pretty`
61+
- `self`
62+
- `debug`
63+
- `compiler`
64+
- `globals`
65+
4266
## Global Runtime
4367

4468
You may use the global runtime by prepending `jade.runtime` to your build and using the `.runtime` option:
@@ -48,7 +72,7 @@ build.scripts(nodes)
4872
.use('templates', jade({
4973
runtime: true
5074
}))
51-
.toStr(function (err, string) {
75+
.build(function (err, string) {
5276
if (err) throw err;
5377
string = jade.runtime + string;
5478
fs.writeFileSync('build.js', string);

index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ exports = module.exports = function (options) {
1313
file.read(function (err, string) {
1414
if (err) return done(err);
1515

16-
setImmediate(done);
17-
1816
// don't cache between environments
1917
var dev = this.dev ? '1' : '0';
2018
var compile = options.string ? '1' : '0';
@@ -32,20 +30,18 @@ exports = module.exports = function (options) {
3230

3331
// compile into HTML string
3432
if (options.string) {
35-
var fn;
3633
try {
37-
fn =
34+
file.string =
3835
cache[hash] = cache[hash]
39-
|| Jade.compile(string, opts);
36+
|| JSON.stringify(Jade.render(string, opts));
4037
} catch (err) {
4138
done(err);
4239
return;
4340
}
4441

4542
file.extension = 'html';
46-
file.string = JSON.stringify(fn(options.locals || {}));
4743
file.define = true;
48-
44+
done();
4945
return
5046
}
5147

@@ -69,6 +65,8 @@ exports = module.exports = function (options) {
6965
file.string = 'var jade = require("jade");\n'
7066
+ 'module.exports = ' + res;
7167
}
68+
69+
done();
7270
})
7371
}
7472
}

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
"twitter": "https://twitter.com/jongleberry"
1010
},
1111
"license": "MIT",
12-
"repository": {
13-
"type": "git",
14-
"url": "https://github.com/component/builder-jade.git"
15-
},
16-
"bugs": {
17-
"mail": "[email protected]",
18-
"url": "https://github.com/component/builder-jade/issues"
19-
},
12+
"repository": "component/builder-jade",
2013
"dependencies": {
2114
"jade": "*"
2215
},

0 commit comments

Comments
 (0)