Создайте помощника или что-то для haml с рубином на направляющих

Я использую haml со своим приложением направляющих, и у меня есть вопрос как самый легкий способ ввести этот haml код в файл HTML:

<div clas="holder">
 <div class=top"></div>
  <div class="content">
   Content into the div goes here
  </div>
 <div class="bottom"></div>
</div>

И я хочу использовать его в своем haml документе как это:

%html
 %head
 %body
  Maybee some content here.
  %content_box #I want to get the code i wrote inserted here
   Content that goes in the content_box like news or stuff
 %body

Существует ли более легкий способ сделать это?


Я получаю эту ошибку:

**unexpected $end, expecting kEND**

с этим кодом:

# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
 def content_box(&block)
  open :div, :class => "holder" do # haml helper
   open :div, :class => "top"
    open :div, :class => "content" do
      block.call
    open :div, :class => "bottom"
  end
 end
end
23
задан meagar 29 June 2012 в 17:12
поделиться

2 ответа

Вы также можете использовать haml_tag

def content_box
  haml_tag :div, :class => "holder" do
    haml_tag :div, :class => "top"
    haml_tag :div, :class => "content" do
      yield
    haml_tag :div, :class => "bottom"
  end
end

и в haml

%html
  %head
  %body
    Maybee some content here.
    = content_box do
      Content that goes in the content_box like news or stuff
37
ответ дан 29 November 2019 в 02:04
поделиться

Типичное решение - использовать частичное.

Или вспомогательный метод в вашем файле _helper.rb:

def content_box(&block)
  open :div, :class => "holder" do # haml helper
    open :div, :class => "top"
    open :div, :class => "content" do
      block.call
    end
    open :div, :class => "bottom"
  end
end

И в haml:

%html
  %head
  %body
    Maybee some content here.
    = content_box do
      Content that goes in the content_box like news or stuff
3
ответ дан 29 November 2019 в 02:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: