如何在ColdFusion中运行CFGroovy时添加纯JavaScript编译器插件服务器端?(H

2019-09-23 14:49发布

我想自己卖的试图建立在服务器上增强jQuery Mobile的标记的想法(运行Coldfusion8 ),然后尝试使用DustJS (使用Javascript模板引擎)来标记预编译成一个js字符串,我想服务器作为一个静态文件。

我想我已经下来到要添加的插件ColdFusion的。 这是我想做的事:

开始用ColdFusion的这样的一个模板:

<cfsavecontent variable="renderedResults">
    <cfoutput>
        {##person}{root}: {name}, {age}{/person}
    </cfoutput> 
</cfsavecontent>

通过运行这个DustJS对编译器的NodeJS返回是这样的:

 (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;
 })();

然后我保存为someStaticTemplate.js 。 该文件被拉到客户端上并填充中对动态数据。

我的问题是ColdFusion的编写本。

我使用Cfgroovy为了在服务器上运行JavaScript:

 <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>

但是做这样返回以下错误:

type: sun.org.mozilla.javascript.internal.JavaScriptException 
message: [object Error] (<Unknown Source>#1)

所以,我必须做一些错误的...

题:

是否有可能在所有到该服务器端编译成JS? 如果是这样,任何想法如何包括该插件。 我也看了这个帖子,但我已经伸展我能做些什么,所以我希望这可以算出来,因为我想以上。

感谢一些投入!

BOUNTY:
好吧,我放弃尝试自己。 赏金时间......我在寻找一个ColdFusion代码片段,让我
一个)加载插件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(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;
 })();

如果在技术上是不可能的,我很开放的替代方法,那让我来创建服务器,这是基于HTML,包括占位符,所以我可以在客户端上添加动态数据的模板。

谢谢!

Answer 1:

你应该看看http://www.bennadel.com/blog/1766-Running-Javascript-In-ColdFusion-With-CFGroovy-And-Rhino.htm

和是否有可能编译HTML标记模板化的ColdFusion服务器端JavaScript?

编码愉快!



文章来源: How to add a pure javascript compiler plugin server-side when running CFGroovy in Coldfusion?