celer / fire-ts

Fire TS is a templating library for NodeJS which specializes in generating non HTML templates (c, c++, Java, JavaScript, Ruby, Perl, etc)
MIT License
7 stars 1 forks source link

Improve passing context to included templates #2

Closed Rush closed 10 years ago

Rush commented 10 years ago

I find this feature be quite limited

This works:

<% var func = declaration.function; %>
<%@ v8_method.fts (func) %>

But this doesn't:

<%@ v8_method.fts (declaration.function) %>

I think it could easily be parsed with PEG.js.

Another thing is I would rather pass the whole context to the template so I would imagine some syntax to do this automatically:

<% with(declaration.function) { %>
   <%@ v8_method.fts  %>
<%} %>

Meanwhile, wish you pleasant vacation.

celer commented 10 years ago

So if the behavior is non-intuitive, it is a bug or enhancement request. I tried to get the spacing right but as you can imagine this was a bit of lofty goal. It mostly works like I want.

I use fire-ts to generate objective c, and java, and HTML for hopjs. So I do have an interest in getting it right.

Feel free to submit any patches! On Feb 22, 2014 7:18 AM, "Damian Kaczmarek" notifications@github.com wrote:

I find this feature be quite limited

This works:

<% var func = declaration.function; %> <%@ v8_method.fts (func) %>

But this doesn't:

<%@ v8_method.fts (declaration.function) %>

I think it could easily be parsed with PEG.js.

Another thing is I would rather pass the whole context to the template so I would imagine some syntax to do this automatically:

<% with(declaration.function) { %> <%@ v8_method.fts %> <%} %>

Meanwhile, wish you pleasant vacation.

Reply to this email directly or view it on GitHubhttps://github.com/celer/fire-ts/issues/2 .

celer commented 10 years ago

So This one is pretty challenging for me, the way fire-ts is written it doesn't actually parse the Javascript, instead it is some regex trickery, and with out having it parse the Javascript I can't see a way to do this. I'm going to close this along the lines of 'WONTFIX: not until i've implemented a Javascript parser inside of fire-ts"

Rush commented 10 years ago

What you could is simply at peg level allow any text that is braces balanced, something like

not_braces = [^()] / template_argument
template_argument = '(' arg:not_braces* ')' { return '(' + arg.join('') + ')'; }

This way parser should not get confused on whatever javascript code is gonna end up in there