Jade:在多行上声明一个变量

时间:2013-12-06 08:28:16

标签: coding-style pug

我有一个像这样声明的玉变量:

BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM} }

但我希望它更具可读性:

BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}
        , more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}
        , see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}
        , see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}
        , program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}
        , see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM}
    }

但即使我在每行末尾添加反斜杠,此代码也无法编译。有没有解决方法?

2 个答案:

答案 0 :(得分:16)

Jade现在支持多线变量,如in the docs所述:

-
  list = ["Uno", "Dos", "Tres",
          "Cuatro", "Cinco", "Seis"]
each item in list
  li= item

答案 1 :(得分:15)

你的问题让我感到惊讶。我在Jade做了一些测试:

这有效(正如你所说):

person = {name: 'Bill', age: 50}

这也有效:

- person = {name: 'Bill', age: 50}

这没有(Jade无法编译它:

- person = {
-   name: 'Bill',
-   age: 50
- }

这是一个很好的解决方法:

- person = {}
- person.name = 'Bill'
- person.age = 50