Comparing version 0.0.3 to 0.0.4
@@ -28,14 +28,15 @@ 'use strict'; | ||
var t; | ||
try | ||
{ | ||
var t = disableInclude ? str : include(str, data); | ||
t = disableInclude ? str : include(str, data); | ||
t = template(t, data); | ||
var compiled = _.template(t); | ||
return compiled(data); | ||
return _.template(t)(data); | ||
} | ||
catch(e) | ||
{ | ||
var msg = "Parsing error:: " + e.message; | ||
console.warn(msg); | ||
console.info(e); | ||
var msg = "Parsing error: " + e.message + " for " + t; | ||
console.warn(e.message + ":"); | ||
console.warn(t); | ||
console.trace(e); | ||
return msg; | ||
@@ -58,3 +59,3 @@ } | ||
return s.replace( | ||
/<%@\s+include\s+file=['|"|](.*?)['|"|]\s+%>/g, | ||
/<jspl\s*:\s*include\s*file=['|"|](.*?)['|"|]\s*\/\s*>/g, | ||
function(match, viewName) | ||
@@ -80,3 +81,3 @@ { | ||
{ | ||
var regexp = /<%@\s+template\s+file=['"](.*?)['"]\s+%>/; | ||
var regexp = /<jspl\s*:\s*template\s*file=['|"|](.*?)['|"|]\s*\/\s*>/; | ||
var matches = regexp.exec(content); | ||
@@ -91,5 +92,5 @@ if(!matches || !matches[1]) | ||
// Clean up view tags: template, html, body | ||
content = content.replace(/<%@\s*template.*%>/g, "") | ||
content = content.replace(/<jspl\s*:\s*template.*\/>/g, "") | ||
.replace(/<\s*(\/*\s*)*(html)*(body)*\s*>/g, ""); | ||
return layout.replace( /<jspl\s*:\s*doBody\s*\/>/g, content); | ||
return layout.replace( /<jspl\s*:\s*doBody\s*[/]*\s*>/g, content); | ||
}; | ||
@@ -96,0 +97,0 @@ exports.template = template; |
{ | ||
"name": "jspl", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "JSP-Like (JSPL) is a simple template engine based on the library: underscore. It's compliant with Express. And the syntax is similar to JSP.", | ||
@@ -5,0 +5,0 @@ "main": "lib/jspl", |
@@ -57,3 +57,3 @@ JSPL [![Build Status](https://travis-ci.org/jvmvik/jspl.svg?branch=master)](https://travis-ci.org/jvmvik/jspl) | ||
Condition: IF | ||
Condition: if | ||
--- | ||
@@ -64,3 +64,3 @@ File: views/index.html | ||
<%= user.profile.firstName %></p> | ||
<% } %> | ||
<% } %> | ||
``` | ||
@@ -76,3 +76,3 @@ | ||
Show variable content | ||
Display variable content | ||
--- | ||
@@ -138,7 +138,7 @@ File: views/index.html | ||
```html | ||
<%@ template file="templateName" %> | ||
<jspl:template file="templateName" /> | ||
``` | ||
- templateName : Location of the included view without extension. The extension .html will be added automatically. | ||
- <%@ %> : Indicate a tag | ||
- ```<jspl: />``` : Indicate a tag | ||
- template : Tag name | ||
@@ -151,3 +151,3 @@ - file : Tag parameter | ||
```html | ||
<%@ template file="layout" %> | ||
<jspl:template file="layout" /> | ||
``` | ||
@@ -165,7 +165,7 @@ | ||
``` | ||
<%@ include file="viewName" %> | ||
<jspl:include file="viewName" /> | ||
``` | ||
- viewName : Location of the included view without extension. The extension .html will be added automatically. | ||
- <%@ %> : Indicate a tag | ||
- ```<jspl: />``` : Indicate a tag | ||
- include : Tag name | ||
@@ -190,3 +190,5 @@ - file : Tag parameter | ||
I do not like Jade or whatever short HTML template engine. I understand why it's a good solution for basic website. | ||
But it does not mix well with complex HTML + Javascript Framework like AngularJS. Also, I think software developer should generally minimize the number of transformation that must be done to produce an output. | ||
But Jade do not mix well with complex HTML + Javascript Framework like AngularJS. Also, I think software developer should generally minimize the number of transformation that must be done to produce an output. | ||
And I have a pretty bad experience with EJS. | ||
For example EJS fails badly if you try to run a simple if condition. | ||
@@ -193,0 +195,0 @@ Roadmap |
@@ -14,5 +14,4 @@ { | ||
"body-parser": "~1.0.0", | ||
"debug": "~0.7.4", | ||
"jspl": "0.0.1" | ||
"debug": "~0.7.4" | ||
} | ||
} |
@@ -26,4 +26,4 @@ var expect = require('expect'); | ||
{ | ||
var str = '<%@ template file="layout" %>'; | ||
var regexp = /<%@\s+template\s+file=['"](.*?)['"]\s+%>/; | ||
var str = '<jspl : template file="layout" / >'; | ||
var regexp = /<jspl\s*:\s*template\s*file=['"](.*?)['"]\s*\/\s*>/; | ||
var matches_array = regexp.exec(str); | ||
@@ -36,3 +36,3 @@ console.log(matches_array[1]); | ||
// Template is layout.html | ||
var s = jspl.template('<%@ template file="layout" %><html><body><p>page content</p></body></html>', {}); | ||
var s = jspl.template('<jspl:template file="layout" /><html><body><p>page content</p></body></html>', {}); | ||
expect(s.replace(/\s*\n\s*/g,'')).toBe('<html><head><title>Layout</title></head><body><h1>Header</h1><p>page content</p></body></html>'); | ||
@@ -46,3 +46,3 @@ }); | ||
{ | ||
var s = jspl.include('<html><%@ include file="chunk" %></html>'); | ||
var s = jspl.include('<html><jspl:include file="chunk" /></html>'); | ||
expect(s).toBe('<html><h2>I\'m a chunk !!</h2></html>', {}); | ||
@@ -53,3 +53,3 @@ }); | ||
{ | ||
var s = jspl.include('<html><%@ include file="chunk2" %></html>',{title: "Header"}); | ||
var s = jspl.include('<html><jspl:include file="chunk2" /></html>',{title: "Header"}); | ||
expect(s).toBe('<html><h1>Header</h1></html>'); | ||
@@ -61,3 +61,3 @@ }); | ||
{ | ||
var s = jspl.include('<html><%@ include file="loop2" %></html>',{head: "Header",people:['Mike', 'Bob', 'Henry']}); | ||
var s = jspl.include('<html><jspl:include file="loop2" /></html>',{head: "Header",people:['Mike', 'Bob', 'Henry']}); | ||
expect(s).toBe('<html><h2>Header</h2>\n<ol>\n<li>Mike</li>\n<li>Bob</li>\n<li>Henry</li>\n</ol></html>'); | ||
@@ -85,3 +85,3 @@ }); | ||
var s = jspl.compile('test/data/loop.html', {}); | ||
expect(s).toBe('Parsing error:: people is not defined'); | ||
expect(s).toMatch(/Parsing error: people is not defined/); | ||
}); | ||
@@ -88,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
51283
46
325
193