Comparing version 0.1.2 to 0.1.3
# Artist changes | ||
* 0.1.3 | ||
1. Option `refresh` is replaced by `cache` | ||
* 0.1.2 | ||
@@ -4,0 +6,0 @@ 1. Fixed issue with options |
63
index.js
var defaults = { | ||
refresh: true, | ||
cache: false, | ||
beautify: true, | ||
@@ -23,3 +23,3 @@ debug: true | ||
* | ||
* - `refresh` auto regenerate the cache on file change | ||
* - `cache` cache compiled functions | ||
* - `beautify` beautify compiled functions | ||
@@ -40,31 +40,27 @@ * - `debug` include debugging information | ||
function verifyCache(ts, path, data, fn) { | ||
if (path in cache && cache[path].ts >= ts) { | ||
fn(null, cache[path].tmpl(data)); | ||
} else { | ||
return function (path, data, fn) { | ||
if (options.cache && path in cache) { | ||
try { | ||
var code = fest.compile(path, options), | ||
tmpl = (new Function('__fest_error', 'return ' + code))(options.errorFn); | ||
cache[path] = { | ||
ts: ts, | ||
tmpl: tmpl | ||
}; | ||
fn(null, tmpl(data)); | ||
fn(null, cache[path](data)); | ||
} catch (err) { | ||
fn(err); | ||
} | ||
} | ||
} | ||
return function (path, data, fn) { | ||
if (options.refresh) { | ||
} else { | ||
fs.stat(path, function (err, stats) { | ||
if (err) { | ||
fn(err); | ||
} else { | ||
verifyCache(stats.mtime.valueOf(), path, data, fn); | ||
} else try { | ||
if (!stats.isFile()) { | ||
fn(new Error('File "' + path + '" is not a regular file.')); | ||
} | ||
var code = fest.compile(path, options), | ||
tmpl = (new Function('__fest_error', 'return ' + code))(options.errorFn); | ||
if (options.cache) { | ||
cache[path] = tmpl; | ||
} | ||
fn(null, tmpl(data)); | ||
} catch (err) { | ||
fn(err); | ||
} | ||
}); | ||
} else { | ||
verifyCache(0, path, data, fn); | ||
} | ||
@@ -82,3 +78,3 @@ }; | ||
* | ||
* - `refresh` auto regenerate the cache on file change | ||
* - `cache` cache compiled functions | ||
* - `beautify` beautify compiled functions | ||
@@ -99,20 +95,19 @@ * - `debug` include debugging information | ||
function verifyCache(ts, path, data, fn) { | ||
if (path in cache && cache[path].ts >= ts) { | ||
return cache[path].tmpl(data); | ||
return function (path, data) { | ||
if (options.cache && path in cache) { | ||
return cache[path](data); | ||
} else { | ||
var stats = fs.statSync(path); | ||
if (!stats.isFile()) { | ||
throw new Error('File "' + path + '" is not a regular file.'); | ||
} | ||
var code = fest.compile(path, options), | ||
tmpl = (new Function('__fest_error', 'return ' + code))(options.errorFn); | ||
cache[path] = { | ||
ts: ts, | ||
tmpl: tmpl | ||
}; | ||
if (options.cache) { | ||
cache[path] = tmpl; | ||
} | ||
return tmpl(data); | ||
} | ||
} | ||
return function (path, data) { | ||
return verifyCache(options.refresh ? fs.statSync(path).mtime.valueOf() : 0, path, data); | ||
}; | ||
} |
{ | ||
"name": "artist", | ||
"version": "0.1.2", | ||
"description": "Template engine for node.js built on Fest", | ||
"version": "0.1.3", | ||
"description": "Template engine for node.js built on fest", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
# Artist | ||
[![Build Status](https://secure.travis-ci.org/eprev/artist.png?branch=master)](http://travis-ci.org/eprev/artist) | ||
Artist is template engine for node.js built on [Fest](http://github.com/mailru/fest). | ||
Artist is a template engine for node.js built on [fest](http://github.com/mailru/fest). | ||
@@ -9,6 +10,5 @@ Features: | ||
* Caches compiled templates | ||
* Auto regenerates the cache on files change | ||
* Synchronous and asynchronous versions | ||
* Synchronous and asynchronous API | ||
* Express-compatible | ||
* Handles Fest's runtime errors | ||
* Handles fest's runtime errors | ||
@@ -18,32 +18,38 @@ ## Installation | ||
``` | ||
npm install -g artist | ||
npm install artist | ||
``` | ||
## API | ||
Provides `render()` and `renderSync()` functions. View source for documentation. | ||
## Usage | ||
See sources for documentation. | ||
Express: | ||
With express: | ||
```javascript | ||
app.engine('xml', require('artist').render()); | ||
``` | ||
Express (production environment): | ||
With express (production environment): | ||
```javascript | ||
app.engine('xml', require('artist').render({ | ||
cache: true, | ||
debug: false | ||
})); | ||
``` | ||
Synchronous version: | ||
```javascript | ||
var render = require('artist').renderSync(); | ||
// ... | ||
var html = render('index.html', {foo: 'bar'}); | ||
var html = render('index.xml', {foo: 'bar'}); | ||
``` | ||
index.xml | ||
```xml | ||
<?xml version="1.0"?> | ||
<fest:template xmlns:fest="http://fest.mail.ru" context_name="json"> | ||
<fest:value>json.foo</fest:value> | ||
</fest:template> | ||
``` |
@@ -9,2 +9,3 @@ var assert = require('assert'), | ||
render = artist.render({ | ||
cache: true, | ||
errorFn: function (err) { | ||
@@ -80,2 +81,3 @@ errors.push(err) | ||
render = artist.renderSync({ | ||
cache: true, | ||
errorFn: function (err) { | ||
@@ -82,0 +84,0 @@ errors.push(err) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11481
11
53
228