Jade: declare a variable over multiple lines

2019-04-19 19:36发布

I have a jade variable declared like this:

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} }

but I would like it to be more readable like this:

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}
    }

but this code doesn't compile even if I add backslashes at the end of each line. Are there any workarounds?

2条回答
Root(大扎)
2楼-- · 2019-04-19 20:15

Jade now supports multineline variables, as described in the docs:

-
  list = ["Uno", "Dos", "Tres",
          "Cuatro", "Cinco", "Seis"]
each item in list
  li= item
查看更多
叛逆
3楼-- · 2019-04-19 20:30

Your question surprised me. I have made some tests in Jade:

This worked (as you said):

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

This worked too:

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

This did not (Jade could not compile it:

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

This is a good workaround:

- person = {}
- person.name = 'Bill'
- person.age = 50
查看更多
登录 后发表回答