Haml: Control whitespace around text

前端 未结 13 2160
时光说笑
时光说笑 2020-11-30 16:38

In my Rails template, I\'d like to accomplish final HTML to this effect using HAML:

I will first link somewhere         


        
13条回答
  •  醉话见心
    2020-11-30 17:37

    A better way to do this has been introduced via Haml's helpers:

    surround

    = surround '(', ')' do
      %a{:href => "food"} chicken
    
    Produces:
    (chicken)
    

    succeed:

    click
    = succeed '.' do
      %a{:href=>"thing"} here
    
    Produces:
    click
    here.
    

    precede:

    = precede '*' do
      %span.small Not really
    
    Produces:
    *Not really
    

    To answer the original question:

    I will first
    = succeed ',' do
      = link_to 'link somewhere', 'http://example.com'
    - if @condition
      then render this half of the sentence if a condition is met
    
    Produces:
    I will first
    link somewhere,
    then render this half of the sentence if a condition is met
    

提交回复
热议问题