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'
if defined?(Rails)
require 'flowplayer/railtie'
end

View File

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

View File

@ -1,8 +1,13 @@
module Flowplayer
require 'rails'
require File.join(File.expand_path('../', __FILE__), 'railties/helper')
class Railtie < ::Rails::Railtie
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

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
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.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
player.onLoad do
@ -17,14 +17,14 @@ describe Flowplayer::Player do
end
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
end
flow_player.dom_id.should == 'my_video'
end
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.logo({:opacity => 0, :fullscreenOnly => true})
player.onLoad do
@ -37,21 +37,22 @@ describe Flowplayer::Player do
end
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.logo(:url => nil, :opacity => 0, :fullscreenOnly => true)
player.onLoad do
'this.unmute();'
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
end
flow_player.script_tags.should match(/\)\;/)
end
it "should raise exception if passed a setter" 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
end
end.should raise_error