Module: Traptcha::ViewHelpers

Defined in:
lib/traptcha/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#captcha_image_tagObject



5
6
7
8
9
# File 'lib/traptcha/view_helpers.rb', line 5

def captcha_image_tag
  captcha = Traptcha::Captcha.generate

  tag(:img, :src => "data:image/png;base64,#{Base64.encode64(captcha.to_png)}", :id => 'traptcha', :alt => 'captcha') + hidden_field_tag(:secure_hash, captcha.value)
end

#captcha_input_tagObject



15
16
17
# File 'lib/traptcha/view_helpers.rb', line 15

def captcha_input_tag
  text_field_tag :captcha
end

#captcha_label_tagObject



11
12
13
# File 'lib/traptcha/view_helpers.rb', line 11

def captcha_label_tag
  label_tag :captcha
end

#captcha_tagObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/traptcha/view_helpers.rb', line 19

def captcha_tag
  if block_given?
    yield captcha_image_tag, captcha_label_tag, captcha_input_tag
  else
     :ul do
      concat (:li, captcha_label_tag)
      concat (:li, captcha_image_tag)
      concat (:li, captcha_input_tag)
    end
  end
end