inital x2

This commit is contained in:
Scott Davis 2011-02-01 16:03:28 -05:00
parent e5153f4361
commit c011e83ac1
7 changed files with 63 additions and 12 deletions

1
init.rb Normal file
View File

@ -0,0 +1 @@
require 'flowplayer'

View File

@ -1 +1,5 @@
require 'flowplayer/player' require 'flowplayer/player'
if defined?(Rails)
require 'flowplayer/railtie'
end

View File

@ -1,9 +1,9 @@
require 'json' require 'json'
module Flowplayer module Flowplayer
class Player class Player
attr_accessor :options, :functions, :dom_id attr_accessor :options, :functions, :dom_id, :swf
def initialize(dom_id, &block) def initialize(dom_id, swf, &block)
@dom_id = dom_id @dom_id, @swf = dom_id, swf
@options = {} @options = {}
@functions = {} @functions = {}
block.call(self) block.call(self)
@ -20,7 +20,7 @@ module Flowplayer
<<-EOS <<-EOS
<script type='text/javascript'> <script type='text/javascript'>
//<![CDATA[ //<![CDATA[
flowplayer("#{dom_id}", #{to_js}) flowplayer("#{dom_id}", "#{swf}", #{to_js});
//]]> //]]>
</script> </script>
EOS EOS

View File

@ -1,8 +1,13 @@
module Flowplayer module Flowplayer
require 'rails' require 'rails'
require File.join(File.expand_path('../', __FILE__), 'railties/helper')
class Railtie < ::Rails::Railtie class Railtie < ::Rails::Railtie
generators do generators do
require File.join(File.expand_path('../', __FILE__), 'railties', 'generators', 'compass_theme', 'compass_theme_generator.rb') require File.join(File.expand_path('../', __FILE__), 'railties', 'generator', 'install_generator.rb')
end
initializer "flowplayer.configure_rails_initialization" do
#ApplicationHelper.send(:include, Flowplayer::Helper)
ApplicationController.instance_eval { helper Flowplayer::Helper }
end end
end end
end end

View File

@ -0,0 +1,24 @@
module Flowplayer
module Generator
class InstallGenerator < Rails::Generators::Base
namespace 'flowplayer'
source_root File.expand_path("../../../../../assets", __FILE__)
argument :install_type, :type => :string, :banner => "commercial", :required => false, :default => ''
def install_flowplayer
copy_file 'flowplayer-3.2.4.min.js', Rails.root.join('public', 'javascript', 'flowplayer.min.js')
end
def install_swfs
if install_type == 'commercial'
copy_file 'flowplayer.commercial-3.2.5.swf', Rails.root.join('public', 'flowplayer.swf')
else
copy_file 'flowplayer-3.2.5.swf', Rails.root.join('public', 'flowplayer.swf')
copy_file 'LICENSE.txt', Rails.root.join('FLOWPLAYER_LICENSE.txt')
end
copy_file 'flowplayer.controls-3.2.3.swf', Rails.root.join('public', 'flowplayer.controls.swf')
end
end
end
end

View File

@ -0,0 +1,16 @@
module Flowplayer
module Helper
# flowplayer_for :hubble do |f|
# f.option 'foo'
# f.onLoad do
# 'this.unmute();'
# end
def flowplayer_for(id, swf, &block)
Player.new(id, swf, &block).script_tags.html_safe
end
end
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Flowplayer::Player do describe Flowplayer::Player do
it "should set options from block" do it "should set options from block" do
flow_player = Flowplayer::Player.new('my_video') do |player| flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen true player.fullscreen true
player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true) player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
player.onLoad do player.onLoad do
@ -17,14 +17,14 @@ describe Flowplayer::Player do
end end
it "should set the dom_id to 'my_video'" do it "should set the dom_id to 'my_video'" do
flow_player = Flowplayer::Player.new('my_video') do |player| flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen true player.fullscreen true
end end
flow_player.dom_id.should == 'my_video' flow_player.dom_id.should == 'my_video'
end end
it "should generate valid options" do it "should generate valid options" do
flow_player = Flowplayer::Player.new('my_video') do |player| flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen true player.fullscreen true
player.logo({:opacity => 0, :fullscreenOnly => true}) player.logo({:opacity => 0, :fullscreenOnly => true})
player.onLoad do player.onLoad do
@ -37,21 +37,22 @@ describe Flowplayer::Player do
end end
it "should create script tags with options" do it "should create script tags with options" do
flow_player = Flowplayer::Player.new('my_video') do |player| flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen true player.fullscreen true
player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true) player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
player.onLoad do player.onLoad do
'this.unmute();' 'this.unmute();'
end end
end end
["<script", "</script>", "flowplayer(\"my_video\", #{flow_player.to_js}"].each do |part| ["<script", "</script>", "flowplayer(\"my_video\", \"commericial.swf\", #{flow_player.to_js}"].each do |part|
flow_player.script_tags.should include part flow_player.script_tags.should include part
end end
flow_player.script_tags.should match(/\)\;/)
end end
it "should raise exception if passed a setter" do it "should raise exception if passed a setter" do
lambda do lambda do
flow_player = Flowplayer::Player.new('my_video') do |player| flow_player = Flowplayer::Player.new('my_video', 'commericial.swf') do |player|
player.fullscreen = true player.fullscreen = true
end end
end.should raise_error end.should raise_error