Module: Ads::Rails::ActionView::Base

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

Instance Method Summary collapse

Instance Method Details

#google_adsense_include_tag(*args) ⇒ Object



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
# File 'lib/ads/rails/action_view/base.rb', line 6

def google_adsense_include_tag(*args)
  options = args.extract_options!
  if ::Rails.env.production?
    variables = options.map do |key, value|
      if value.is_a? String
        value = "'#{value}'"
      end
      "google_ad_#{key} = #{value};"
    end
    (
      :script,
      variables.join("\n").html_safe,
      type: 'text/javascript'
    ) +
    (
      :script,
      nil,
      type: 'text/javascript',
      src: "#{request.protocol}pagead2.googlesyndication.com/pagead/show_ads.js"
    )
  elsif Ads.config.renderer.is_a? Proc
    instance_exec options, &Ads.config.renderer
  else
    (
      :div,
      nil,
      style: "width:#{options[:width]}px;height:#{options[:height]}px;background:#c8c8c8;"
    )
  end
end