I'm trying to sell myself to the idea of trying to build enhanced Jquery Mobile markup on the server (running Coldfusion8
) and then try to use DustJS (Javascript templating engine) to precompile the markup into a js string, which I want to server as a static file.
I think I have it down to trying to add the plugin in Coldfusion. Here is what I want to do:
Start with a template like this in Coldfusion:
<cfsavecontent variable="renderedResults">
<cfoutput>
{##person}{root}: {name}, {age}{/person}
</cfoutput>
</cfsavecontent>
Running this through the DustJS compiler on NodeJS returns something like this:
(function() {
dust.register("demo", body_0);
function body_0(chk, ctx) {
return chk.section(ctx.get("person"), ctx, {
"block": body_1
}, null);
}
function body_1(chk, ctx) {
return chk.reference(ctx.get("root"), ctx, "h").write(": ").reference(ctx.get("name"), ctx, "h").write(", ").reference(ctx.get("age"), ctx, "h");
}
return body_0;
})();
which I then save as someStaticTemplate.js
. This file is pulled in on the client and filled with dynmic data.
My problem is compiling this in Coldfusion.
I'm using Cfgroovy
in order to run Javascript on the server:
<cfimport prefix="g" taglib="../../tags/cfgroovy/" />
35k zipped plugin here
<!--- COMPILE --->
var dustedTemplate = dust.compile( variables.tempLateToCompile, variables.templateName);
<!--- OUT --->
variables.put("renderedResult", dustedTemplate);
</g:script>
However doing it like this returns the following error:
type: sun.org.mozilla.javascript.internal.JavaScriptException
message: [object Error] (<Unknown Source>#1)
So I must be doing something wrong...
Question:
Is it possible at all to compile this server-side into JS? If so, any idea how to include the plugin. I have also looked at this post, but I'm already stretching what I can do, so I'm hoping this can work out as I'm trying above.
Thanks for some inputs!
BOUNTY:
Ok, I give up trying myself. Bounty time... I'm looking for a Coldfusion code snippet that allows me to
a) load the DustJS plugin in a CFGrooy tag or alternative javascript enabling setting
b) let's me run the DustJS Javascript-compile function to turn my template from
{##person}{root}: {name}, {age}{/person}
into this:
(function() {
dust.register("demo", body_0);
function body_0(chk, ctx) {
return chk.section(ctx.get("person"), ctx, {
"block": body_1
}, null);
}
function body_1(chk, ctx) {
return chk.reference(ctx.get("root"), ctx, "h").write(": ").reference(ctx.get("name"), ctx, "h").write(", ").reference(ctx.get("age"), ctx, "h");
}
return body_0;
})();
If that is not possible technically, I'm open for alternative approaches, that allow me to create a template on the server, which is HTML based and includes placeholder so I can add dynamic data on the client.
Thanks!
You should look at http://www.bennadel.com/blog/1766-Running-Javascript-In-ColdFusion-With-CFGroovy-And-Rhino.htm
and Is it possible to compile HTML markup to templatable javascript on Coldfusion server-side?
Happy Coding!!!