Comparing version 0.4.1 to 0.5.0
45
index.js
@@ -11,6 +11,8 @@ /** | ||
const vm = require('vm'); | ||
const p = require('path'); | ||
const path = require('path'); | ||
const stripComments = require('strip-comments'); | ||
const odesza = {}; | ||
const blocks = {}; | ||
const cache = { | ||
@@ -42,6 +44,5 @@ templates: {}, | ||
// strip comments | ||
template = template.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, '$1'); | ||
template = stripComments(template); | ||
var s = getStatements(template); | ||
let s = getStatements(template); | ||
@@ -92,6 +93,6 @@ // if an extend statement is found, fill the extended template blocks in | ||
s.include.forEach(statement => { | ||
let path = `${basePath}${statement}`; | ||
let p = `${basePath}${statement}`; | ||
template = template | ||
.split(`include ${statement}`) | ||
.join(odesza.renderFile(path, options)); | ||
.join(odesza.renderFile(p, options)); | ||
}); | ||
@@ -111,5 +112,5 @@ | ||
odesza.renderFile = function(location, options) { | ||
var template; | ||
let basePath = location.substr(0, location.lastIndexOf('/') + 1); | ||
location = resolvePath(location); | ||
var basePath = location.substr(0, location.lastIndexOf('/') + 1); | ||
var template; | ||
if (useCache && cache.templates[location] != null) { | ||
@@ -125,3 +126,3 @@ template = cache.templates[location]; | ||
/** | ||
* Disables template and path caching. | ||
* Disables caching. | ||
* | ||
@@ -139,3 +140,3 @@ * @public | ||
* @public | ||
* @param {string} path | ||
* @param {string} file | ||
* @param {object} options | ||
@@ -145,5 +146,5 @@ * @param {function} fn | ||
odesza.__express = function(path, options, fn) { | ||
odesza.__express = function(file, options, fn) { | ||
try { | ||
return fn(null, odesza.renderFile(path, options)); | ||
return fn(null, odesza.renderFile(file, options)); | ||
} catch (e) { | ||
@@ -180,14 +181,14 @@ return fn(e); | ||
* @private | ||
* @param {string} path The relative path to the file. | ||
* @return {string} The resolved path. | ||
* @param {string} file The relative file to the file. | ||
* @return {string} The resolved path for the file. | ||
*/ | ||
function resolvePath(path) { | ||
if (typeof path != 'string') { | ||
throw new TypeError('invalid path: input must be a string'); | ||
function resolvePath(file) { | ||
if (typeof file != 'string') { | ||
throw new TypeError('invalid file: input must be a string'); | ||
} | ||
if (useCache && cache.paths[path] != null) { | ||
return cache.paths[path]; | ||
if (useCache && cache.paths[file] != null) { | ||
return cache.paths[file]; | ||
} | ||
var resolvedPath = p.resolve(path); | ||
var resolvedPath = path.resolve(file); | ||
if (!fs.existsSync(resolvedPath)) { | ||
@@ -199,6 +200,6 @@ if (fs.existsSync(`${resolvedPath}.ode`)) { | ||
} else { | ||
throw new Error(`cannot find file with path: ${path}`); | ||
throw new Error(`cannot find file with file: ${file}`); | ||
} | ||
} | ||
cache.paths[path] = resolvedPath; | ||
cache.paths[file] = resolvedPath; | ||
return resolvedPath; | ||
@@ -205,0 +206,0 @@ } |
{ | ||
"name": "odesza", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Write clean, expressive templates with just HTML and inline JavaScript", | ||
@@ -23,4 +23,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"commander": "^2.9.0" | ||
"commander": "^2.9.0", | ||
"strip-comments": "^0.4.2" | ||
} | ||
} |
# Odesza | ||
Odesza is a templating engine that allows you to write clean, expressive templates with inline JavaScript. | ||
Odesza is a templating engine that allows you to write clean, expressive templates with inline JavaScript. Some of the features include | ||
- multiple inheritance (extends, includes, blocks) | ||
- multiple inheritance (extends, includes, block scope) | ||
- full access to inline ES6 JavaScript | ||
- support for Express | ||
- no magic or new language to learn | ||
- support for Express framework | ||
- no "magic" or new shorthand to learn | ||
@@ -10,0 +10,0 @@ ### Inspiration |
Sorry, the diff of this file is not supported yet
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
18128
2
+ Addedstrip-comments@^0.4.2
+ Addeddefine-property@0.2.5(transitive)
+ Addedesprima@2.7.3(transitive)
+ Addedesprima-extract-comments@0.2.1(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedextract-comments@0.10.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.7(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedparse-code-context@0.2.2(transitive)
+ Addedstrip-comments@0.4.4(transitive)