'Symmetrically clean expanded (one-item-per-line) arrays in HAML?

I'm trying to figure out if there's some way to make the following code both visually "clean" and also easily sortable so each line with an array item has one array item and only one array item (plus the comma).

- conditions = [feature_on,
  job_has_started,
  user_can_request,
  no_current_request,
  job_reappointable,
  stopping_soon,]

If I want to reorder the conditions (which represent lambdas used to determine whether a form is shown or not) to put the fastest conditions to compute first (or alternately putting the conditions that are most often false) I can't necessarily simply reorder the conditions. I have to also muck about with the opening and closing brackets and other things. This is not my idea of elegance. I would like something much closer to this:

- conditions = [
  feature_on,
  job_has_started,
  user_can_request,
  no_current_request,
  job_reappointable,
  stopping_soon,
  ]

But I have not found any way to get HAML to allow this. \ at the end of the first line does not solve the problem. Neither does HAML's own '|', which is used similarly in other situations in HAML. I'm not 100% sure whether it is possible. But I'm sure there are others who have tried to achieve similar ends with HAML. How can I do it?

If it's not currently possible with out-of-the-box HAML, how hard would it be to patch HAML to allow this?



Solution 1:[1]

Use a :ruby filter https://haml.info/docs/yardoc/file.REFERENCE.html#ruby-filter.

:ruby
  conditions = [
    feature_on,
    user_can_request,
    job_has_started,
    no_current_request,
    job_reappointable,
    stopping_soon,
  ]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex