module RobotCatcher::Helpers::FormTagHelper

Public Class Methods

create_tagged_field_tag(method_name, parent_method) click to toggle source
# File lib/robot_catcher/helpers.rb, line 48
def self.create_tagged_field_tag(method_name, parent_method)
  define_method(method_name) do |label, *args|
    rc_hash_tag(label) + self.send(parent_method, label, *args)
  end
end

Public Instance Methods

rc_form_tag(url_for_options = {}, options = {}, &block) click to toggle source

(field_tag_helpers - [:check_box_tag, :radio_button_tag, :hidden_field_tag, :file_field_tag]).each do |selector|

class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
  def #{selector}(method, options = {})  # def text_field_tag(method, options = {})
    self.send(                           #   self.send(
      #{selector.inspect},               #     "text_field_tag",
      method)                            #     method)
  end                                    # end
RUBY_EVAL

end

# File lib/robot_catcher/helpers.rb, line 68
def rc_form_tag(url_for_options = {}, options = {}, &block)
  if !options.has_key? :ip
    raise ArgumentError, "should include ip address"
  end
  ip = options.delete(:ip)

  timestamp = Time.now.to_i.to_s
  # p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
  @spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")

  options[:spinner] = @spinner

  html_options = options[:html] ||= {}

  html_options[:data]   = options.delete(:data)   if options.has_key?(:data)
  html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
  html_options[:method] = options.delete(:method) if options.has_key?(:method)
  html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
  html_options[:authenticity_token] = options.delete(:authenticity_token)

  builder = RobotCatcher::Helpers::FormBuilder.new(nil, nil, self, options)
  content = capture(builder, &block)
  html_options[:multipart] ||= builder.multipart?

  html_options = html_options_for_form(url_for_options, html_options)
  
  if block_given?
    output = form_tag_html(html_options)
    output.safe_concat(hidden_field_tag(:timestamp, timestamp))
    output.safe_concat(hidden_field_tag(:spinner, @spinner))
    output << content
    output.safe_concat("</form>")
  else
    output = form_tag_html(html_options)
    output.safe_concat(hidden_field_tag(:timestamp, timestamp))
    output.safe_concat(hidden_field_tag(:spinner, @spinner))
  end
end
rc_hash_tag(label) click to toggle source
# File lib/robot_catcher/helpers.rb, line 42
def rc_hash_tag(label)
  raise(SpinnerError.new, "Form has not been initialized properly! (use rc_form_tag)") if @spinner.nil? 
  hash_tag = Digest::MD5.hexdigest(label.to_s + @spinner + "robotcatcher")
  text_field_tag(hash_tag, nil, :style=>"display:none")
end