Module: AdSenseForSearch::ViewHelper

Defined in:
lib/adsense_for_search/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#adsense_for_search(*options) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
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
43
44
45
46
47
48
49
50
# File 'lib/adsense_for_search/view_helper.rb', line 5

def adsense_for_search(*options)
  raise ArgumentError, "AdSense for search needs a query string" unless options.first

  pageOptions = {
    :pubId => 'pub',
    :query => options.first
  }

  adblock1 = {
    :container => 'adblock1',
    :number => 3,
    :width => 'auto',
    :lines => 2,
    :fontFamily => 'arial',
    :fontSizeTitle => '14px',
    :fontSizeDescription => '14px',
    :fontSizeDomainLink => '14px'
  }

  adblock1.merge! options.last[:adblock1] if options.last.has_key? :adblock1

  adblock2 = {
    :container => 'adblock2',
    :number => 4,
    :width => '250px',
    :lines => 3,
    :fontFamily => 'arial',
    :fontSizeTitle => '12px',
    :fontSizeDescription => '12px',
    :fontSizeDomainLink => '12px'
  }

  adblock2.merge! options.last[:adblock2] if options.last.has_key? :adblock2

  js = ""
  js << "var pageOptions = #{pageOptions.to_json2};\n"
  js << "\n  var adblock1 = #{adblock1.to_json2};\n" if options.last.has_key? :adblock1
  js << "\n  var adblock2 = #{adblock2.to_json2};\n" if options.last.has_key? :adblock2
  js << "\n  new google.ads.search.Ads(pageOptions#{ ', adblock1' if options.last.has_key? :adblock1 }#{ ', adblock2' if options.last.has_key? :adblock2 });"

  <<-javascript
<script type="text/javascript" charset="utf­8">
  #{js}
</script>
  javascript
end