如何使用ScriptSharp动态生成JavaScript? [英] How to dynamically generate javascript using ScriptSharp?

查看:65
本文介绍了如何使用ScriptSharp动态生成JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种动态生成JavaScript的方法.通过浏览Script#的文档,我没有找到任何关于此的信息,所以这是我的问题:

1)是否可以在运行时生成JavaScript代码?

2)是否可以动态设置将生成的代码保存到的文件名?还是可以将生成的代码作为字符串获取?

一种情况是:用户访问一个网站,在文本框中输入名称,点击按钮,然后生成一个显示警告的javascript("Hello name "). (可以下载)

我正在使用通过NuGet(0.7.5)获得的版本.

如果可能的话,我将不胜感激.

谢谢!

解决方案

1)是的,可能. script#编译器打包在ScriptSharp.dll中,您可以使用它公开的API.有关这样做的示例,请在script#存储库中查看script#msbuild任务的源.

2)使用API​​时,可以有效地传递流-这样就可以获取生成的内容,可以根据需要使用它.

我建议克隆存储库,并使用"cc"分支选择最新更改. github上的Wiki有构建步骤. 0.7.5现在有点老了.

希望有帮助.

I'm looking for a way to dynamically generate javascript. I didn't find any information on this by browsing through Script#'s documentation, so here are my questions:

1) Is it possible to generate javascript code during runtime?

2) Is it possible to dynamically set a file name to which generated code would be saved to? Or can I get the generated code as a string?

A scenario would be: A user goes to a web site, enters a name in a text box, hits a button and a javascript is generated that would say alert("Hello name"). (which can be offered as a download)

I'm using the version I got through NuGet (0.7.5).

If it is possible, I would appreciate any hints or examples.

Thank you!

解决方案

1) Yes, its possible. The script# compiler is packaged in ScriptSharp.dll and you can use the API it exposes. For an example of doing so, check out the sources of the script# msbuild tasks in the script# repository.

2) When you use the API, you effectively pass in a Stream - so you get the generated content, which you can use as you wish.

I'll recommend cloning the repository and using the "cc" branch to pick up the latest changes. The wiki on github has steps to build. 0.7.5 is a bit old now.

Hope that helps.

这篇关于如何使用ScriptSharp动态生成JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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