Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:avonderluft/radiant-banner-rotato…
Browse files Browse the repository at this point in the history
…r-extension

Conflicts:
	banner_rotator_extension.rb
  • Loading branch information
Andrew vonderLuft committed Nov 17, 2010
2 parents 283e435 + 72eb0ae commit a1464ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/views/admin/banners/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
= f.label :name
= f.text_field :name, :class => 'textbox'
%br/
%p
= f.label :description, "Description"
%br/
~ f.text_area :description, :size => '72x5'
%p
= f.label :background_image
%br/
Expand Down
3 changes: 2 additions & 1 deletion banner_rotator_extension.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class BannerRotatorExtension < Radiant::Extension

version "0.7.2"
description "Allows addition and independent management of rotating banners on pages."
url "https://github.com/avonderluft/radiant-banner-rotator-extension"
Expand All @@ -23,7 +24,7 @@ def activate
end

def deactivate
admin.tabs.remove "Banners"
# admin.tabs.remove "Banners"
end

def load_default_banner_regions
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/003_add_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddDescription < ActiveRecord::Migration
def self.up
add_column :banners, :description, :text
end

def self.down
remove_column :banners, :description
end
end
9 changes: 7 additions & 2 deletions lib/banner_rotator/page_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ def banner_placements_with_inheritance
end

def select_banner
banners_with_weighting = banner_placements.map do |p|
@banners_with_weighting ||= banner_placements.map do |p|
[p.banner] * p.weight
end.flatten
banners_with_weighting[rand(banners_with_weighting.size)]

x = rand(@banners_with_weighting.size)
banner = @banners_with_weighting[x]
@banners_with_weighting.delete(x+1)

banner
end
end
end
9 changes: 8 additions & 1 deletion lib/banner_rotator/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module BannerRotator::Tags
tag.expand if tag.locals.banner && page.show_banner?
end

%w{name background_image foreground_image link_url link_target image_style}.each do |att|
%w{name background_image foreground_image link_url link_target image_style description}.each do |att|
desc %{
Outputs the #{att} attribute of the current banner.
Expand All @@ -42,6 +42,13 @@ module BannerRotator::Tags
tag "banner:if_#{att}" do |tag|
tag.expand unless tag.locals.banner[att].blank?
end
tag "banner:content" do |tag|
if tag.locals.banner['background_image'] =~ /swf/i
"<a href=\"#{tag.locals.banner['link_url']}\" target=\"#{tag.locals.banner['link_target']}\"><object class=\"banner\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"160\" height=\"140\" bgcolor=\"#f0f7fd\"><param name=\"movie\" value=\"#{tag.locals.banner['background_image']}\"><param name=\"quality\" value=\"high\"><embed src=\"#{tag.locals.banner['background_image']}\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"160\" height=\"140\" bgcolor=\"#f0f7fd\"></embed></object></a>"
else
"<a href=\"#{tag.locals.banner['link_url']}\" target=\"#{tag.locals.banner['link_target']}\"><img src=\"#{tag.locals.banner['background_image']}\" /></a>"
end
end
desc %{
Expands the contents if there is no #{att}.
Expand Down

0 comments on commit a1464ab

Please sign in to comment.