Module: Erector::Rails::Helpers

Includes:
ActionController::UrlWriter
Defined in:
lib/erector/rails/extensions/rails_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Delegate to non-markup producing helpers via method_missing, returning their result directly.



112
113
114
115
116
117
118
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 112

def method_missing(name, *args, &block)
  if parent.respond_to?(name)
    parent.send(name, *args, &block)
  else
    super
  end
end

Class Method Details

.def_block_rails_helper(method_name) ⇒ Object

Wrappers for rails helpers that produce markup, concatenating directly to the output buffer if given a block, returning a string otherwise. In the latter case, Erector needs to manually output their result.



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 90

def self.def_block_rails_helper(method_name)
  module_eval(<<-METHOD_DEF, __FILE__, __LINE__+1)
    def #{method_name}(*args, &block)
      if block_given?
        parent.#{method_name}(*args, &block)
      else
        text parent.#{method_name}(*args, &block)
      end
    end
  METHOD_DEF
end

.def_simple_rails_helper(method_name) ⇒ Object

Wrappers for rails helpers that produce markup. Erector needs to manually emit their result.



13
14
15
16
17
18
19
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 13

def self.def_simple_rails_helper(method_name)
  module_eval(<<-METHOD_DEF, __FILE__, __LINE__+1)
    def #{method_name}(*args, &block)
      text parent.#{method_name}(*args, &block)
    end
  METHOD_DEF
end

Instance Method Details

#fields_for(record_or_name_or_array, *args, &proc) ⇒ Object



141
142
143
144
145
146
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 141

def fields_for(record_or_name_or_array, *args, &proc)
  options = args.extract_options!
  options[:builder] ||= ::Erector::RailsFormBuilder
  args.push(options)
  parent.fields_for(record_or_name_or_array, *args, &proc)
end

#flashObject



148
149
150
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 148

def flash
  parent.controller.send(:flash)
end

#form_for(record_or_name_or_array, *args, &proc) ⇒ Object



134
135
136
137
138
139
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 134

def form_for(record_or_name_or_array, *args, &proc)
  options = args.extract_options!
  options[:builder] ||= ::Erector::RailsFormBuilder
  args.push(options)
  parent.form_for(record_or_name_or_array, *args, &proc)
end

#render(*args, &block) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 126

def render(*args, &block)
  captured = parent.capture do
    parent.concat(parent.render(*args, &block))
    parent.output_buffer.to_s
  end
  rawtext(captured)
end

#respond_to?(name) ⇒ Boolean

Since we delegate method_missing to parent, we need to delegate respond_to? as well.

Returns:

  • (Boolean)


122
123
124
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 122

def respond_to?(name)
  super || parent.respond_to?(name)
end

#sessionObject



152
153
154
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 152

def session
  parent.controller.session
end

#url_for(*args) ⇒ Object



7
8
9
# File 'lib/erector/rails/extensions/rails_helpers.rb', line 7

def url_for(*args)
  parent.url_for(*args)
end