Class: Markaby::Rails::RailsBuilder::FormHelperProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/markaby/rails/rails_builder.rb

Overview

This is used for the block variable given to form_for. Typically, an erb template looks as so:

<% form_for :foo do |f|
  <%= f.text_field :bar %>
<% end %>

form_for adds the form tag to the input stream, and assumes that later the user will append the <input> tag to the input stream himself (in erb, this is done with the <%= %> tags).

We could do the following in Markaby:

form_for :foo do |f|
  text f.text_field(:bar)
end

But this is ugly. This is prettier:

form_for :foo do |f|
  f.text_field :bar
end

Instance Method Summary collapse

Constructor Details

#initialize(builder, proxied_object) ⇒ FormHelperProxy

Returns a new instance of FormHelperProxy.



31
32
33
34
# File 'lib/markaby/rails/rails_builder.rb', line 31

def initialize(builder, proxied_object)
  @builder = builder
  @proxied_object = proxied_object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object (private)



42
43
44
45
46
# File 'lib/markaby/rails/rails_builder.rb', line 42

def method_missing(sym, *args, &block)
  result = @proxied_object.__send__(sym, *args, &block)
  @builder.text(result) if result.is_a?(String)
  result
end

Instance Method Details

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/markaby/rails/rails_builder.rb', line 36

def respond_to?(sym, include_private = false)
  @proxied_object.respond_to?(sym, include_private) || super
end