From c011e83ac1a3e39f6d523e7d9ce0df16715b37f3 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 1 Feb 2011 16:03:28 -0500 Subject: [PATCH] inital x2 --- init.rb | 1 + lib/flowplayer.rb | 6 ++++- lib/flowplayer/player.rb | 8 +++---- lib/flowplayer/railtie.rb | 7 +++++- .../railties/generator/install_generator.rb | 24 +++++++++++++++++++ lib/flowplayer/railties/helper.rb | 16 +++++++++++++ spec/flowplayer_spec.rb | 13 +++++----- 7 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 init.rb create mode 100644 lib/flowplayer/railties/generator/install_generator.rb create mode 100644 lib/flowplayer/railties/helper.rb diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..94a3966 --- /dev/null +++ b/init.rb @@ -0,0 +1 @@ +require 'flowplayer' \ No newline at end of file diff --git a/lib/flowplayer.rb b/lib/flowplayer.rb index 0a1a395..671a79d 100644 --- a/lib/flowplayer.rb +++ b/lib/flowplayer.rb @@ -1 +1,5 @@ -require 'flowplayer/player' \ No newline at end of file +require 'flowplayer/player' + +if defined?(Rails) + require 'flowplayer/railtie' +end \ No newline at end of file diff --git a/lib/flowplayer/player.rb b/lib/flowplayer/player.rb index ff10088..8206e5d 100644 --- a/lib/flowplayer/player.rb +++ b/lib/flowplayer/player.rb @@ -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 EOS diff --git a/lib/flowplayer/railtie.rb b/lib/flowplayer/railtie.rb index 9715b33..a626448 100644 --- a/lib/flowplayer/railtie.rb +++ b/lib/flowplayer/railtie.rb @@ -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 \ No newline at end of file diff --git a/lib/flowplayer/railties/generator/install_generator.rb b/lib/flowplayer/railties/generator/install_generator.rb new file mode 100644 index 0000000..e7394a8 --- /dev/null +++ b/lib/flowplayer/railties/generator/install_generator.rb @@ -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 \ No newline at end of file diff --git a/lib/flowplayer/railties/helper.rb b/lib/flowplayer/railties/helper.rb new file mode 100644 index 0000000..c5e3c61 --- /dev/null +++ b/lib/flowplayer/railties/helper.rb @@ -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 \ No newline at end of file diff --git a/spec/flowplayer_spec.rb b/spec/flowplayer_spec.rb index a10b42b..246cbdd 100644 --- a/spec/flowplayer_spec.rb +++ b/spec/flowplayer_spec.rb @@ -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 - ["", "flowplayer(\"my_video\", #{flow_player.to_js}"].each do |part| + ["", "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