Module: AdSense::Rails::ActionView::Base

Defined in:
lib/ad_sense/rails/action_view/base.rb

Instance Method Summary collapse

Instance Method Details



36
37
38
39
40
41
42
# File 'lib/ad_sense/rails/action_view/base.rb', line 36

def ad_link_tag(ad_slot, options = {})
  adsense_opts  = get_ad_options_from_hash(options.merge(ad_slot: ad_slot), true)
  wrapper_class = get_classes_for_ad_wrapper(adsense_opts)
  adsense_opts  = get_ad_script_from_hash(adsense_opts)

  generate_ad_tag wrapper_class, adsense_opts
end

#ad_search_tag(ad_container_id, options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ad_sense/rails/action_view/base.rb', line 13

def ad_search_tag(ad_container_id, options)
  # based on https://developers.google.com/custom-search-ads/docs/code-generator
  script = "         var pageOptions = {\n           'pubId': '\#{AdSense.search_ad_client_id}',\n           'query': '\#{get_query_for_search_ad(options)}',\n           'hl': 'en'\n         };\n\n        var adblock1 = {\n          'container': '\#{ad_container_id}',\n          'width': '\#{options[:width]}'\n        };\n        new google.ads.search.Ads(pageOptions, adblock1);\n  SCRIPT\n\n  content_tag :div, class: \"search_ad_wrapper \#{options[:wrapper_class]}\" do\n    [content_tag(:div, '', id: ad_container_id),\n     javascript_include_tag('http://www.google.com/adsense/search/ads.js'),\n     javascript_tag { script }].join('').html_safe\n  end\nend\n".strip_heredoc

#ad_slot_tag(ad_slot = nil, options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/ad_sense/rails/action_view/base.rb', line 5

def ad_slot_tag(ad_slot = nil, options = {})
  adsense_opts  = get_ad_options_from_hash(options.merge!(ad_slot: ad_slot), false)
  wrapper_class = get_classes_for_ad_wrapper(options)
  adsense_opts  = get_ad_script_from_hash(adsense_opts)

  generate_ad_tag wrapper_class, adsense_opts
end