Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to give whitespace in ruby slim

I want to seperate currency and total with whitespace.

Please suggest me a solution Any help would be appreciated.

p
strong Total:
span
    = @order.currency
    = humanized_money_with_symbol @order.total_paisas/100
like image 341
SreRoR Avatar asked Nov 23 '15 07:11

SreRoR


People also ask

Does Ruby care about whitespace?

Whitespace might be (mostly) irrelevant to the Ruby interpreter, but its proper use is the key to writing easily readable code.

What is Slim in ruby?

Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.

What is Slim css?

Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.

What is a slim file?

Definition of slim file : a file very narrow in proportion to its length.


4 Answers

You can also use Slim output => or =<

https://github.com/slim-template/slim#output-

Use trailing space on the first output

p
strong Total:
span
    => @order.currency
    = humanized_money_with_symbol @order.total_paisas/100

or use leading space on the second output

p
strong Total:
span
    = @order.currency
    =< humanized_money_with_symbol @order.total_paisas/100
like image 121
Zzz Avatar answered Nov 08 '22 15:11

Zzz


You can solve this with string interpolation, by doing something like this:

p
strong Total:
span
    = "#{@order.currency} #{humanized_money_with_symbol @order.total_paisas/100}"

Or with a non-breaking space (nbsp) like this:

p
strong Total:
span
    = @order.currency
    | &nbsp;
    = humanized_money_with_symbol @order.total_paisas/100
like image 36
Bryan Oemar Avatar answered Nov 08 '22 16:11

Bryan Oemar


Another option:

p
strong Total:
span
  = [@order.currency, humanized_money_with_symbol @order.total_paisas/100].join(' ')
like image 24
jeffdill2 Avatar answered Nov 08 '22 17:11

jeffdill2


There is special syntax for verbatim text with trailing space, and that syntax is just a single quotation mark:

= @user.first_name
'
= @user.last_name

| &nbsp;, join(' ') and string interpolation are nothing but workarounds.

like image 43
Nick Roz Avatar answered Nov 08 '22 15:11

Nick Roz