How to define class in and Arbre block?

208 views Asked by At

Sorry if this is a stupid question, but I would like to know how one can go about defining a class in an Arbre block. I tried to simply put the comma after the block, but Ruby accuses it of an error (specifically: "unexpected token tCOMMA (Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops) (error:Lint/Syntax)").

This is how I tried to do it:

div {
    h4 "Title", class: "title"
    span "Info", class: "info"
}, class: "my_div"

this results in the aformentioned error. But I don't really know any other way to go about this. Any help would be much appreciated!

1

There are 1 answers

4
David On BEST ANSWER

Arbre definitions are ruby methods, that has a basic syntax that you have to follow. First comes the positional arguments, then keyword arguments and the last a block. In your example you do it in the other way around, so you pass a block then a keyword argument. To fix this simply change to:

div class: "my_div" {
    h4 "Title", class: "title"
    span "Info", class: "info"
}

Which is equivalent to:

div(class: "my_div") {
    h4("Title", class: "title")
    span("Info", class: "info")
}