Class: SimpleCaptchaInput

Inherits:
Formtastic::Inputs::StringInput
  • Object
show all
Defined in:
lib/simple_captcha_reloaded/adapters/formtastic.rb

Instance Method Summary collapse

Instance Method Details

#captcha_key(captcha) ⇒ Object



29
30
31
# File 'lib/simple_captcha_reloaded/adapters/formtastic.rb', line 29

def captcha_key(captcha)
  builder.hidden_field :captcha_key, value: captcha[:captcha_id]
end

#image_tag(captcha) ⇒ Object



25
26
27
# File 'lib/simple_captcha_reloaded/adapters/formtastic.rb', line 25

def image_tag(captcha)
  template.(:img, nil, src: captcha[:captcha_url], alt: 'Captcha', class: 'simple-captcha-image')
end

#refresh_button(captcha) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/simple_captcha_reloaded/adapters/formtastic.rb', line 33

def refresh_button(captcha)
  template. :div, class: 'simple-captcha-reload' do
    template.link_to captcha[:refresh_url], class: options[:captcha][:refresh_button_class], data: {remote: true} do
      I18n.t('simple_captcha_reloaded.refresh_button_html')
    end
  end
end

#set_options!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/simple_captcha_reloaded/adapters/formtastic.rb', line 14

def set_options!
  default_options = {
    refresh_button: true,
    id: 'simple_captcha_wrapper'
  }
  options[:wrapper_html] ||= {}
  options[:captcha] ||= {}
  options[:captcha].reverse_merge!(default_options)
  options[:wrapper_html][:id] ||= options[:captcha][:id]
end

#to_htmlObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/simple_captcha_reloaded/adapters/formtastic.rb', line 2

def to_html
  set_options!
  captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
  input_wrapping do
    label_html <<
    image_tag(captcha) <<
    captcha_key(captcha) <<
    builder.text_field(method, input_html_options) <<
    refresh_button(captcha)
  end
end