Module: ReCaptcha::ViewHelper

Defined in:
lib/recaptcha.rb

Overview

Some simple view helpers. Include this module in your own helper to pull in macros to spit out view code.

include Recaptcha

Instance Method Summary collapse

Instance Method Details

#get_captcha(options = {}) ⇒ Object

Call this to generate the actual ReCaptcha script into your template. Options can include

rcc_pub

public recaptcha key (defaults to RCC_PUB constant)

rcc_priv

privte recaptcha key (defaults to RCC_PRIV constant)

ssl

generate ssl-based output, defaults to false

This method also sets :rcc_err into the session. Example (rcc_pub and rcc_private not required if RCC_PUB & RCC_PRIV constants are used):

= get_captcha(:rcc_pub => 'foobar', :rcc_priv => 'blegga', :ssl => true)


41
42
43
44
45
46
# File 'lib/recaptcha.rb', line 41

def get_captcha(options={})
  k = ReCaptcha::Client.new((options[:rcc_pub] || RCC_PUB), (options[:rcc_priv] || RCC_PRIV), (options[:ssl] || false))
  r = k.get_challenge(session[:rcc_err] || '', options)
  session[:rcc_err]=''
  r
end

#mail_hide(address, contents = nil) ⇒ Object

Call this to generate the MailHide view code.

Note: doesn’t currently support ssl for some reason.

address

the email address you want to hide

contents

optional string to display as the text of the mailhide link



54
55
56
57
58
59
60
61
62
63
# File 'lib/recaptcha.rb', line 54

def mail_hide(address, contents=nil)
  contents = truncate(address,10) if contents.nil?
  k = ReCaptcha::MHClient.new(MH_PUB, MH_PRIV, address)
  enciphered = k.crypted_address
  uri = "http://www.google.com/recaptcha/mailhide/d?k=#{MH_PUB}&c=#{enciphered}"
  t =<<-EOF
  <a href="#{uri}"
  onclick="window.open('#{uri}', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;" title="Reveal this e-mail address">#{contents}</a>
EOF
end