是否可以在ColdFusion服务器端将HTML标记编译为模板化JavaScript? [英] Is it possible to compile HTML markup to templatable javascript on Coldfusion server-side?

查看:358
本文介绍了是否可以在ColdFusion服务器端将HTML标记编译为模板化JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找Javascript模板引擎,试图找到一种方式来在/ offline上提供标准模板。

I have been looking at Javascript templating engines trying to find a way to have standard templates available on/offline.

目前我在 dustjs / linkedIn 这需要服务器端预编译模板到 js 文件 - 很难像我使用 Coldfusion8

Currently I'm kind of stuck at dustjs/linkedIn which would require to server-side pre-compile a template into a jsfile - difficult as I'm using Coldfusion8.

在Coldfusion中运行Javascript时存在稀疏链接( example )。所以:

There are sparse links available on running Javascript in Coldfusion (example). So:

问题:

Coldfusion中有一个易于使用的Javascript?我不是在谈论 toScript 我们的< cfoutput>< script> alert(hello)>< / cfoutput> code>,我想在cfscheduled任务中的服务器上运行类似于dustjs编译器的javascript函数来获取HTML模板并从中编译:

Question:
Is there an easy to use Javascript in Coldfusion? I'm not talking about toScript our <cfoutput><script>alert("hello")></cfoutput>, I want to run a javascript function like the dustjs compiler on the server in a cfscheduled task to take HTML templates and compile them from this:

  Hello {name}! You have {count} new messages.

(function() {
    dust.register("demo", body_0);

    function body_0(chk, ctx) {
    return chk.write("Hello ").reference(ctx.get("name"), ctx, "h").write("! You have ").reference(ctx.get("count"), ctx, "h").write(" new messages.");
    }
    return body_0;
})();

这是在dustJS compiler.js 文件(我认为...)。如果不可能,除了创建一个coldfusion编译器,将标记更改为编译的JavaScript之外,还有什么其他选项?

which is done in the dustJS compiler.js file (I think...). If it's not possible, what are other options besides creating a "coldfusion compiler" which changes markup to compiled javascript?

感谢一些困难!

推荐答案

查看 CFGroovy 。虽然针对groovy,它是真正的CF使用通用脚本功能的Java(JSR-223)你应该能够启动Rhino通过这个和运行你的代码。事实上,Ben Nadel有一个

Take a look at CFGroovy. Although targeting groovy, it's really a way for CF to use the generic scripting features of Java (JSR-223) You ought to be able to start Rhino through this and run your code. In fact, Ben Nadel has an article on doing this.

另外,您可以将节点放在服务器上,并使用cfexecute运行节点来编译模板。

Althernatively, you could put node on your server and use cfexecute to run node to compile your templates.

如果你使它工作,我会考虑不按计划编译。也许尝试一下:

If you make it work, I'd consider not compiling on a schedule. Perhaps try one fo the following:


  • 如果你有一个定义的构建过程,编译为构建的一部分。

  • 按需编译,因此您的脚本网址可能是script.cfm?script = whatever.js并具有CF检查日期,并且可以编译模板或

  • 使用DirectoryWatcher事件网关来监视脚本文件夹和更新时编译。

我最喜欢第三个选项,因为它只会在更改时编译,这可能是你想要的。

I like the third option best, as it'll only compile on change, which is probably what you want.

这篇关于是否可以在ColdFusion服务器端将HTML标记编译为模板化JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆