Permalink
Browse files

Initial commit of the Ad Banners extension

  • Loading branch information...
0 parents commit 7a6c0d36d375ff2ff645e65068a8cf2b072ca6d3 @davec committed Jun 13, 2009
3 README
@@ -0,0 +1,3 @@
+= Ad Banners
+
+Description goes here
120 Rakefile
@@ -0,0 +1,120 @@
+# I think this is the one that should be moved to the extension Rakefile template
+
+# In rails 1.2, plugins aren't available in the path until they're loaded.
+# Check to see if the rspec plugin is installed first and require
+# it if it is. If not, use the gem version.
+
+# Determine where the RSpec plugin is by loading the boot
+unless defined? RADIANT_ROOT
+ ENV["RAILS_ENV"] = "test"
+ case
+ when ENV["RADIANT_ENV_FILE"]
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
+ else
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
+ end
+end
+
+require 'rake'
+require 'rake/rdoctask'
+require 'rake/testtask'
+
+rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
+$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
+require 'spec/rake/spectask'
+# require 'spec/translator'
+
+# Cleanup the RADIANT_ROOT constant so specs will load the environment
+Object.send(:remove_const, :RADIANT_ROOT)
+
+extension_root = File.expand_path(File.dirname(__FILE__))
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
+ end
+
+ desc "Print Specdoc for all specs"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ [:models, :controllers, :views, :helpers].each do |sub|
+ desc "Run the specs under spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ # Hopefully no one has written their extensions in pre-0.9 style
+ # desc "Translate specs from pre-0.9 to 0.9 style"
+ # task :translate do
+ # translator = ::Spec::Translator.new
+ # dir = RAILS_ROOT + '/spec'
+ # translator.translate(dir, dir)
+ # end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
+ ::CodeStatistics::TEST_TYPES << "Model specs"
+ ::CodeStatistics::TEST_TYPES << "View specs"
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
+ task :load => :environment do
+ require 'active_record/fixtures'
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+end
+
+desc 'Generate documentation for the ad_banners extension.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'AdBannersExtension'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+# For extensions that are in transition
+desc 'Test the ad_banners extension.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+# Load any custom rakefiles for extension
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,25 @@
+# Uncomment this if you reference any of your controllers in activate
+# require_dependency 'application'
+
+class AdBannersExtension < Radiant::Extension
+ version "0.1"
+ description "Manage ad banners"
+ url "http://yourwebsite.com/ad_banners"
+
+ define_routes do |map|
+ map.namespace :admin, :member => { :remove => :get } do |admin|
+ admin.resources :ad_banners
+ end
+ end
+
+ def activate
+ Radiant::AdminUI.send :include, AdBannersAdminUI unless defined? admin.ad_banner
+ admin.ad_banner = Radiant::AdminUI.load_default_ad_banner_regions
+
+ admin.tabs.add "Ads", "/admin/ad_banners", :after => "Layouts", :visibility => [:all]
+ end
+
+ def deactivate
+ end
+
+end
@@ -0,0 +1,3 @@
+class Admin::AdBannersController < Admin::ResourceController
+ model_class AdBanner
+end
@@ -0,0 +1,2 @@
+module Admin::AdBannersHelper
+end
@@ -0,0 +1,10 @@
+class AdBanner < ActiveRecord::Base
+ default_scope :order => 'name ASC'
+
+ belongs_to :asset
+
+ validates_presence_of :name, :asset_id#, :link_url
+ validates_format_of :link_url, :allow_blank => true,
+ :with => /\Ahttps?:\/\/.+\z/,
+ :message => "doesn't look like a URL"
+end
@@ -0,0 +1,26 @@
+- @stylesheets << 'admin/assets'
+- include_javascript 'lowpro'
+- include_javascript 'admin/assets'
+- include_javascript 'admin/ad_banners'
+- include_javascript 'dragdrop'
+
+#assets-container
+ #asset-tabs
+ - render_region :asset_tabs do |asset_tabs|
+ -# asset_tabs.upload_tab do
+ %a.asset-tab{ :href => "#upload-assets", :id => "tab_upload-assets" } Upload
+ - asset_tabs.bucket_tab do
+ %a.asset-tab{ :href => "#bucket", :id => "tab_bucket" } Bucket
+
+ #assets
+ #bucket.pane
+ - render_region :bucket_pane do |bucket_pane|
+ - bucket_pane.bucket_notes do
+ %p
+ %span.note The Bucket provides temporary storage for your items.
+ %span#clear-bucket
+ = link_to_remote('Clear Bucket', {:url => clear_bucket_url} )
+ - bucket_pane.bucket do
+ = render :partial => "bucket"
+ - bucket_pane.bucket_bottom do
+ .clear
@@ -0,0 +1,10 @@
+%ul#bucket_list
+ - if session[:bucket]
+ - session[:bucket].each do |url, info|
+ = render :partial => 'bucket_asset', :locals => { :asset_url => url, :asset_id => info[:id], :asset_type => info[:type], :asset_title => info[:title], :asset_thumbnail =>info[:thumbnail], :page => @page }
+ - else
+ %li
+ %p.note Your bucket is empty
+
+
+
@@ -0,0 +1,7 @@
+%li
+
+ %div{ :class => "#{asset_type} asset", :id => "bucket_#{asset_id}" }
+ = link_to image_tag(asset_thumbnail), asset_url, :title => asset_title, :class => "bucket_link"
+
+ .info{ :id => "#{asset_id}_info" }
+ = link_to_function image_tag('/images/assets/add.png'), "AdBanner.attach($('bucket_#{asset_id}'), $('image-thumbnail'))", { :class => 'add_asset', :title => 'Attach to ad' }
@@ -0,0 +1,33 @@
+- thumb_width, thumb_height = Asset.thumbnail_sizes[:thumbnail].first.split(/\D/)
+- form_for [:admin, @ad_banner] do |f|
+ .form-area
+ #ad_banner_form_area
+ #ad_banner-data
+ %p.title
+ %label{:for => 'ad_banner_name'} Name
+ = f.text_field :name, :class => 'textbox', :maxlength => 255
+ %p.title
+ %label{:for => 'ad_banner_asset_id'} Image
+ %span#image-thumbnail{ :style => "width:#{thumb_width}px;height:#{thumb_height}px;" }
+ - if @ad_banner.asset.nil?
+ %span.note Drag an image from the assets bucket to here
+ - else
+ = image_tag(@ad_banner.asset.thumbnail(:thumbnail))
+ = f.hidden_field :asset_id
+ %p.title
+ %label{:for => 'ad_banner_link_url'} Link URL
+ = f.text_field :link_url, :class => 'textbox', :maxlength => 255
+ %p.title
+ %label{:for => 'ad_banner_weight'}
+ Weight
+ %span.note (The greater the weight, the more likely the ad banner is to appear.)
+ = f.select :weight, (1..10).to_a
+ %p.title
+ %label{:for => 'ad_banner_link_target'} Target Window
+ = f.select :link_target, [ [ 'Default', '' ], [ 'New Window', '_blank' ], [ 'Same Window', '_top' ] ]
+ = javascript_tag "$('ad_banner_name').activate()"
+ %p.buttons
+ = save_model_button(@ad_banner)
+ = save_model_and_continue_editing_button(@ad_banner)
+ or
+ = link_to('Cancel', admin_ad_banners_url)
@@ -0,0 +1,9 @@
+- include_stylesheet 'admin/ad_banners'
+= render_region :top
+
+- render_region :main do |main|
+ - main.edit_header do
+ %h1 Edit Ad Banner
+
+ - main.edit_form do
+ = render :partial => 'form'
@@ -0,0 +1,42 @@
+- include_stylesheet 'admin/ad_banners'
+
+%h1 Ad Banners
+
+%p
+ Click on an ad banner name below to edit it, or click <code>Remove</code> to delete it.
+
+%table#ad_banners.index
+ %thead
+ %tr
+ %th.name
+ Name
+ %th.image
+ Image Preview
+ %th.weight
+ Weight
+ %th.url
+ URL
+ %th.modify
+ Modify
+ %tbody
+ - if @ad_banners.empty?
+ %tr
+ %td.note{ :colspan => '5' }
+ No Ad Banners
+ - else
+ - @ad_banners.each do |ad_banner|
+ %tr.node.level-1
+ %td.name
+ = image('ad_banners/ad')
+ = link_to(h(ad_banner.name), edit_admin_ad_banner_url(ad_banner))
+ %td.image
+ = image_tag(ad_banner.asset.thumbnail(:icon))
+ %td.weight
+ = ad_banner.weight
+ %td.url
+ = link_to ad_banner.link_url
+ %td.remove
+ = link_to(image('remove', :alt => 'Remove Ad Banner'), remove_admin_ad_banner_url(ad_banner))
+
+%p
+ = link_to(image('ad_banners/new-ad', :alt => 'New Ad Banner'), new_admin_ad_banner_url)
@@ -0,0 +1,9 @@
+- include_stylesheet 'admin/ad_banners'
+= render_region :top
+
+- render_region :main do |main|
+ - main.edit_header do
+ %h1 New Ad Banner
+
+ - main.edit_form do
+ = render :partial => 'form'
@@ -0,0 +1,21 @@
+- include_stylesheet 'admin/ad_banners'
+
+%h1 Remove Ad Banner
+
+%p Are you sure you want to <strong class="warning">permanently remove</strong> the following ad banner?
+
+%table#ad_banners.index
+ %tbody
+ %tr.node.level-1
+ %td.name
+ = h @ad_banner.name
+ %td.image
+ = image_tag(@ad_banner.asset.thumbnail(:thumbnail))
+ %td.link_url
+ = @ad_banner.link_url
+
+- form_for [:admin, @ad_banner], :html => { :method => :delete } do
+ %p.buttons
+ %input.button{ :type => 'submit', :value => 'Delete Ad Banner' }/
+ or
+ = link_to('Cancel', admin_ad_banners_url)
@@ -0,0 +1,17 @@
+class CreateAdBanners < ActiveRecord::Migration
+ def self.up
+ create_table :ad_banners do |t|
+ t.string :name
+ t.string :link_url
+ t.string :link_target
+ t.integer :asset_id
+ t.integer :weight
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :ad_banners
+ end
+end
@@ -0,0 +1,25 @@
+module AdBannersAdminUI
+
+ def self.included(base)
+ base.class_eval do
+
+ attr_accessor :ad_banner
+ alias_method :ad_banners, :ad_banner
+
+ protected
+
+ def load_default_ad_banner_regions
+ returning OpenStruct.new do |ad_banner|
+ ad_banner.edit = Radiant::AdminUI::RegionSet.new do |edit|
+ edit.main.concat %w{edit_header edit_form assets_container}
+ edit.bucket_pane.concat %w{bucket_notes bucket bucket_bottom}
+ edit.asset_tabs.concat %w{bucket_tab}
+ end
+ ad_banner.new = ad_banner.edit
+ end
+ end
+
+ end
+
+ end
+end
Oops, something went wrong.

0 comments on commit 7a6c0d3

Please sign in to comment.