Sha256: 0726987c1ffae4f42116c8a9d8d9b6a63c950faab4d6ff2b501f96283119bf89

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
# GoogleAdsense
module GoogleAdsense
  class Ad
    @@visible = false
    @@ads = {}
    cattr_accessor :client,:visible,:ads
    attr_accessor  :width,:height,:client,:id,:slot
    def self.visible?
      !!visible
    end

    def initialize(id,slot,options={})
      @id     = id
      @client = self.class.client
      @width  = options[:width] || 728
      @height = options[:height] || 90
      @slot   = slot
      self.class.ads[@id] = self
    end

    def to_html
      html = "<script language=\"javascript\">\n"
      html << "google_ad_client = \"#{@client}\";\n"
      html << "google_ad_slot = \"#{@slot}\";\n"
      html << "google_ad_width = #{@width};\n"
      html << "google_ad_height = #{@height}\n"
      html << "</script>\n";
      html << "<script language=\"javascript\" type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>\n"
    end
  end

  module Helpers
    def google_adsense(id)
      ad = GoogleAdsense::Ad.ads[id]
      if ad 
        if GoogleAdsense::Ad.visible?
          ad.to_html.html_safe
        else
          "<div style='overflow:hidden;width:#{ad.width};height:#{ad.height};border:1px dashed #555'>#{h ad.inspect}</div>".html_safe
        end
      else
        ''
      end
    end
  end
end

ActionView::Base.send(:include,GoogleAdsense::Helpers)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
google_adsense-0.0.4 lib/google_adsense.rb
google_adsense-0.0.3 lib/google_adsense.rb
google_adsense-0.0.2 lib/google_adsense.rb
google_adsense-0.0.1 lib/google_adsense.rb