Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a clean way to display a hyphen with haml

Tags:

haml

I have this partial that renders a line containing three peaces of data contained in a span, and between the spans there is a hyphen. Since the hyphen is a haml keyword (or whatever you call that) you can't just put it between the spans, or haml would go looking for a function or variable. So I've got this

%p
  %span{ :class => 'client'}= "#{ won_or_lost['object']['deal']['client'] }"
  = "-"
  %span{ :class => 'value'}= "#{ won_or_lost['object']['deal']['value'] }"
  = "- Thanks to"
  %span{ :class => 'owner'}= "#{ won_or_lost['object']['deal']['owner'] }

You probably agree with me that

= "-"

is rather ugly. It's not a real problem, but is there a clean way to do this?

like image 917
Jasper Kennis Avatar asked Jan 20 '11 10:01

Jasper Kennis


2 Answers

%p
  %span.client= won_or_lost['object']['deal']['client']
  \-
  %span.value= won_or_lost['object']['deal']['value']
  \- Thanks to
  %span.owner= won_or_lost['object']['deal']['owner']

http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#escaping_

like image 163
Heikki Avatar answered Oct 01 '22 09:10

Heikki


I sometimes prefer to use an Em-dash, which I think looks better typographically:

%p
  %span.client= won_or_lost['object']['deal']['client']
  — 
  %span.value= won_or_lost['object']['deal']['value']
  — Thanks to
  %span.owner= won_or_lost['object']['deal']['owner']
like image 27
Ryenski Avatar answered Oct 01 '22 10:10

Ryenski