Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a simple dot "." in HAML?

Tags:

In my Ruby on Rails Project I use HAML, I need to translate something like this

<div>foo <a>bar</a>.<div> 

into HAML. It should look like:

.divclass   foo   %a bar   .      

The period at start is not working because its used by HAML. So how can I use a period as content?

Even with building a span around its not working, again the period is taken as something special.

I think there is an escape mechanism but I can't find it.

like image 694
Calmon Avatar asked Sep 20 '12 12:09

Calmon


People also ask

How do I write code in HAML?

In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.

What is HAML code?

Haml (HTML Abstraction Markup Language) is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives the flexibility to have some dynamic content in HTML.


2 Answers

It is escaped with \

like this

\. 

See Escaping \ in the HAML reference.

Update: Using HAML's succeed (as in this answer) is a better solution if you need a dot in the end of the sentence (to prevent unnecessary white space).

like image 52
khustochka Avatar answered Sep 21 '22 15:09

khustochka


A better method:

%p   This sentence ends with a link which is *just* before a period   = succeed "." do     %a{:href => "#"} link   But the period wasn't included with the link and there was no space before the period. 
like image 23
Jay Avatar answered Sep 17 '22 15:09

Jay