Module: AdCopy::ViewMethods

Included in:
ActionView::Base
Defined in:
lib/view_methods.rb

Overview

Methods within this module will be included in ActionView::Base

Instance Method Summary collapse

Instance Method Details

#adcopy_puzzle(options = {}) ⇒ Object

Returns the HTML for an AdCopy puzzle

Options:

tabindex

The tab index of the text field within the puzzle (defaults to nil)

theme

The theme applied to the puzzle (defaults to 'purple')

lang

The language of the puzzle (defaults to 'en')



12
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
# File 'lib/view_methods.rb', line 12

def adcopy_puzzle(options = {})
  AdCopy::check_for_keys!
  options = { :tabindex => nil,
              :theme    => 'purple',
              :lang     => 'en'
              }.merge(options)
  
  output = ""
  
  output << %{<script type="text/javascript">\n}
  output << " var ACPuzzleOptions = {\n"
  output << %{      tabindex:   #{options[:tabindex]},\n} unless options[:tabindex].nil?
  output << %{      theme:     '#{options[:theme]}',\n}
  output << %{      lang:      '#{options[:lang]}'\n}
  output << " };\n"
  output << %{</script>\n}
  
  output << %{<script type="text/javascript"}
  output << %{   src="#{AdCopy::API_SERVER}/papi/challenge.script?k=#{AdCopy::CONFIG['C_KEY']}">}
  output << %{</script>}

  output << %{<noscript>}
  output << %{   <iframe src="#{AdCopy::API_SERVER}/papi/challenge.noscript?k=#{AdCopy::CONFIG['C_KEY']}"}
  output << %{   height="300" width="500" frameborder="0"></iframe><br/>}
  output << %{   <textarea name="adcopy_challenge" rows="3" cols="40">}
  output << %{   </textarea>}
  output << %{   <input type="hidden" name="adcopy_response"}
  output << %{   value="manual_challenge"/>}
  output << %{</noscript>}
  return output
end