Some compiling rules: http://draft.monkeyscript.org/ejs/spec.txt
An example .ejs file: http://draft.monkeyscript.org/ejs/example.ejs
And it's compiled form: http://draft.monkeyscript.org/ejs/example.js
For readability I've left newlines inside of strings, however most
likely compiled templates will replace newlines with \n after escaping
backslashes and single quotes.
So far I've omitted notes on actual code calls, originally I was
thinking of handling things with `this` but I'm thinking it'll be best
to specify names for arguments formally for passing data, or perhaps
make use of with.
A few interesting notes:
* Like JSONP a variable or callback can be specified so it's actually
possible to send compiled templates to the browser in fun ways that let
you use a template both browser and server side (as long as you avoid
newer syntaxes not supported in browsers, and include a minimal ejs.js
file if you make use of filters).
* I made this from the start with an understanding of some of erb's
faults, so there are actually some things you can do in ejs you can't do
in erb.
For example, in erb this will fail miserably: <ul><%= [1,2,3,4,5].map {
|i| %><li><%= i %></li><% }.join('\n') %></ul>
But in ejs this will work: <ul><%= [1,2,3,4,5].map( %><li><%=
arguments[0] %></li><% ).join('\n') %></ul>
Though I haven't specified syntax for naming the arguments going to
unclosed functional blocks, I'll probably use something like 1.8's
function() syntax sugar.
--
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
I do. Around here it takes about an hour.
Given your predilection for zone acquisition and your tinkerer's
mentality, I would recommend buying yourself a static IP and a copy of
DNS and Bind (O'Reilly).
Wes
--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
I already know enough about DNS though. Personally I don't go for the
de-facto tools, rather than Bind I'd probably opt for PowerDNS, nice
support for using a database as a backend.
It might be a good option for the small company I work for, but
personally finding a reasonable DNS host with fallback servers might be
best.
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
EJS appears to have a lot in common with PHP and JSP. I've had the
pleasure of working with Django recently, which has one of the new
styles of template parser/formatters that are more structured and
readable, in addition to providing insightful tracebacks. Kevin
Dangoor and George Moschovitis pointed out JSON Template, which
appears to be a similar, strong, interoperable, and idiomatically
JavaScript contender for the template engine role.
http://json-template.googlecode.com/svn/trunk/doc/Introducing-JSON-Template.html
But, while I would personally go a different way, if you were to
provide a package of your EJS template engine, and if it were made
interoperable, I think your package could potentially be listed in a
ServerJS package index. Are you recommending that EJS be a component
of the ServerJS standard library?
Kris Kowal
>
> EJS does have some stuff in common with PHP, I don't really know about
> JSP though.
For JSP, you could write it like EJS, but not the only way. Of course
you can use JavaScript as the language of your JSP. And JSP would be
way faster.
The main problem with template schemes like EJS is they break XML well-
formedness -- completely unnecessary.
-Rob
Start/End is completely customizable, I could even step that up even
more to let you write up regexes and differentiate an = from a non = and
use different ends.
Though frankly I'd avoid any use of } or ] like the plague, <> are the
only parenthesis that make sense, something like this will become hell:
${ if( testing ) { }$Some nested block${ } }$
And it won't even parse right if you try EJS.endTag = '}';
But quite frankly I don't see much point in your template file being
valid xml, the output is what matters, and a valid xml template doesn't
mean you have valid xml output: (pardon the syntax, I don't have a
connection to check the JSONTemplate syntax right now)
<ul>
{section .list}
<li><a href="{href}">{if text}{text}</a>{or}Untitled{/if}</li>
{/section}
</ul>
That template is xml valid, but the output will be wrong any time there
is no text specified for an item in the list.
>> As a bonus to that, it means that you aren't limited to the world of
>> XHTML and you can use .ejs to get any kind of output you want, even
>>
>
> Fine, but there still is no *real* need to use angle brackets in a way
> that breaks well-formedness rules when you *do* want XML.
>
Then use them in a way that doesn't break well-formedness:
EJS.startTag = '<ejs>';
EJS.endTag = '</ejs>';
<ul><ejs>for ( let item in list ) {</ejs><li><ejs>= item
</ejs><li><ejs>}</ejs></ul>
The reason for the <% ... %> is:
A) Tradition
B) Trying to throw {} into the syntax when you're allowing direct
embedding of the entire language becomes a nightmare since {} already
have other meanings inside of the language.
Security and a simple expressed syntax vs. the power and flexibility of
having the entire language embedded.
Both have perfectly valid uses depending on what you need, pick what
works for your project and use it. There's no reason for one kind to die
off in favor of another.
Myself, sometimes I want the safe simple syntax of a normal template
language, and other times I have more use for the fully embedded setup.
> -Rob
>
>
>> write a bit of looping stuff into CSS, JS, or whatnot. In fact I used
>> ERB at one point to write the CSS for a few color scheme classes.
>> Conversely I find that things like XSL which do guarantee XML
>> well-formed output get in the way and force you to write your
>> templates
>> around the syntax, rather than write the template around your
>> document.
>>
>>
>> ~Daniel Friesen (Dantman, Nadir-Seen-Fire)
>>
>> Robert Koberg wrote:
>>
>>> On May 3, 2009, at 7:34 PM, Daniel Friesen wrote:
>>>
>>>
>>>
>>>> EJS does have some stuff in common with PHP, I don't really know
>>>> about
>>>> JSP though.
>>>>
>>>>
>>> For JSP, you could write it like EJS, but not the only way. Of course
>>> you can use JavaScript as the language of your JSP. And JSP would be
>>> way faster.
>>>
>>> The main problem with template schemes like EJS is they break XML
>>> well-
>>> formedness -- completely unnecessary.
>>>
>>> -Rob
>>>
>>>
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
>
> Robert Koberg wrote:
>> On May 3, 2009, at 9:08 PM, Daniel Friesen wrote:
>>
>>
>>> XML well-formedness has no business in this area.
>>> I see no reason to validate my .ejs file against XML, only the
>>> output
>>> itself matters.
>>>
>>
>> I would argue that it reduces flexibility. I (and others) like to
>> generate templates in-addition-to/instead-of just handwriting a
>> template. Or use the template in a transform that renders a larger
>> page.
>>
> Huh, what does XML Validity have to do with the ability to nest
> templates in other templates?
you seem to be missing the point. First, I should have written an
*xsl* transform -- apologies if this lead to confusion. You may not
care, but I do. When I have to deal with a template system that is not
able to be written in a well-formed manner (I see that yours can be),
I cannot transform it to meet my needs whether is for a full html page
render, conversion to JSON, conversion to atom, creation of reporting
for various occurences of things, and on and on and on. It ill require
manually rework from someone.
I am simply saying that angles brackets used in a way as to break xml
well-formedness are unnecessary and should be avoided.
think of the children!
-Rob
If you're interested, I've already made a head start on porting
Narcissus to our module spec. The defs and parse modules work in
Narwhal, at least, although there are a couple properties left still.
I have no plans to do the exec module personally, but would be glad to
pull it from anyone who needs it. My interest in Narcissus is in
creating a module bundler and minifier (I would like to target both
client and server side with modules with Narwhal and Chiron).
http://github.com/kriskowal/narcissus/tree/master
Kris Kowal
On another port note. Narcissus seams to be based around JS 1.5; It's
missing support for all the nice js1.6-1.8 additions like let, function
syntax sugar, destructors, and various other parts of the whole
generators and iterators bit.
If anyone is interested in porting Narcissus to a version that supports
the newer features, I'd be interested in that project. Or an even wilder
idea, a version that conditionally supports different JS versions ;).
Cause I'm over here in EJS left with syntax errors whenever I want to
use my favorite new features.
As for all these notes about Narcissus 'modification', it's unfortunate
but it looks like Narcissus wasn't build in a very extension friendly
manor. To use narcissus to do something other than pure js1.5 stuff you
need to hack it and modify it into a different piece of software
If anyone is interested in working on taking Narcissus and making it
into a system where someone can easily take the nice isolated Narcissus
package and only need to extend things to make it do something new
(Bonus if we can make it do this in a way that multiple different syntax
parsers based on Narcissus (ejs, js1.8, etc...) can coexist without
loading Narcissus more than once.) I'd be interested in discussing ideas
for that as well.
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
Yeah, I fixed that in my version on github too, along with most of the
properties and such. It's probably not a perfect match for your use
case, and it's not complete, but it's a head start.
Kris Kowal
The way Wes' GPSEE handles compiling SpiderMonkey gives me a real nice
fuzzy feeling, unfortunately I had an error when compiling GPSEE
itself. (I still love the compiling though... It's a little verbose in
what to do, but it's lent well to prebuilt packages and whatnot)
If you disable JS_THREADSAFE, Spidermonkey should work without NSPR.
> Frankly I don't feel like compiling boost from source for flusspferd
> just cause it uses a version newer than what I already have installed
> on my system.
>
We support versions 1.36, 1.37, 1.38 and 1.39 of Boost. Older versions
than that don't have all the features we use. (Specifically it is
boost::unordered_map, a hash map class introduced in 1.36, that makes
Flusspferd incompatible with Boost 1.35 and older. Before 1.36 was
rolled out, we used boost::multi_index_container for the same purpose,
but that really was a lot of unneeded overhead that we could strip by
moving to boost::unordered_map.)
But see <http://www.boost.org/users/history/>.
Of course Flusspferd requires a working Spidermonkey first.
http://jslibs.googlecode.com/svn/wiki/jslibs_debugger2.png
Soubok's looks interesting. The debugger itself is written in XUL.
> Wes
>
> --
> Wesley W. Garland
> Director, Product Development
> PageMail, Inc.
> +1 613 542 2787 x 102
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
The issue is Soubok's build system. He's got a whole libs/ folder which
pulls in sources for a number of other libraries. And he uses something
like recursive make and has it compile everything and does something
along the line of statically linking.
It works great from the standpoint of Windows where you're just about
completely unlikely to run into any of those libraries as shared
libraries. But doesn't lend itself to using ones that are available.
>> Frankly I don't feel like compiling boost from source for flusspferd
>> just cause it uses a version newer than what I already have installed
>> on my system.
>>
>>
>
> We support versions 1.36, 1.37, 1.38 and 1.39 of Boost. Older versions
> than that don't have all the features we use. (Specifically it is
> boost::unordered_map, a hash map class introduced in 1.36, that makes
> Flusspferd incompatible with Boost 1.35 and older. Before 1.36 was
> rolled out, we used boost::multi_index_container for the same purpose,
> but that really was a lot of unneeded overhead that we could strip by
> moving to boost::unordered_map.)
>
> But see <http://www.boost.org/users/history/>.
>
> Of course Flusspferd requires a working Spidermonkey first.
>
Ubuntu has boost 1.34, other than that though, I don't even know if the
SpiderMonkey 1.7 will work for Narcissus at the moment.
~Daniel Friesen (Dantman, Nadir-Seen-Fire)
Ubuntu has newer versions available:
http://packages.ubuntu.com/search?keywords=boost%201.37
We support Spidermonkey 1.8+.
--
In theory, there is no difference between theory and practice.
In practice, there is. .... Yogi Berra
I've implemented something very similar before ServerJS started. I've
attached the source code as it may help. (It may also be throw away.)
Peter