Module: Tagfiles::Tagfile

Defined in:
lib/tagfiles/tagfile.rb

Overview

Tagfile implementation

Instance Method Summary collapse

Instance Method Details

#tagfile(name, locals = {}, &block) ⇒ Object Also known as: tf

Renders a layout when called with a block or partial otherwise.

Following partial lookups will be performed:

  • app/views/admin/page/tagfiles/_box.html.erb

  • app/views/admin/tagfiles/_box.html.erb

  • app/views/tagfiles/_box.html.erb

Examples:

app/views/admin/page/index.html.erb:

  <%= tagfile :box, title: 23 do %>
    Box content
  <% end %>

app/views/tagfiles/_box.html.erb

  <div class="box">
    <h2><%= title %></h2>
    <p><%= yield %></p>
  </div>

Parameters:

  • name (String)

    name of the used tagfile

  • locals (Hash) (defaults to: {})

    optional locals passed to the tagfile



28
29
30
31
32
33
34
35
36
# File 'lib/tagfiles/tagfile.rb', line 28

def tagfile(name, locals = {}, &block)
  prefix = lookup_tagfile_prefix(controller.controller_path || "", name)

  if block
    render layout: "#{prefix}/#{name}", locals: locals, &block
  else
    render partial: "#{prefix}/#{name}", locals: locals
  end
end