Module: Ambethia::ReCaptcha::Helper
- Defined in:
- lib/recaptcha/recaptcha.rb
Instance Method Summary collapse
-
#recaptcha_tags(options = {}) ⇒ Object
Your public API can be specified in the
options
hash or preferably the environment variableRECAPTCHA_PUBLIC_KEY
.
Instance Method Details
#recaptcha_tags(options = {}) ⇒ Object
Your public API can be specified in the options
hash or preferably the environment variable RECAPTCHA_PUBLIC_KEY
.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/recaptcha/recaptcha.rb', line 13 def ( = {}) # Default options key = [:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY'] error = [:error] ||= session[:recaptcha_error] uri = [:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER xhtml = Builder::XmlMarkup.new :target => out=(''), :indent => 2 # Because I can. if [:display] xhtml.script(:type => "text/javascript"){ |x| x << "var RecaptchaOptions = #{[:display].to_json};\n"} end if [:ajax] xhtml.div(:id => 'dynamic_recaptcha') {} xhtml.script(:type => "text/javascript", :src => "#{uri}/js/recaptcha_ajax.js") {} xhtml.script(:type => "text/javascript") do |x| x << "Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha') );" end else xhtml.script(:type => "text/javascript", :src => :"#{uri}/challenge?k=#{key}&error=#{error}") {} unless [:noscript] == false xhtml.noscript do xhtml.iframe(:src => "#{uri}/noscript?k=#{key}", :height => [:iframe_height] ||= 300, :width => [:iframe_width] ||= 500, :frameborder => 0) {}; xhtml.br xhtml.textarea nil, :name => "recaptcha_challenge_field", :rows => [:textarea_rows] ||= 3, :cols => [:textarea_cols] ||= 40 xhtml.input :name => "recaptcha_response_field", :type => "hidden", :value => "manual_challenge" end end end raise ReCaptchaError, "No public key specified." unless key return out end |