[Greasemonkey] Long literal strings of html

Julien Couvreur julien.couvreur at gmail.com
Sat Apr 16 17:27:35 EDT 2005


On 4/16/05, Jeremy Dunck <jdunck at gmail.com> wrote:
> This might be helpful:
> http://trimpath.com/project/wiki/JavaScriptTemplates
> http://trimpath.com/project/wiki/JavaScriptTemplateRunsIn

Nice.

I'm not saying that the template functionality needs to be in GM. I
think it would be small enough that it can be included in the scripts
that want it.

The templating framework that you linked is more sophisticated
(syntax- and parsing- wise) than what I was thinking of ;-)

I was thinking of simply breaking down the template based on <@, @>
and <@= tags. The pieces that are outside of these tags (the literal
html) would be converted to a output.write(<the literal html,
encoded>). The pieces inside these tags (the javascript) would be left
as is.

The following template:
<ul>
<@ for(var i in list) { @>
<li><@= i.text @></li>
<@ } @>
</ul>

would be converted to the following javascript string (to be evaluated
in a context where "list" and "output" are defined):
'output.write("<ul>");
for(var i in list) {
  output.write("<li>");
  output.write(i.text);
  output.write("</li>");
}
output.write("</ul>");'

Cheers,
Julien


More information about the Greasemonkey mailing list