lib/robot_catcher/helpers.rb in robot_catcher-0.0.6 vs lib/robot_catcher/helpers.rb in robot_catcher-0.1.0

- old
+ new

@@ -1,7 +1,10 @@ module RobotCatcher module Helpers + class SpinnerError < StandardError + end + class FormBuilder < ActionView::Helpers::FormBuilder def initialize(object_name, object, template, options) @spinner = options[:spinner] super(object_name, object, template, options, nil) end @@ -34,14 +37,18 @@ :rc_search_field_tag, :rc_telephone_field_tag, :rc_phone_field_tag, :rc_date_field_tag, :rc_time_field_tag, :rc_datetime_field_tag, :rc_datetime_local_field_tag, :rc_month_field_tag, :rc_week_field_tag, :rc_url_field_tag, :rc_email_field_tag, :rc_number_field_tag] + 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 + def self.create_tagged_field_tag(method_name, parent_method) define_method(method_name) do |label, *args| - hash_tag = Digest::MD5.hexdigest(label.to_s + @spinner + "robotcatcher") - text_field_tag(hash_tag, nil, :style=>"display:none") + - self.send(parent_method, label, *args) + rc_hash_tag(label) + self.send(parent_method, label, *args) end end field_tag_helpers.each do |name| create_tagged_field_tag(name, name.to_s.sub(/rc_/, '').to_sym) \ No newline at end of file