Module: Htmless::Helper

Included in:
Rails::AbstractBuilder
Defined in:
lib/htmless/helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) builder(method_name) {|self| ... }

adds instance method to the class. Method accepts any instance of builder and returns it after rendering.

Examples:

class User
# ...
  include HammerBuilder::Helper

  builder :menu do |user|
    li user.name
  end
end

User.new.menu(HammerBuilder::Standard.get).to_html! #=> "<li>Name</li>"

Parameters:

  • method_name (Symbol)

Yields:

  • (self)

    builder_block is evaluated inside builder and accepts instance of a rendered object as parameter



18
19
20
21
22
# File 'lib/htmless/helper.rb', line 18

def builder(method_name, &builder_block)
  define_method(method_name) do |builder, *args|
    builder.dive(self, *args, &builder_block)
  end
end