ejs
ejs copied to clipboard
Add 'literal' tag to make content in the tag pair be taken as literal and not be parsed
When you ejs template contains literal strings <% or %>, it will be recognized as delimiters by ejs engine,where it is not the template author's intention and it probably cause en parse error. We need add support to make some content (especailly string equals to delimiter ) be treated as literal and not parsed by ejs. I add such support as a literal tag.Its usage is as follows:
<%literal%>
<span>this span contains delimeters <% %> , it should be wrapped by literal tag</span>
<%/literal%>
<script type="text/javascript">
var template="<%=title%>";
...
</script>
Don't inline a polyfill for JSON, either make do without JSON.stringify, or require it. We probably have other things that break worse in older browsers anyway, just get people to polyfill it properly.
Although JSON is not a global object of node.js. But node.js is built on V8, which provides the global object JSON. And The definition of the JSON object is part of the ECMAScript 5 specification.So I think threre is no problem if the ejs template runs at Node.js server side. For old browsers , I have check whether the JSON object exists.If it doesn't exists , I provide a alternative method to do json stringify. See the code:
exports.stringifyJSON=function(obj)
{
if(typeof(JSON)=="object"&&typeof(JSON.stringify)=="function")
return JSON.stringify(obj);
else
return stringify(obj);
}
For the js coding style (curly brace) issue , I will modify the code and pull a request again.
Yes, older browsrs will need to polyfill JSON. The problem is that they will most likely need JSON for things other than EJS. This change would force even modern browsers to download the shim for JSON. That's a lot of code to support browsers that have a tiny market share.
If you want to support older browssers, just use something like modenizr in your own projects. Don't do it at a library level.
I will remove the stringify method for supporting old browsers in util.js.
This would be a great addition. Will this be included someday?
Agreed. This would be a seemingly great feature.