Skip to content

Commit

Permalink
Admin can edit video content on the home page
Browse files Browse the repository at this point in the history
  • Loading branch information
veezus committed Feb 17, 2009
1 parent 1b0d5c5 commit fbd0240
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/controllers/admin/site_options_controller.rb
@@ -0,0 +1,10 @@
class Admin::SiteOptionsController < ApplicationController
resources_controller_for :site_options
layout false

response_for :update do |format|
format.html do
redirect_to :back
end
end
end
12 changes: 12 additions & 0 deletions app/helpers/admin/site_options_helper.rb
@@ -0,0 +1,12 @@
module Admin::SiteOptionsHelper
def video_content
SiteOption.for(:video_content)
end

def change_site_option(key)
if current_user && current_user.admin?
site_option = SiteOption.find_or_initialize_by_key(key)
link_to "Edit #{key.to_s.humanize}", edit_admin_site_option_path(site_option), :rel => 'facebox'
end
end
end
16 changes: 16 additions & 0 deletions app/models/site_option.rb
@@ -0,0 +1,16 @@
class SiteOption < ActiveRecord::Base
include Sanitizy

validates_presence_of :key
validates_presence_of :value

cleanse_columns(:value) do |sanitizer|
sanitizer.allowed_tags.replace(%w(object param embed a img))
sanitizer.allowed_attributes.replace(%w(width height name src value allowFullScreen type href allowScriptAccess style wmode pluginspage classid codebase data quality))
end

def self.for(key)
site_option = find_by_key(key)
site_option && site_option.value
end
end
5 changes: 5 additions & 0 deletions app/views/admin/site_options/edit.html.haml
@@ -0,0 +1,5 @@
- form_for([:admin, @site_option]) do |f|
= f.label :value
= f.text_area :value
%br/
= f.submit
15 changes: 6 additions & 9 deletions app/views/homes/show.html.haml
Expand Up @@ -2,16 +2,13 @@
- # TODO Clean home page mark up for equalizing column white backgrounds. - CT
.block-spacer
.home-boxer
%div.home-floater.home-image-box{:style=>"width:375px;float:left;background: #fff;"}
%div.home-floater.home-image-box{:style=>"width:425px;float:left;background: #fff;"}
.home-floater
%h3{:style => "color: red;"}
%strong What is Spot.Us?
.double_content_border
%object{ :height => "197", :width => "350" }
%param{ :name => "allowfullscreen", :value => "true" }/
%param{ :name => "allowscriptaccess", :value => "always" }/
%param{ :name => "movie", :value => "http://vimeo.com/moogaloop.swf?clip_id=2041615&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" }/
%embed{ :src => "http://vimeo.com/moogaloop.swf?clip_id=2041615&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1", :type => "application/x-shockwave-flash", :allowfullscreen => "true", :allowscriptaccess => "always", :height => "197", :width => "350" }/
= video_content
= change_site_option(:video_content)
%hr.space.clear
.double_content_border{:style=>"margin-top:10px;"}
%h5{:style=>"margin:0;"}
Expand All @@ -24,7 +21,7 @@
== #{link_to "blog", "http://blog.spot.us"} join our
== #{link_to "Facebook", "http://www.facebook.com/home.php#/group.php?sid=b04b3406bd9281f4fe4df6c39efef5d5&refurl=http%3A%2F%2Fwww.facebook.com%2Fs.php%3Fref%3Dsearch%26init%3Dq%26q%3Dspot.us%26sid%3Db04b3406bd9281f4fe4df6c39efef5d5&gid=29554944739"} or follow us on
== #{link_to "Twitter", "http://twitter.com/spotus"}.
%div.home-floater{:style=>"width:510px;float:right;background: #fff;"}
%div.home-floater{:style=>"width:460px;float:right;background: #fff;"}
- if @featured_pitch.blank?
%h3 Create the first story
.double_content_border
Expand Down Expand Up @@ -66,10 +63,10 @@
%img{:src=>"../images/spotus_ie_pixel.gif"}
.block-spacer
.home-boxer
%div.home-floater.home-image-box{:style=>"width:375px;float:left;background: #fff;"}
%div.home-floater.home-image-box{:style=>"width:425px;float:left;background: #fff;"}
= link_to image_tag('nyt_article.png'), 'http://www.nytimes.com/2008/08/24/weekinreview/24kershaw.html?_r=1&oref&oref=slogin'

%div.home-floater{:style=>"width:510px;float:right;background: #fff;"}
%div.home-floater{:style=>"width:460px;float:right;background: #fff;"}
%h3 Start a Story
.double_content_border
%h3
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -32,6 +32,7 @@
admin.resources :credits
admin.resources :pitches, :member => { :fact_checker_chooser => :get }
admin.resources :tips
admin.resources :site_options
end

map.namespace :myspot do |myspot|
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20090217143024_create_site_options.rb
@@ -0,0 +1,14 @@
class CreateSiteOptions < ActiveRecord::Migration
def self.up
create_table :site_options do |t|
t.string :key
t.text :value

t.timestamps
end
end

def self.down
drop_table :site_options
end
end
11 changes: 11 additions & 0 deletions db/migrate/20090217151235_load_site_options.rb
@@ -0,0 +1,11 @@
class LoadSiteOptions < ActiveRecord::Migration
def self.up
SiteOption.create!(:key => :video_content, :value => "<object width=\"400\" height=\"225\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=2041615&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=2041615&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"400\" height=\"225\"></embed></object>")
end

def self.down
if site_option = SiteOption.find_by_key(:video_content)
site_option.destroy
end
end
end
9 changes: 9 additions & 0 deletions spec/controllers/admin/site_options_controller_spec.rb
@@ -0,0 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Admin::SiteOptionsController do

it "should use resources_controller" do
# no test for this
end

end
5 changes: 5 additions & 0 deletions spec/factories.rb
Expand Up @@ -170,6 +170,11 @@
credit.association(:user)
end

Factory.define :site_option do |site_option|
site_option.key 'key'
site_option.value 'value'
end


# handy builders ##################################################################################

Expand Down
38 changes: 38 additions & 0 deletions spec/helpers/admin/site_options_helper_spec.rb
@@ -0,0 +1,38 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Admin::SiteOptionsHelper do
include Admin::SiteOptionsHelper

describe "video_content" do
it "should ask SiteOption for the value" do
SiteOption.should_receive(:for).with(:video_content).and_return('a value')
video_content.should == 'a value'
end
end

describe "change_site_option" do
it "should load or initialize a site option" do
stub!(:current_user).and_return(Factory(:admin))
site_option = SiteOption.create!(:key => :key, :value => 'a value')
SiteOption.should_receive(:find_or_initialize_by_key).with(:key).and_return(site_option)
change_site_option(:key)
end

it "should give an edit link if the user is an admin" do
site_option = SiteOption.create!(:key => :key, :value => 'a value')
SiteOption.stub!(:find_or_initialize_by_key).and_return(site_option)
stub!(:current_user).and_return(Factory(:admin))
change_site_option(:key).should have_tag('a[href=?]', edit_admin_site_option_path(site_option))
end

it "should return nil if the user is not an admin" do
stub!(:current_user).and_return(Factory(:citizen))
change_site_option(:key).should be_nil
end

it "should return nil if there is no current_user" do
stub!(:current_user).and_return(nil)
change_site_option(:key).should be_nil
end
end
end
16 changes: 16 additions & 0 deletions spec/models/site_option_spec.rb
@@ -0,0 +1,16 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe SiteOption do

requires_presence_of SiteOption, :key
requires_presence_of SiteOption, :value

it "should have a for class method" do
SiteOption.should respond_to(:for)
end

it "should return a value based on a key" do
SiteOption.create!(:key => :key, :value => 'value')
SiteOption.for(:key).should == 'value'
end
end

0 comments on commit fbd0240

Please sign in to comment.