如何在ColdFusion中运行CFGroovy时添加纯JavaScript编译器插件服务器端? [英] How to add a pure javascript compiler plugin server-side when running CFGroovy in Coldfusion?
问题描述
我试图卖自己的想法,尝试在服务器上运行增强的Jquery Mobile标记(运行 Coldfusion8
),然后尝试使用 DustJS (Javascript模板引擎)将标记预编译为js字符串,我想将其作为静态文件来服务。
我想我有这个想要在Coldfusion中添加插件。这里是我想做的:
在Coldfusion中使用这样的模板开始:
< cfsavecontent variable =renderedResults>
< cfoutput>
{## person} {root}:{name},{age} {/ person}
< / cfoutput>
< / cfsavecontent>
通过 DustJS 编译器返回如下:
b $ b 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 age),ctx,h);
}
return body_0;
})();
然后保存为 someStaticTemplate.js
。这个文件在客户端被拉入并填充dynmic数据。
我的问题是在Coldfusion中编译此文件。
我正在使用 Cfgroovy
以便在服务器上运行Javascript:
< cfimport prefix =gtaglib =../。 ./tags/cfgroovy//>
35k zipped plugin here
<!--- COMPILE --->
var dustedTemplate = dust.compile(variables.tempLateToCompile,variables.templateName);
<!--- OUT --->
variables.put(renderedResult,dustedTemplate);
< / g:script>
但是这样做会返回以下错误:
$ b b
type:sun.org.mozilla.javascript.internal.JavaScriptException
message:[object Error](< Unknown Source>#1)
所以我一定做错了...
strong>问题:
是否有可能将这个服务器端编译成JS?如果是这样,任何想法如何包括插件。我还查看了这帖子,但我已经伸展了我能做的,所以我希望这可以工作,因为我在上面尝试。
感谢您的部分输入!
BOUNTY :
转换我的模板
好的,我放弃了自己。赏金时间...我正在寻找一个Coldfusion代码片段,允许我
a)加载DustJS插件在CFGrooy标记或替代javascript启用设置
b)让我跑DustJS Javascript编译函数从
{## person} {root}:{name},{age } {/ person}
:
(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 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;
})
如果这在技术上是不可能的,我可以选择其他方法,模板,它是基于HTML的,包括占位符,因此我可以在客户端上添加动态数据。
谢谢!
解决方案您应该查看 http://www.bennadel.com/blog/1766-Running-Javascript-In-ColdFusion-With-CFGroovy-And- Rhino.htm
和是否可以在ColdFusion服务器端将HTML标记编译为模板化JavaScript?
Happy Coding !!!
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!!!
这篇关于如何在ColdFusion中运行CFGroovy时添加纯JavaScript编译器插件服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!