Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a pure javascript compiler plugin server-side when running CFGroovy in Coldfusion?
    text
    copied!<p>I'm trying to sell myself to the idea of trying to build enhanced Jquery Mobile markup on the server (running <code>Coldfusion8</code>) and then try to use <a href="http://akdubya.github.com/dustjs/" rel="nofollow">DustJS</a> (Javascript templating engine) to precompile the markup into a js string, which I want to server as a static file. </p> <p>I think I have it down to trying to add the plugin in Coldfusion. Here is what I want to do:</p> <p>Start with a template like this in Coldfusion:</p> <pre><code>&lt;cfsavecontent variable="renderedResults"&gt; &lt;cfoutput&gt; {##person}{root}: {name}, {age}{/person} &lt;/cfoutput&gt; &lt;/cfsavecontent&gt; </code></pre> <p>Running this through the <a href="http://akdubya.github.com/dustjs/" rel="nofollow">DustJS</a> compiler on NodeJS returns something like this:</p> <pre><code> (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; })(); </code></pre> <p>which I then save as <code>someStaticTemplate.js</code>. This file is pulled in on the client and filled with dynmic data.</p> <p>My problem is compiling this in Coldfusion.</p> <p>I'm using <a href="http://www.barneyb.com/barneyblog/projects/cfgroovy2/" rel="nofollow"><code>Cfgroovy</code></a> in order to run Javascript on the server:</p> <pre><code> &lt;cfimport prefix="g" taglib="../../tags/cfgroovy/" /&gt; 35k zipped plugin here &lt;!--- COMPILE ---&gt; var dustedTemplate = dust.compile( variables.tempLateToCompile, variables.templateName); &lt;!--- OUT ---&gt; variables.put("renderedResult", dustedTemplate); &lt;/g:script&gt; </code></pre> <p>However doing it like this returns the following error:</p> <pre><code>type: sun.org.mozilla.javascript.internal.JavaScriptException message: [object Error] (&lt;Unknown Source&gt;#1) </code></pre> <p>So I must be doing something wrong...</p> <p><strong>Question:</strong> </p> <p>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 <a href="http://www.bennadel.com/blog/1767-Running-Javascript-And-jQuery-In-ColdFusion-With-CFGroovy-And-Rhino.htm" rel="nofollow">this</a> post, but I'm already stretching what I can do, so I'm hoping this can work out as I'm trying above.</p> <p>Thanks for some inputs!</p> <p><strong>BOUNTY</strong>:<br> Ok, I give up trying myself. Bounty time... I'm looking for a Coldfusion code snippet that allows me to<br> a) load the DustJS plugin in a CFGrooy tag or alternative javascript enabling setting<br> b) let's me run the DustJS Javascript-compile function to turn my template from </p> <pre><code> {##person}{root}: {name}, {age}{/person} </code></pre> <p>into this:</p> <pre><code> (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; })(); </code></pre> <p>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. </p> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload