Haml syntax: split a line to a couple of rows

后端 未结 5 1331
慢半拍i
慢半拍i 2021-01-03 20:15

I use HAML in my rails project for my html templates. I would like to figure out if its possible to divide a very long line and make it a couple of rows:

%a.         


        
5条回答
  •  失恋的感觉
    2021-01-03 21:00

    Sometimes Multiline in HAML can have little to nothing to do with adding rails code, since some elements need to have lots of attributes, such as the Bootstrap Progress Bar, and simply look hideous on one line.

    This was giving me a headache:

    .progress
      .progress-bar.progress-bar-striped.progress-bar-success{ |
                      role: "progressbar",                     |
                      aria: {                                  |
                        valuenow: "#{@percent}",               |
                        valuemin: "0",                         |
                        valuemax: "100",                       |
                      },                                       |
                      style: "width: #{@percent}%;" }          |
        = "#{@percent}%"
    

    And here was the solution to my struggle:

    .progress
      .progress-bar { class: "progress-bar-striped progress-bar-success",
                      role: "progressbar",
                      aria: { valuenow: "#{@percent}",
                              valuemin: "0",
                              valuemax: "100", 
                      },
                      style: "width: #{@percent}%;" }
        = "#{@percent}%"
    

    Please note that even without the pipebar lines, so long as the preceding line ended in a comma, and no line ended with an open bracket,

提交回复
热议问题