zoukankan      html  css  js  c++  java
  • 介绍Asta4D

    介绍Asta4D

    友好的开发框架-Asta4D(4)

    开始介绍Asta4D的主要特点和功能。 

    1. 可继承的模板与参数化嵌入 
     模板文件是可继承的,同时,子模板文件允许对父模板的指定位置进行覆盖,追加,插入操作。 

    parent.html 

    复制代码
    <html> 
        <head> 
            <afd:block id="block1"> 
                <link href="parent1.css" rel="stylesheet" type="text/css" /> 
            </afd:block> 
             
            <afd:block id="block2"> 
                <link href="parent2.css" rel="stylesheet" type="text/css" /> 
            </afd:block> 
    
            <title>extension sample</title> 
        </head> 
        <body> 
            <afd:block id="content">content</afd:block> 
        </body> 
    </html> 
    复制代码

    child.html 

    复制代码
    <html> 
    <head></head> 
    <body> 
    <!-- (1) --> 
    <afd:extension parent="parent.html"> 
    
        <!-- (2) --> 
        <afd:block append="block1"> 
            <link href="child1.css" rel="stylesheet" type="text/css" /> 
        </afd:block> 
    
        <!-- (3) --> 
        <afd:block insert="block2"> 
            <link href="child2.css" rel="stylesheet" type="text/css" /> 
        </afd:block> 
    
        <!-- (4) --> 
        <afd:block override="content "> 
            <div>hello</div> 
            <!-- (5) --> 
            <afd:embed target="/templates/embed.html" ></afd:embed> 
        </afd:block> 
    
    </afd:extension> 
    </body> 
    </html> 
    复制代码

    embed.html 

    复制代码
    <html> 
    <head></head> 
    <body> 
        <!-- (6) --> 
        <afd:block append="block1"> 
            <link href="embed.css" rel="stylesheet" type="text/css" /> 
        </afd:block> 
        <div>good embed</div> 
    </body> 
    </html> 
    复制代码

    上述示例中,child模板通过extension标记声明继承关系(1),同时,通过简单的block声明,对父模板的指定block进行追加,插入和覆盖操作(2,3,4)。另外,子模板中通过embed标记声明了直接导入外部模板文件(5),更进一步的,在被导入的外部模板文件中,也同样可以声明对已有的block的操作(6),这对于模板文件中header的合并非常有用。上面的例子会由Asta4D的模板引擎合并成下面的内容输出: 

    复制代码
    <html> 
    <head> 
         
        <!—block1 --> 
        <link href="parent1.css" rel="stylesheet" type="text/css" /> 
        <link href="child1.css" rel="stylesheet" type="text/css" /> 
        <link href="embed.css" rel="stylesheet" type="text/css" /> 
    
        <!—block2 --> 
        <link href="child2.css" rel="stylesheet" type="text/css" /> 
        <link href="parent2.css" rel="stylesheet" type="text/css" /> 
    
        <title>extension sample</title> 
    
    </head> 
    <body> 
    
        <!—content --> 
        <div>hello</div> 
    
        <!—embed --> 
        <div>good embed</div> 
    
    </body> 
    </html> 
    复制代码

    在通过embed标记导入外部模板文件时,可以通过指定DOM属性的方式向外部模板文件传入参数: 

    <afd:embed target="/xxx/showList.html" showLimit="30"></afd:embed> 

    上述例子中指定的showLimit参数在外部模板文件showList.html的渲染逻辑中可以通过参数注入访问,从而实现参数化渲染逻辑。这个特性对于定义页面组件非常有用,将通用的HTML片段封装起来通过embed引入,同时通过参数传递来控制行为,基本上来说,在模板中引用一个embed文件,类似于一次可传参的函数调用。特别需要指出的是,这里的参数并不限于在模板文件中静态指定,在运行时同样可以动态指定embed参数,而且,参数类型也不仅限于可字符串化的字符或者数值类型,在运行时动态指定的embed参数可以是任意Java类型。更详细的关于参数化嵌入的说明,可以参考后述的渲染逻辑的部分。 

    简单的讲,Asta4D的模板思想类似于传统的OOP模式,可以将父子模板视同为父子类的关系,而block则可以被视作可覆盖的虚方法。至于embed的外部文件,可以视同函数调用,记住,既然你可以向embed的文件传递任意类型的参数,因此它事实上和函数调用的确没有什么区别。

    当前标签: asta4d

     
    友好的开发框架-Asta4D(3) xzer 2013-03-24 16:32 阅读:48 评论:0  
     
    友好的开发框架-Asta4D(2) xzer 2013-03-24 16:31 阅读:66 评论:0  
     
    友好的开发框架-Asta4D(1) xzer 2013-03-15 19:14 阅读:98 评论:0
  • 相关阅读:
    [转帖]Mootools源码分析03 Hash
    iphone的手势与触摸编程学习笔记
    怎样使项目中的cocos2d默认模板支持ARC内存管理
    xCode4.2下添加TableViewController会出现”Prototype cells“警告
    关于31天App教程示例中一些因SDK版本而出现的问题
    带你掌握二进制SCA检测工具的短板及应对措施
    HDZ城市行深圳站|AIoT时代,如何抓住智联生活的战略机会点?
    分析内部运行机制,教你解决Redis性能问题
    今天谈谈用户故事地图,不是用户故事
    云图说|ModelArts Pro:让AI开发更简单
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2998794.html
Copyright © 2011-2022 走看看