Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade: declare a variable over multiple lines

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?

like image 672
netimen Avatar asked Dec 06 '13 08:12

netimen


People also ask

How do you declare multiple variables in a single line?

You can declare multiple variables in a single line. However, there are more efficient ways to define numerous variables in JavaScript. First, define the variables’ names and values separated by commas using just one variable keyword from var, let, or const.

How to declare multiple variables in JavaScript?

You can declare multiple variables in a single line. However, there are more efficient ways to define numerous variables in JavaScript. First, define the variables’ names and values separated by commas using just one variable keyword from var, let, or const. Click on the following link to see the working of the code segment.

How do I declare a string over multiple lines in jQuery?

Someone asked me the other day how to declare a string over multiple lines in jQuery. It’s actually plain JavaScript and can be done by simply adding the escape character backslash “” after each line. As you can see we simply add the backslash to the end of each line to tell the interpreter it’s part of the same long string.

How to declare and initialize variables in JavaScript?

The most common technique of declaring and initializing JavaScript variables is to write each variable on its line, as in: Click on the following link to see the working of the code segment. You can declare multiple variables in a single line.


1 Answers

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

-
  list = ["Uno", "Dos", "Tres",
          "Cuatro", "Cinco", "Seis"]
each item in list
  li= item
like image 192
gsingh2011 Avatar answered Sep 17 '22 15:09

gsingh2011