module ReCaptcha::Helpers

Public Instance Methods

recaptcha_script(language: nil) click to toggle source
# File lib/re_captcha/helpers.rb, line 10
def recaptcha_script(language: nil)
  html = ''
  html << %(<script src="#{ReCaptcha.client.api_endpoint}api.js#{language_query(language)}" async defer></script>\n)
  format_html(html)
end
recaptcha_tags(options = {}) click to toggle source
# File lib/re_captcha/helpers.rb, line 3
def recaptcha_tags(options = {})
  html = ''
  html << %(<div class="g-recaptcha" data-sitekey="#{ReCaptcha.client.public_key}" )
  html << %(#{tag_attributes(options)}></div>\n)
  format_html(html)
end

Private Instance Methods

format_html(html) click to toggle source
# File lib/re_captcha/helpers.rb, line 18
def format_html(html)
  html.respond_to?(:html_safe) ? html.html_safe : html
end
language_query(language) click to toggle source
# File lib/re_captcha/helpers.rb, line 31
def language_query(language)
  "?hl=#{ReCaptcha.client.language_code(language)}" if language
end
tag_attributes(theme: 'light', type: 'image', size: 'normal', tab_index: 0, callback: nil, expired_callback: nil) click to toggle source
# File lib/re_captcha/helpers.rb, line 22
def tag_attributes(theme: 'light', type: 'image', size: 'normal',
  tab_index: 0, callback: nil, expired_callback: nil)
  attributes = ''
  attributes << %(data-theme="#{theme}" data-type="#{type}" data-size="#{size}" data-tabindex="#{tab_index}" )
  attributes << %(data-callback="#{callback}" ) if callback
  attributes << %(data-expired-callback="#{expired_callback}") if expired_callback
  attributes.respond_to?(:html_safe) ? attributes.html_safe : attributes
end