From 7c1f0e6cf6561482c9aacb882c5baa6717331b79 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Mon, 31 Jan 2011 17:22:47 -0500 Subject: [PATCH] specs passing --- .DS_Store | Bin 0 -> 6148 bytes Gemfile.lock | 2 ++ flowplayer.gemspec | 1 + lib/.DS_Store | Bin 0 -> 6148 bytes lib/flowplayer.rb | 1 + lib/flowplayer/player.rb | 56 ++++++++++++++++++++++++++++++ lib/flowplayer/rails/helper.rb | 19 +++++++++++ lib/flowplayer/railtie.rb | 8 +++++ spec/flowplayer_spec.rb | 60 +++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 10 files changed, 148 insertions(+) create mode 100644 .DS_Store create mode 100644 lib/.DS_Store create mode 100644 lib/flowplayer.rb create mode 100644 lib/flowplayer/player.rb create mode 100644 lib/flowplayer/rails/helper.rb create mode 100644 lib/flowplayer/railtie.rb create mode 100644 spec/flowplayer_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..085e803667c3180224fc208974add50a9dbc954b GIT binary patch literal 6148 zcmeHK%}T>S5T0$TZvBB=M30N-BGn2-@DM@;k3tGPSkZ(C4TPpNDLuq!d?BB~r|@~4 z*D-T_hcKAl zYMuxAEc1e?_FM<~2tAtj(== 1.0.0) flowplayer! + json mocha nokogiri rspec (~> 2.0.0) diff --git a/flowplayer.gemspec b/flowplayer.gemspec index 23dac1a..e7b37cb 100644 --- a/flowplayer.gemspec +++ b/flowplayer.gemspec @@ -23,5 +23,6 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 2.0.0" s.add_development_dependency "nokogiri" s.add_development_dependency "mocha" + s.add_development_dependency "json" end diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + // + + EOS + end + + private + + def functions_to_javascript + functions.map {|option, function| "\"#{option}\":#{function}"} + end + + def options_to_javascript + options.map do |option, value| + if value.is_a?(String) + "\"#{option}\":\"#{value.to_json}\"" + else + "\"#{option}\":#{value.to_json}" + end + end + end + + def method_missing(method, *args, &block) + raise "Setters are not supported use method('whatever') to set configs" if /\=$/.match(method.to_s) + if block.nil? + options[method] = args.first + else + functions[method] = "function() { #{block.call.gsub(/\;$/, '')}; }" + end + return method + end + + end +end \ No newline at end of file diff --git a/lib/flowplayer/rails/helper.rb b/lib/flowplayer/rails/helper.rb new file mode 100644 index 0000000..78b91e9 --- /dev/null +++ b/lib/flowplayer/rails/helper.rb @@ -0,0 +1,19 @@ +module Flowplayer + module Helpers + + # flowplayer_for :hubble do |f| + # f.option 'foo' + # f.onLoad do + # 'this.unmute();' + # end + + + + + + def flowplayer_for(id, swf, &block) + FlowPlayer::Player.new(id, swf, &block).script_tags + end + + end +end \ No newline at end of file diff --git a/lib/flowplayer/railtie.rb b/lib/flowplayer/railtie.rb new file mode 100644 index 0000000..9715b33 --- /dev/null +++ b/lib/flowplayer/railtie.rb @@ -0,0 +1,8 @@ +module Flowplayer + require 'rails' + class Railtie < ::Rails::Railtie + generators do + require File.join(File.expand_path('../', __FILE__), 'railties', 'generators', 'compass_theme', 'compass_theme_generator.rb') + end + end +end \ No newline at end of file diff --git a/spec/flowplayer_spec.rb b/spec/flowplayer_spec.rb new file mode 100644 index 0000000..a10b42b --- /dev/null +++ b/spec/flowplayer_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Flowplayer::Player do + it "should set options from block" do + flow_player = Flowplayer::Player.new('my_video') do |player| + player.fullscreen true + player.logo(:url => nil, :opacity => 0, :fullscreenOnly => true) + player.onLoad do + 'this.unmute();' + end + end + + flow_player.options[:fullscreen].should == true + flow_player.functions[:onLoad].should == 'function() { this.unmute(); }' + flow_player.options[:logo].should be_an(Hash) + + end + + it "should set the dom_id to 'my_video'" do + flow_player = Flowplayer::Player.new('my_video') 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| + player.fullscreen true + player.logo({:opacity => 0, :fullscreenOnly => true}) + player.onLoad do + 'this.unmute();' + end + end + flow_player.to_js.should include 'fullscreen' + flow_player.to_js.should match /^\{.+\}$/ + flow_player.to_js.should include({:opacity => 0, :fullscreenOnly => true}.to_json) + end + + it "should create script tags with options" do + flow_player = Flowplayer::Player.new('my_video') 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| + flow_player.script_tags.should include part + end + end + + it "should raise exception if passed a setter" do + lambda do + flow_player = Flowplayer::Player.new('my_video') do |player| + player.fullscreen = true + end + end.should raise_error + end + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..79f7869 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require File.expand_path('../../lib/flowplayer', __FILE__) \ No newline at end of file