Skip to content

Commit a3530a6

Browse files
committed
Merge branch 'master' of https://github.com/jsdoc3/jsdoc
2 parents 97e5cb9 + 5ea5f62 commit a3530a6

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

rhino_modules/jsdoc/template.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/**
2-
@overview
3-
@author Rafał Wrzeszcz <[email protected]>
4-
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
2+
* @file Wrapper for underscore's template utility to allow loading templates from files.
3+
* @author Rafał Wrzeszcz <[email protected]>
4+
* @author <a href="mailto:[email protected]">Matthew Christopher Kastor-Inare III</a>
5+
* @license Apache License 2.0 - See file 'LICENSE.md' in this project.
6+
* @change 2012-10-20 cache and settings are no longer private fields.
7+
* This was done so that plugins could use this class without messing up
8+
* the final output when template name collisions occur. i.e. each instance
9+
* has it's own template cache. The settings were made specific to each
10+
* instance so that users of this class could redefine the underscore
11+
* template settings if they want to.
512
*/
613

714
var _ = require('underscore'),
815
fs = require('fs'),
916
path = require('path');
1017

11-
// override default settings
12-
var settings = {
13-
evaluate: /<\?js([\s\S]+?)\?>/g,
14-
interpolate: /<\?js=([\s\S]+?)\?>/g,
15-
escape: /<\?js~([\s\S]+?)\?>/g
16-
};
1718

1819
/**
1920
@module jsdoc/template
@@ -27,6 +28,14 @@ var settings = {
2728
exports.Template = function(path) {
2829
this.path = path;
2930
this.layout = null;
31+
this.cache = {};
32+
// override default template tag settings
33+
this.settings = {
34+
evaluate : /<\?js([\s\S]+?)\?>/g,
35+
interpolate: /<\?js=([\s\S]+?)\?>/g,
36+
escape : /<\?js~([\s\S]+?)\?>/g
37+
};
38+
3039
};
3140

3241
/** Loads template from given file.
@@ -35,11 +44,9 @@ exports.Template = function(path) {
3544
*/
3645
exports.Template.prototype.load = function(file) {
3746
var _path = path.join(this.path, file);
38-
return _.template(fs.readFileSync(_path), null, settings);
47+
return _.template(fs.readFileSync(_path), null, this.settings);
3948
};
4049

41-
// templates cache
42-
var cache = {};
4350

4451
/**
4552
Renders template using given data.
@@ -52,12 +59,12 @@ var cache = {};
5259
*/
5360
exports.Template.prototype.partial = function(file, data) {
5461
// load template into cache
55-
if (!(file in cache)) {
56-
cache[file] = this.load(file);
62+
if (!(file in this.cache)) {
63+
this.cache[file] = this.load(file);
5764
}
5865

5966
// keep template helper context
60-
return cache[file].call(this, data);
67+
return this.cache[file].call(this, data);
6168
};
6269

6370
/**

0 commit comments

Comments
 (0)