woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

使用MyGeneration创建模板

概观

这是一个使用 MyGeneration 开发模板的基本的介绍。如果你安装了 MyGeneration ,并且对 MyGeneration 感到迷惑的话,这里是一个很好的教你使用 MyGeneration 的教程。这个教程将教会你使用 MyGeneration 创建基本的 JScript. VBScript. 的模板。

 

创建模板

打开 MyGeneration
从菜单中选择File->New->JScript. Template或者File->New->VBScript. Template
填充模板属性
你可以通过点击 Property 按钮查看或编辑模板的属性
按照如下的显示填充属性窗体


clip_image002


保存模板

·         选择File->Save As...保存模板

 

输入UI接口代码

 

通过切换到Interface CodeTab页面,可以编辑接口代码。这里的接口代码在运行时,将会生成一个窗体,提示用户输入一个名称,而用户输入的名称将会替换掉“Hello World”中的World

JScript

 

clip_image003//In the interface code segment, the setup function
clip_image003
 //is the initial function call.
clip_image003
 function setup()
clip_image003 {
clip_image003       
//Set the form title bar to say "Hello World!!"
clip_image003
        ui.Title = "Hello World!!";
clip_image003
clip_image003
clip_image003       
//Set the height and width of the form in pixels
clip_image003
        ui.Height = 150;
clip_image003        ui.Width = 340;
clip_image003
clip_image003
clip_image003       
//Add a label and a textbox to the form.
clip_image003
        ui.AddLabel("lblName", "Enter a Name:", "Enter a name belowclip_image004");
clip_image003        ui.AddTextBox("txtName", "World", "Enter a name in hereclip_image004");
clip_image003
clip_image003
clip_image003       
//The number of times to repeat "Hellow World!!"
clip_image003
        input.item("timesToRepeat") = 10;
clip_image003
clip_image003
clip_image003       
//Tells MyGeneration to display the form. If this is
clip_image003
        //set to false. MyGeneration skips displaying the
clip_image003
        //form, but retains any changes made in the interface
clip_image003
        //code segment.
clip_image003
        ui.ShowGUI = true;
clip_image003 }
clip_image003
clip_image003

VBScript

 

clip_image003'In the interface code segment, the setup function
clip_image003
 'is the initial function call.
clip_image003
 Sub setup()
clip_image003       
'Set the form title bar to say "Hello World!!"
clip_image003
        ui.Title = "Hello World!!"
clip_image003
clip_image003
clip_image003       
'Set the height and width of the form in pixels
clip_image003
        ui.Height = 150
clip_image003        ui.Width = 340
clip_image003
clip_image003
clip_image003       
'Add a label and a textbox to the form.
clip_image003
        ui.AddLabel "lblName", "Enter a Name:", "Enter a name belowclip_image004"
clip_image003        ui.AddTextBox "txtName", "World", "Enter a name in hereclip_image004"
clip_image003
clip_image003
clip_image003       
'The number of times to repeat "Hellow World!!"
clip_image003
        input.item("timesToRepeat") = 10
clip_image003       
'Tells MyGeneration to display the form. If this is
clip_image003
        'set to false. MyGeneration skips displaying the
clip_image003
        'form, but retains any changes made in the interface
clip_image003
        'code segment.
clip_image003
        ui.ShowGUI = true
clip_image003 
End Sub
clip_image003
clip_image003

 

测试UI接口

如果你想测试一下前面输入的内容的结果,你就需要执行模板。点击工具栏的Execute按钮(绿色的播放按钮),你将看到如下的结果


clip_image006

输入模板代码

 

通过切换到Template Code Tab页,可以查看和编辑模板代码。如下的代码将生成一个显示10Hello Name!!!HTML页面。

 

JScript

 

clip_image003<html>
clip_image003        <body>
clip_image003 <%
for (var i = 0; i < input.item("timesToRepeat"); i++) { %>
clip_image003                        <br>Hello <%= input.item("txtName") %>!!
clip_image003 <% } %>
clip_image003        </body>
clip_image003 </html>
clip_image003

 

VBScript

 

clip_image003<html>
clip_image003        <body>
clip_image003 <%
For i = 0 to input.item("timesToRepeat") %>
clip_image003                        <br>Hello <%= input.item("txtName") %>!!
clip_image003 <%
Next %>
clip_image003        </body>
clip_image003 </html>

 

执行完成的模板

·         执行模板之前,保存模板

·         点击执行按钮,

  执行后的结果如下: 

 

clip_image003 <html>
clip_image003       
<body>
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003                       
<br>Hello World!!
clip_image003       
</body>
clip_image003 
</html>
clip_image003
clip_image003

 

结束语

 

希望通过这个教程,你看到了 MyGeneration 通过你的指尖在键盘上的敲打而显现的强大的力量。当你开始熟悉 MyGeneration 之后,我建议你做如下的事情:

1.    查看安装 MyGeneration 时附带的模板,我从哪儿学到了很多;

2.    研究 Zeus API文档以及 MyMeta.

3.    思考一下,在你的工作中哪些需要使用 MyGeneration ,发现这些,你将会吃惊的发现,以前很多耗时的工作, MyGeneration 会使它们变得轻而易举。

 

posted on 2010-03-03 13:17 肥仔 阅读(1110) 评论(0)  编辑 收藏 引用 所属分类: 模板引擎


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理