I have the following haml:
9 %strong Asked by:
10 = link_to @user.full_name, user_path(@user)
11 .small= "(#{@question.created_at.strftime("%B %d, %Y")})"
This currently puts the link and the date on separate lines, when it should look like “link (date)” and date has a class span of small…..
Your code will generate something like this html:
When you use something like
.small(i.e. use the dot without specifying the element type) haml creates an implicitdiv. Sincedivelements are by default block level elements the date will be in a new block and so will appear on a new line. In order to get it to appear on the same line, you’ll need an inline level element.You could change the css for the “small” class to explicitly make it display inline, but html already provides an inline version of the
div– thespan, so you can change the last line fromto
which will give you
which are all inline elements, so will appear as one line.
As for having it all on the same line in the haml, I don’t think that’s possible with plain haml syntax. Haml uses the indentation and whitespace in order to determine what to do, and having just one line means there’s no indentation.
The haml FAQ says:
You seem to be at the edge of what haml is intended for. You could write your html directly if you really wanted it all on one line:
or perhaps you could create a helper that will generate the block for you.