【问题标题】:Grunt jade compiler filling out empty attributesGrunt 玉编译器填写空属性
【发布时间】:2014-11-22 02:27:59
【问题描述】:

我正在使用 grunt-contrib-jade 模块来编译我的 Jade 模板,如果我将属性留空,如下行:

article(ui-view)

它将编译为:

<article ui-view="ui-view"></article>

这会破坏我的 AngularJS ui-router,因为它不会像处理命名视图一样处理“ui-view”指令(不是我想要的)。当然也可以这样写我的jade文件:

article(ui-view='')

但这不是我想要的,有什么方法可以阻止jade编译器填写空属性吗?

【问题讨论】:

    标签: gruntjs npm pug


    【解决方案1】:

    doctype html 位于.jade 文件的开头时,一切似乎都很好。

    对于没有doctype的partials,也可以在调用Jade时通过{doctype: 'html'}作为选项来解决:

    jade -O "{doctype:'html'}" partial.jade
    

    通过将doctype: 'html' 添加到选项中,它也适用于grunt-contrib-jade,如下所示:

    jade: {
      devel: {
        options: {
          pretty: true,
          doctype: 'html'
        },
        files: [{
          expand: true,
          cwd: 'src',
          src: [ '**/*.jade' ],
          dest: 'app',
          ext: '.html'
        }]
      }
    }
    

    【讨论】:

    • 你的意思是把{doctype:'html'}放在文件的顶部?
    • @AhmadAlfy 否。将doctype html 放在文件顶部,或将{doctype:'html'} 传递给jade 编译器。
    【解决方案2】:

    在你的玉中使用纯html:&lt;div ui-view&gt;&lt;/div&gt;

    【讨论】:

    • 问题是关于如何处理 Jade 中的空属性,回退到 HTML 是一种选择(解决方法)。它不回答如何做到翡翠。
    猜你喜欢
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多