module Erector::Rails::Helpers

Public Class Methods

def_block_rails_helper(method_name) click to toggle source

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.

# File lib/erector/rails2/extensions/rails_helpers.rb, line 91
      def self.def_block_rails_helper(method_name)
        module_eval("          def #{method_name}(*args, &block)
            if block_given?
              parent.#{method_name}(*args, &block)
            else
              rails_helper_output = parent.#{method_name}(*args, &block)
              # i wonder why this is text and not rawtext
              text rails_helper_output
            end
          end
", __FILE__, __LINE__+1)
      end
def_simple_rails_helper(method_name) click to toggle source

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

# File lib/erector/rails2/extensions/rails_helpers.rb, line 13
      def self.def_simple_rails_helper(method_name)
        module_eval("          def #{method_name}(*args, &block)
            # i wonder why this is text and not rawtext
            text parent.#{method_name}(*args, &block)
          end
", __FILE__, __LINE__+1)
      end

Public Instance Methods

fields_for(record_or_name_or_array, *args, &proc) click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 154
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
flash() click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 161
def flash
  parent.controller.send(:flash)
end
form_for(record_or_name_or_array, *args, &proc) click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 147
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
method_missing(name, *args, &block) click to toggle source

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

# File lib/erector/rails2/extensions/rails_helpers.rb, line 125
def method_missing(name, *args, &block)
  if parent.respond_to?(name)
    parent.send(name, *args, &block)
  else
    super
  end
end
render(*args, &block) click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 139
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) click to toggle source

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

# File lib/erector/rails2/extensions/rails_helpers.rb, line 135
def respond_to?(name)
  super || parent.respond_to?(name)
end
session() click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 165
def session
  parent.controller.session
end
url_for(*args) click to toggle source
# File lib/erector/rails2/extensions/rails_helpers.rb, line 7
def url_for(*args)
  parent.url_for(*args)
end