Module: Card::Set::All::Recaptcha::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb,
card/tmpsets/set/mod035-card-mod-recaptcha/all/recaptcha.rb

Instance Method Summary collapse

Instance Method Details

#card_form_html_opts(action, opts = {}) ⇒ Object



100
101
102
103
104
# File 'card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb', line 100

def card_form_html_opts action, opts={}
  super
  opts["data-recaptcha"] ||= "on" if recaptcha?(opts)
  opts
end

#hidden_form_tags(action, opts) ⇒ Object



94
95
96
97
98
# File 'card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb', line 94

def hidden_form_tags action, opts
  return super unless recaptcha?(opts)

  super + recaptcha_token(action)
end

#recaptcha?(opts) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb', line 106

def recaptcha? opts
  card.recaptcha_on? && opts[:recaptcha] != :off
end

#recaptcha_script_urlObject



90
91
92
# File 'card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb', line 90

def recaptcha_script_url
  "https://www.google.com/recaptcha/api.js?render=#{Card.config.recaptcha_site_key}"
end

#recaptcha_token(action) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'card/tmpsets/set/mod034-card-mod-recaptcha/all/recaptcha.rb', line 80

def recaptcha_token action
  output [
    javascript_include_tag(recaptcha_script_url),
    hidden_field_tag("recaptcha_token", "",
                     "data-site-key": Card.config.recaptcha_site_key,
                     "data-action": action,
                     class: "_recaptcha-token")
  ]
end