Home > Blockchain >  inline raw html inside haml, right after interpolation
inline raw html inside haml, right after interpolation

Time:05-17

Ultimately I need an url encoded line, to pass it to whatsapp or telegram share feature from web. I need to add a line break <br> after unlinked sequence of data, but what I tried all the time it appears as text element, not html element.

My initial code is

%br
- if unit.square_total.present?
  Total area:
  = cut_zeros(unit.square_total)
  %br
- if unit.square_plot.present?
  Plot area:
  = cut_zeros(unit.square_plot)
  %br
- if unit.square_covered.present?
  Covered:
  = cut_zeros(unit.square_covered)
  %br
- if unit.ceiling_height.present?
  Ceiling height:
  = cut_zeros(unit.ceiling_height)
  %br
- if unit.ceiling_basement_height.present?
  Basement ceiling height:
  = cut_zeros(unit.ceiling_basement_height)
  %br

My current practiced fails

%br
= unit.square_total? ? "Total area: #{cut_zeros(unit.square_total)}" : nil
%br
= unit.square_plot? ? "Plot area: #{cut_zeros(unit.square_plot)}" : nil
%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)} <br>": nil
%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}" : nil
%br# last line

this code releases a lot of <br> which I have to avoid to appear.

so I have to avoid all that %br and to be added of if statement true

so i tried

# series of similar lines above omitted
%br
= unit.square_total? ? "Total area: #{cut_zeros(unit.square_total)} %br": nil
= unit.square_plot? ? "Plot area: #{cut_zeros(unit.square_plot)}"   %br : nil
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)} <br>": nil
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}" : nil # last line

but all the time it's not what i expected

! I'll be more than happy you you could give me an advice how to bring this code (included a series of omitted strings) to percent % encoded (url encoded) finally.

Because now what I'm doing, 1st. create a code. which executes well, but multi-lined 2nd. I join all the lines to single long line and trying to make all statements working inline, so i can simply use something like this sample

But it hearts so....

The result I'm getting originally

link to image

to help you understand the case

CodePudding user response:

Use if statement:

%br
- if unit.square_total?
  = "Total area: #{cut_zeros(unit.square_total)}" 
  %br
- else if unit.square_plot?
  = "Plot area: #{cut_zeros(unit.square_plot)}"
  %br
- ...

EDIT

so, try

%br
= unit.square_covered? ? "Covered: #{cut_zeros(unit.square_covered)}<br>".html_safe: nil
  • Related