Module: Turnstile::Helpers
- Defined in:
- lib/turnstile/helpers.rb
Constant Summary collapse
- DEFAULT_ERRORS =
{ turnstile_unreachable: 'Oops, we failed to validate your Turnstile response. Please try again.', verification_failed: 'Turnstile verification failed, please try again.' }.freeze
Class Method Summary collapse
- .invisible_turnstile_tags(custom) ⇒ Object
- .to_error_message(key) ⇒ Object
- .to_message(_key, default) ⇒ Object
- .turnstile_tags(options) ⇒ Object
Class Method Details
.invisible_turnstile_tags(custom) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/turnstile/helpers.rb', line 36 def self.(custom) = { callback: 'javascriptCallback', ui: :button }.merge(custom) text = .delete(:text) html, tag_attributes = components(.dup) html << default_callback() if default_callback_required?() case [:ui] when :button html << %(<button type="submit" #{tag_attributes}>#{text}</button>\n) when :input html << %(<input type="submit" #{tag_attributes} value="#{text}"/>\n) else raise(TurnstileError, "Turnstile ui `#{[:ui]}` is not valid.") end html.respond_to?(:html_safe) ? html.html_safe : html end |
.to_error_message(key) ⇒ Object
10 11 12 13 |
# File 'lib/turnstile/helpers.rb', line 10 def self.(key) default = DEFAULT_ERRORS.fetch(key) { raise ArgumentError "Unknown Turnstile captcha error - #{key}" } ("turnstile.errors.#{key}", default) end |
.to_message(_key, default) ⇒ Object
16 17 18 |
# File 'lib/turnstile/helpers.rb', line 16 def self.(key, default) I18n.translate(key, default: default) end |
.turnstile_tags(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/turnstile/helpers.rb', line 25 def self.() if .key?(:ssl) raise(TurnstileError, "SSL is now always true. Please remove 'ssl' from your calls to turnstile_tags.") end html, tag_attributes = components(.dup) html << %(<div #{tag_attributes}></div>\n) html.respond_to?(:html_safe) ? html.html_safe : html end |