Comparing version 0.3.0 to 0.3.1
28
index.js
@@ -73,4 +73,4 @@ /* jshint noyield: true */ | ||
} | ||
, noCache = false | ||
, cachedCompiler = {} | ||
, globalNoCache = false | ||
, compilers = new Map() | ||
, defaultLocals, viewPath | ||
@@ -95,6 +95,5 @@ | ||
* @param {Object} options options that pass to Jade compiler, merged with global default options | ||
* @param {Boolean} force true - force to re-compile template instead of use cached compiler | ||
* false - force to use cached compiler | ||
* @param {Boolean} noCache use cache or not | ||
*/ | ||
return function* (tpl, locals, options, force) { | ||
return function* (tpl, locals, options, noCache) { | ||
var compileOptions, tplPath, rawJade, compiler, skipCache | ||
@@ -114,13 +113,12 @@ | ||
skipCache = options === true || force === true | ||
skipCache = _.isBoolean(options) ? options : _.isBoolean(noCache) ? noCache : globalNoCache | ||
if (!skipCache) { | ||
compiler = cachedCompiler[tplPath] | ||
} | ||
if (skipCache) { | ||
compiler = jade.compile(rawJade, compileOptions) | ||
} else { | ||
compiler = compilers.get(tplPath) | ||
if (!compiler) { | ||
if (noCache === true || skipCache || !cachedCompiler[tplPath]) { | ||
cachedCompiler[tplPath] = compiler = jade.compile(rawJade, compileOptions) | ||
} else { | ||
compiler = cachedCompiler[tplPath] | ||
if (!compiler) { | ||
compiler = jade.compile(rawJade, compileOptions) | ||
compilers.set(tplPath, compiler) | ||
} | ||
@@ -149,3 +147,3 @@ } | ||
if (_.isBoolean(options.noCache)) { | ||
noCache = options.noCache | ||
globalNoCache = options.noCache | ||
} | ||
@@ -152,0 +150,0 @@ |
{ | ||
"name": "koa-jade", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A Jade middleware for Koa", | ||
@@ -29,12 +29,12 @@ "main": "index.js", | ||
"dependencies": { | ||
"jade": "~1.7.0", | ||
"fs-extra": "~0.11", | ||
"fs-extra": "^0.12.0", | ||
"jade": "^1.7.0", | ||
"lodash": "*" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.7", | ||
"gulp-jshint": "^1.6", | ||
"jshint-stylish": "*", | ||
"koa": "^0.6", | ||
"marked": "*" | ||
"gulp": "^3.8.8", | ||
"gulp-jshint": "^1.8.5", | ||
"jshint-stylish": "^1.0.0", | ||
"koa": "^0.12.2", | ||
"marked": "^0.3.2" | ||
}, | ||
@@ -41,0 +41,0 @@ "engines": { |
@@ -49,3 +49,3 @@ # Koa-jade | ||
`noCache`: if `true`, re-compile templates when page refreshed; if `false`, use cached compiler first. Can be overrided by `render`'s `force`. | ||
`noCache`: use cache or not. Cache could make template rendering 100x faster than without cache. It useful for production, but useless for development (pages would not be updated untill Koa restarted). In most case, `noCache: process.env === 'development'` should be enough. If wanna control it in production for specific page, use `render()`'s `noCache` instead. | ||
@@ -62,3 +62,3 @@ `helperPath`: String or Array, where to load helpers, and make them available on all `.jade`. In Array, you can use object to assgin name for module, eg: `{ random: './path/to/random.js' }`. | ||
### render(tpl, locals, options, force) | ||
### render(tpl, locals, options, noCache) | ||
@@ -69,11 +69,11 @@ Render template, and set rendered template to `this.body`. | ||
`locals`: locals for this page. Optional. If `options` or `force` presented, please use `{}`, `undefined` or `null` for empty `locals`. | ||
`locals`: locals for this page. Optional. If `options` or `noCache` presented, please use `{}`, `undefined` or `null` for empty `locals`. | ||
`options`: override global default options for this page. Only assigning an `object` or a `boolean` to it will take effects. | ||
`force`: tell Jade if force to re-compile template instead loading it from cache. By default, `koa-jade` stores the results of `Jade.compile` in memories, in order to speed up the future request. By setting force to `true` or `false` will force these behaviors: `true` - force to re-compile template instead of use cached compiler, `false` - force to use cached compiler first. | ||
`noCache`: use cache or not. Notes: 1. overrides global `noCache`; 2. won't affect other pages. | ||
If `options` is set to `true` or `false`, will be treated as `force`, and `force` will be ignored. For example, `render(tpl, locals, true)` equals to `render(tpl, locals, {}, true)`, `render(tpl, locals, true, false)` will force re-compilation. | ||
If `options` is set to `true` or `false`, it will be treated as `noCache`, and `noCache` will be ignored. For example, `render(tpl, locals, true)` equals to `render(tpl, locals, {}, true)`, and `render(tpl, locals, true, false)` will skip cache and re-compile template. | ||
`options` and `force` are optional. | ||
`options` and `noCache` are optional. | ||
@@ -80,0 +80,0 @@ ## basedir |
12277
168
+ Addedacorn@1.2.22.7.0(transitive)
+ Addedacorn-globals@1.0.9(transitive)
+ Addedalign-text@0.1.4(transitive)
+ Addedasap@1.0.0(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedcharacter-parser@1.2.1(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedcommander@2.6.02.8.1(transitive)
+ Addedconstantinople@3.0.2(transitive)
+ Addedfs-extra@0.12.0(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedjade@1.11.0(transitive)
+ Addedjstransformer@0.0.2(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedpromise@6.1.0(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addeduglify-js@2.8.29(transitive)
+ Addedvoid-elements@2.0.1(transitive)
+ Addedwith@4.0.3(transitive)
+ Addedyargs@3.10.0(transitive)
- Removedasync@0.2.10(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedcharacter-parser@1.2.0(transitive)
- Removedcommander@2.1.0(transitive)
- Removedconstantinople@2.0.1(transitive)
- Removedfs-extra@0.11.1(transitive)
- Removedjade@1.7.0(transitive)
- Removedminimatch@10.0.1(transitive)
- Removedmonocle@1.1.51(transitive)
- Removedreaddirp@0.2.5(transitive)
- Removedsource-map@0.1.34(transitive)
- Removeduglify-js@2.4.24(transitive)
- Removedvoid-elements@1.0.0(transitive)
- Removedwith@3.0.1(transitive)
- Removedyargs@3.5.4(transitive)
Updatedfs-extra@^0.12.0
Updatedjade@^1.7.0