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
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
# 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
# File lib/erector/rails2/extensions/rails_helpers.rb, line 161 def flash parent.controller.send(:flash) end
# 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
# File lib/erector/rails2/extensions/rails_helpers.rb, line 112 def link_to(*args, &block) if block_given? parent.link_to(*args, &block) else args[0] = CGI.escapeHTML(args[0]) rails_helper_output = parent.link_to(*args, &block) # i wonder why this is text and not rawtext text rails_helper_output end end
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
# 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
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
# File lib/erector/rails2/extensions/rails_helpers.rb, line 165 def session parent.controller.session end
# File lib/erector/rails2/extensions/rails_helpers.rb, line 7 def url_for(*args) parent.url_for(*args) end