V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
jiyinyiyong
V2EX  ›  分享创造

Cirru HTML: 类似 Jade 的缩进语法来编译生成 HTML

  •  
  •   jiyinyiyong ·
    jiyinyiyong · 2014-03-26 16:55:50 +08:00 · 2979 次点击
    这是一个创建于 3710 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Jade 很强大的, 但是空格处理, 还有属性偏多时的写法让我不舒服,
    刚好自己想尝试写个模版引擎, 就做了一个给自己用, 按 Cirru 的文法写的.

    主要的功能:
    * 缩进语法
    * : 语法简化属性的书写
    * 简化的 @ 语法, 用来处理逻辑和嵌入数据
    * 嵌入文件的功能
    * 做了预编译, 加快模版的执行

    缺少的部分:
    * 没有做命令行版本的编译工具
    * 每次渲染前需要做 cache
    * 详细文档.. 看视频也能了解一些
    * 基于 CommonJS 规范. 没有 requirejs 等版本

    使用 @partial 和 @insert 依赖服务端环境, 其他的浏览器环境也能跑.

    代码的例子: #file-html-cirru

    项目的仓库地址: https://github.com/Cirru/cirru-html

    我在项目里使用的时候会用 ShellJS 脚本这样调用:
    https://github.com/jiyinyiyong/dual-balanced-ternary/blob/master/make.coffee#L14

    cirru-html 和 Vue.js 搭配的效果是这样的:
    https://github.com/jiyinyiyong/todolist/blob/master/cirru/menu.cirru

    另外还有个视频做了一些比较具体的介绍:


    目前非常粗糙, 有想法请在 GitHub 上提 Issue, 欢迎 fork
    第 1 条附言  ·  2014-05-12 15:01:32 +08:00
    后续的更新之后, 方便浏览器端调用,, 不过接口也随之做了修改:
    https://github.com/Cirru/cirru-html
    浏览器端的 Demo:
    http://repo.cirru.org/html/index.html
    4 条回复    2014-05-12 19:22:47 +08:00
    bitbegin
        1
    bitbegin  
       2014-05-12 15:06:01 +08:00 via Android
    沙发
    ivenvd
        2
    ivenvd  
       2014-05-12 15:36:23 +08:00
    还是 Slim 简洁……
    zythum
        3
    zythum  
       2014-05-12 17:38:16 +08:00
    做得不错!
    NemoAlex
        4
    NemoAlex  
       2014-05-12 19:22:47 +08:00
    我觉得这个这么多蚊香也没比 Jade 好啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5115 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 02:41 · PVG 10:41 · LAX 19:41 · JFK 22:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.