swf_fu 1.3.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/README.rdoc +30 -50
  2. data/Rakefile +38 -0
  3. data/app/assets/javascripts/swf_fu.js.coffee +7 -0
  4. data/{assets → app/assets}/javascripts/swfobject.js +0 -0
  5. data/app/helpers/swf_fu_helper.rb +51 -0
  6. data/app/models/swf_fu/generator.rb +139 -0
  7. data/lib/swf_fu.rb +15 -2
  8. data/lib/swf_fu/version.rb +3 -0
  9. data/lib/tasks/swf_fu_tasks.rake +4 -0
  10. data/test/dummy/README.rdoc +261 -0
  11. data/test/dummy/Rakefile +7 -0
  12. data/test/dummy/app/assets/javascripts/application.js +16 -0
  13. data/test/dummy/app/assets/javascripts/example.js.coffee +9 -0
  14. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  15. data/test/dummy/app/controllers/application_controller.rb +5 -0
  16. data/test/dummy/app/helpers/application_helper.rb +2 -0
  17. data/test/dummy/app/views/application/example.html.erb +7 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/config.ru +4 -0
  20. data/test/dummy/config/application.rb +56 -0
  21. data/test/dummy/config/boot.rb +10 -0
  22. data/test/dummy/config/database.yml +25 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +37 -0
  25. data/test/dummy/config/environments/production.rb +67 -0
  26. data/test/dummy/config/environments/test.rb +37 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +15 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  33. data/test/dummy/config/locales/en.yml +5 -0
  34. data/test/dummy/config/routes.rb +58 -0
  35. data/test/dummy/db/development.sqlite3 +0 -0
  36. data/test/dummy/db/test.sqlite3 +0 -0
  37. data/test/dummy/log/development.log +2861 -0
  38. data/test/dummy/log/test.log +1002 -0
  39. data/test/dummy/public/404.html +26 -0
  40. data/test/dummy/public/422.html +26 -0
  41. data/test/dummy/public/500.html +25 -0
  42. data/test/dummy/public/favicon.ico +0 -0
  43. data/test/dummy/public/swfs/example.swf +0 -0
  44. data/test/dummy/public/swfs/source/Example.as +26 -0
  45. data/test/dummy/public/swfs/source/example.fla +0 -0
  46. data/test/dummy/script/rails +6 -0
  47. data/test/dummy/tmp/cache/assets/C14/440/sprockets%2F7165b4ee637490447887e423298985d7 +0 -0
  48. data/test/dummy/tmp/cache/assets/CC9/940/sprockets%2F384b7526ce19a1676cf839c97e283d65 +0 -0
  49. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  50. data/test/dummy/tmp/cache/assets/D21/B30/sprockets%2F3c26aead77064197ac98a91d4c46f879 +0 -0
  51. data/test/dummy/tmp/cache/assets/D2B/260/sprockets%2F85f8be26166cf70b5d954fff37a42987 +0 -0
  52. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  53. data/test/dummy/tmp/cache/assets/D41/740/sprockets%2F414358cbdcf6fbb7d59c54ea24824407 +0 -0
  54. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  55. data/test/dummy/tmp/cache/assets/D4F/590/sprockets%2Ff4f8bbee986218b7a2173c69ca28429e +0 -0
  56. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  57. data/test/dummy/tmp/cache/assets/D68/4F0/sprockets%2F448bbac6b7407ae050c726c3491fde6d +0 -0
  58. data/test/dummy/tmp/cache/assets/DB2/170/sprockets%2Fc6c10bc26cb025a7b1beb05c24198fae +0 -0
  59. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  60. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  61. data/test/dummy/tmp/cache/assets/E1E/4F0/sprockets%2Fefa070e0f1ca299bc30dad1ff1b196ee +0 -0
  62. data/test/dummy/tmp/cache/assets/E6D/DA0/sprockets%2F753c6b9fddf2dffb5f978cd1ae50cda8 +0 -0
  63. data/test/dummy/tmp/pids/server.pid +1 -0
  64. data/test/support/assert_same_striped.rb +8 -0
  65. data/test/{results.rb → support/fixtures/results.rb} +5 -6
  66. data/test/swf_path_test.rb +35 -0
  67. data/test/swf_tag_test.rb +93 -0
  68. data/test/test_helper.rb +9 -18
  69. metadata +220 -85
  70. data/CHANGELOG.rdoc +0 -45
  71. data/FLASH_OBJECT.rdoc +0 -31
  72. data/VERSION +0 -1
  73. data/assets/swfs/expressInstall.swf +0 -0
  74. data/lib/action_view/helpers/asset_tag_helper/swf_asset.rb +0 -61
  75. data/lib/action_view/helpers/swf_fu_helper.rb +0 -184
  76. data/lib/swf_fu/tasks.rb +0 -72
  77. data/rails/init.rb +0 -11
  78. data/tasks/rails.rake +0 -1
  79. data/test/swf_fu_test.rb +0 -131
@@ -1,45 +0,0 @@
1
- = swf_fu --- History
2
-
3
- == Version 1.3.2 - February 19, 2010
4
- * Packaged the plugin as a gem [Marcus Wyatt]
5
-
6
- == Version 1.3.1 - February 5, 2010
7
-
8
- * Improved compatibility with Rails 3.0: swf_tag now outputs html_safe content.
9
-
10
- * Got rid of deprecation warning in Rails 2.2+ when using swf_tag in block form.
11
-
12
- == Version 1.3.0 - June 20, 2009
13
-
14
- * Updated to swf_object v2.2. Change should not be noticeable to users, except compatibility improvements and better auto install. Added the option +switch_off_auto_hide_show+.
15
-
16
- == Version 1.2.0 - January 14, 2009
17
-
18
- * flashvars[:id] will now default to the DOM id of the object. I didn't want to have any extra defaults than the very basic ones, but there is no easy way to get this from Flash (see http://www.actionscript.org/forums/showthread.php3?t=136044 ) and no easy way to specify that using +swf_default_options+.
19
- * If flashvars is a string (e.g. "myVar=myValue") it will be parsed into a hash so that the behaviour for default values apply to strings or hashes. swf_default_options[:flashvars] can also be a string and will also be parsed before being merged.
20
- * Small bug fix: the options passed as hashes (:flashvars, :parameters and :html_options) were changed if swf_default_options[:flashvars, ...] existed. They are now left unchanged.
21
-
22
- == Version 1.1.0 - January 3, 2009
23
-
24
- * Improved the way to specify alternate content
25
-
26
- == Version 1.0.3 - January 3, 2009
27
-
28
- * Improved javascript initialization
29
-
30
- :initialize => [1, 2, 3] # produces in javascript: obj.initialize(1,2,3) instead of ([1,2,3])
31
- # no :initialize produces in javascript: obj.initialize() instead of (null)
32
- :initialize => nil # stil produces obj.initialize(null)
33
-
34
- == Version 1.0.2 - January 3, 2009
35
-
36
- * Bug fix for flashvars in dynamic method
37
-
38
- == Version 1.0.1 - January 2, 2009
39
-
40
- * File reorganization
41
- * Bug fix for default options
42
-
43
- == Version 1.0 - X-mas, 2008
44
-
45
- === Initial release.
@@ -1,31 +0,0 @@
1
- == Compatibility with FlashObject
2
-
3
- This document is intended for users of FlashObject, a (much older) swf embedding plugin that inspired swf_fu.
4
-
5
- You can choose to:
6
-
7
- 1) keep both. They won't interfere and +flashobject_tag+ will continue to use the older SWFObject 1.5 library.
8
-
9
- 2) remove FlashObject:
10
-
11
- script/plugin remove flashobject_helper
12
-
13
- You can also manually remove <tt>javascripts/flashobject.js</tt>
14
-
15
- +swf_fu+ will take over the +flashobject_tag+ and will use the new SWFObject 2.2 library.
16
- This should not have impacts as long as:
17
- * your swf path is absolute (e.g. "/path/to/my_flash.swf"). If it is relative, move your swf file from 'public/' to the new 'public/swfs/' asset folder
18
- * you include the default javascripts (otherwise you need to include 'swfobject' explicitely and stop including 'flashobject')
19
- * you don't use the javascript object before the page is loaded. SWFObject 2.2 makes the changes to the web page later
20
- * you don't rely on the +verify_file_exists+ option (it doesn't do anything anymore)
21
-
22
- In either case 1 or 2, you change existing calls to +flashobject_tag+ for +swf_tag+ at your leisure.
23
- The interface is similar and the main differences are some options name changes:
24
- :flash_id => :id
25
- :variables => :flashvars
26
- :background_color => options[:parameters][:bgcolor]
27
-
28
- Moreover, the following defaults are gone:
29
- :flashvars[:lzproxied]
30
- :parameters[:scale]
31
- :parameters[:bgcolor]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.3.3
@@ -1,61 +0,0 @@
1
- module ActionView #:nodoc:
2
-
3
- # <tt>ActionView::Base.swf_default_options</tt> is a hash that
4
- # will be used to specify defaults in priority to the standard
5
- # defaults.
6
- class Base
7
- @@swf_default_options = {}
8
- cattr_accessor :swf_default_options
9
- end
10
-
11
- module Helpers # :nodoc:
12
- module AssetTagHelper
13
-
14
- # Computes the path to an swf asset in the public 'swfs' directory.
15
- # Full paths from the document root will be passed through.
16
- # Used internally by +swf_tag+ to build the swf path.
17
- #
18
- # ==== Examples
19
- # swf_path("example") # => /swfs/example.swf
20
- # swf_path("example.swf") # => /swfs/example.swf
21
- # swf_path("fonts/optima") # => /swfs/fonts/optima.swf
22
- # swf_path("/fonts/optima") # => /fonts/optima.swf
23
- # swf_path("http://www.example.com/game.swf") # => http://www.example.com/game.swf
24
- #
25
- # It takes into account the global setting +asset_host+, like any other asset:
26
- #
27
- # ActionController::Base.asset_host = "http://assets.example.com"
28
- # image_path("logo.jpg") # => http://assets.example.com/images/logo.jpg
29
- # swf_path("fonts/optima") # => http://assets.example.com/swfs/fonts/optima.swf
30
- #
31
- def swf_path(source)
32
- if defined? SwfTag
33
- SwfTag.new(self, @controller, source).public_path
34
- else
35
- compute_public_path(source, SwfAsset::DIRECTORY, SwfAsset::EXTENSION)
36
- end
37
- end
38
- alias_method :path_to_swf, :swf_path # aliased to avoid conflicts with a swf_path named route
39
-
40
- private
41
- module SwfAsset # :nodoc:
42
- DIRECTORY = 'swfs'.freeze
43
- EXTENSION = 'swf'.freeze
44
-
45
- def directory
46
- DIRECTORY
47
- end
48
-
49
- def extension
50
- EXTENSION
51
- end
52
- end
53
-
54
- # AssetTag is available since 2.1.1 (http://github.com/rails/rails/commit/900fd6eca9dd97d2341e89bcb27d7a82d62965bf )
55
- class SwfTag < AssetTag # :nodoc:
56
- include SwfAsset
57
- end if defined? AssetTag
58
- end
59
- end
60
- end
61
-
@@ -1,184 +0,0 @@
1
- module ActionView #:nodoc:
2
- module Helpers # :nodoc:
3
- module SwfFuHelper
4
- # Returns a set of tags that display a Flash object within an
5
- # HTML page.
6
- #
7
- # Options:
8
- # * <tt>:id</tt> - the DOM +id+ of the flash +object+ element that is used to contain the Flash object; defaults to the name of the swf in +source+
9
- # * <tt>:width, :height</tt> - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
10
- # * <tt>:size</tt> - the size of the Flash object, in the form "400x300".
11
- # * <tt>:mode</tt> - Either :dynamic (default) or :static. Refer to SWFObject's doc[http://code.google.com/p/swfobject/wiki/documentation#Should_I_use_the_static_or_dynamic_publishing_method?]
12
- # * <tt>:flashvars</tt> - a Hash of variables that are passed to the swf. Can also be a string like <tt>"foo=bar&hello=world"</tt>
13
- # * <tt>:parameters</tt> - a Hash of configuration parameters for the swf. See Adobe's doc[http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701#optional]
14
- # * <tt>:alt</tt> - HTML text that is displayed when the Flash player is not available. Defaults to a "Get Flash" image pointing to Adobe Flash's installation page.
15
- # * <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
16
- # * <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by swf_fu)
17
- # * <tt>:javascript_class</tt> - specify a javascript class (e.g. "MyFlash") for your flash object. The initialize method will be called when the flash object is ready.
18
- # * <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
19
- # * <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}"_div</tt>
20
- #
21
- def swf_tag(source, options={}, &block)
22
- Generator.new(source, options, self).generate(&block)
23
- end
24
-
25
- # For compatibility with the older FlashObject.
26
- # It modifies the given options before calling +swf_tag+.
27
- # See FLASH_OBJECT.rdoc
28
- def flashobject_tag_for_compatibility(source, options={})
29
- options = options.reverse_merge(
30
- :auto_install => nil,
31
- :parameters => {:scale => "noscale"},
32
- :variables => {:lzproxied => false},
33
- :flash_id => "flashcontent_#{rand(1_100)}",
34
- :background_color => "#ffffff"
35
- )
36
- { :variables => :flashvars, :flash_id => :id }.each{|from, to| options[to] ||= options.delete(from) }
37
- options[:parameters][:bgcolor] ||= options.delete(:background_color)
38
- swf_tag(source, options)
39
- end
40
-
41
- alias_method :flashobject_tag, :flashobject_tag_for_compatibility unless defined? flashobject_tag
42
-
43
- private
44
- DEFAULTS = {
45
- :width => "100%",
46
- :height => "100%",
47
- :flash_version => 7,
48
- :mode => :dynamic,
49
- :auto_install => "expressInstall",
50
- :alt => <<-"EOS".squeeze(" ").strip.freeze
51
- <a href="http://www.adobe.com/go/getflashplayer">
52
- <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
53
- </a>
54
- EOS
55
- }.freeze
56
-
57
- class Generator # :nodoc:
58
- VALID_MODES = [:static, :dynamic]
59
- def initialize(source, options, view)
60
- @view = view
61
- @source = view.swf_path(source)
62
- options = ActionView::Base.swf_default_options.merge(options)
63
- [:html_options, :parameters, :flashvars].each do |k|
64
- options[k] = convert_to_hash(options[k]).reverse_merge convert_to_hash(ActionView::Base.swf_default_options[k])
65
- end
66
- options.reverse_merge!(DEFAULTS)
67
- options[:id] ||= source.gsub(/^.*\//, '').gsub(/\.swf$/,'')
68
- options[:div_id] ||= options[:id]+"_div"
69
- options[:width], options[:height] = options[:size].scan(/^(\d*%?)x(\d*%?)$/).first if options[:size]
70
- options[:auto_install] &&= @view.swf_path(options[:auto_install])
71
- options[:flashvars][:id] ||= options[:id]
72
- @mode = options.delete(:mode)
73
- @options = options
74
- unless VALID_MODES.include? @mode
75
- raise ArgumentError, "options[:mode] should be either #{VALID_MODES.join(' or ')}"
76
- end
77
- end
78
-
79
- def generate(&block)
80
- if block_given?
81
- @options[:alt] = @view.capture(&block)
82
- if Rails::VERSION::STRING < "2.2"
83
- @view.concat(send(@mode), block.binding)
84
- else
85
- @view.concat(send(@mode))
86
- end
87
- else
88
- send(@mode)
89
- end
90
- end
91
-
92
- private
93
- CONCAT = ActiveSupport.const_defined?(:SafeBuffer) ? :safe_concat : :concat
94
- def convert_to_hash(s)
95
- case s
96
- when Hash
97
- s
98
- when nil
99
- {}
100
- when String
101
- s.split("&").inject({}) do |h, kvp|
102
- key, value = kvp.split("=")
103
- h[key.to_sym] = CGI::unescape(value)
104
- h
105
- end
106
- else
107
- raise ArgumentError, "#{s} should be a Hash, a String or nil"
108
- end
109
- end
110
-
111
- def convert_to_string(h)
112
- h.map do |key_value|
113
- key_value.map{|val| CGI::escape(val.to_s)}.join("=")
114
- end.join("&")
115
- end
116
-
117
- def static
118
- param_list = @options[:parameters].map{|k,v| %(<param name="#{k}" value="#{v}"/>) }.join("\n")
119
- param_list += %(\n<param name="flashvars" value="#{convert_to_string(@options[:flashvars])}"/>) unless @options[:flashvars].empty?
120
- html_options = @options[:html_options].map{|k,v| %(#{k}="#{v}")}.join(" ")
121
- r = @view.javascript_tag(
122
- %(swfobject.registerObject("#{@options[:id]}_container", "#{@options[:flash_version]}", #{@options[:auto_install].to_json});)
123
- )
124
- r.send CONCAT, <<-"EOS".strip
125
- <div id="#{@options[:div_id]}"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="#{@options[:width]}" height="#{@options[:height]}" id="#{@options[:id]}_container" #{html_options}>
126
- <param name="movie" value="#{@source}" />
127
- #{param_list}
128
- <!--[if !IE]>-->
129
- <object type="application/x-shockwave-flash" data="#{@source}" width="#{@options[:width]}" height="#{@options[:height]}" id="#{@options[:id]}">
130
- #{param_list}
131
- <!--<![endif]-->
132
- #{@options[:alt]}
133
- <!--[if !IE]>-->
134
- </object>
135
- <!--<![endif]-->
136
- </object></div>
137
- EOS
138
- r << @view.javascript_tag(extend_js) if @options[:javascript_class]
139
- r.send CONCAT, library_check
140
- r
141
- end
142
-
143
- def dynamic
144
- @options[:html_options] = @options[:html_options].merge(:id => @options[:id])
145
- @options[:parameters] = @options[:parameters].dup # don't modify the original parameters
146
- args = (([@source] + @options.values_at(:div_id,:width,:height,:flash_version)).map(&:to_s) +
147
- @options.values_at(:auto_install,:flashvars,:parameters,:html_options)
148
- ).map(&:to_json).join(",")
149
- preambule = @options[:switch_off_auto_hide_show] ? "swfobject.switchOffAutoHideShow();" : ""
150
- r = @view.javascript_tag(preambule + "swfobject.embedSWF(#{args})")
151
- r.send CONCAT, <<-"EOS".strip
152
- <div id="#{@options[:div_id]}">
153
- #{@options[:alt]}
154
- </div>
155
- EOS
156
- r << @view.javascript_tag("swfobject.addDomLoadEvent(function(){#{extend_js}})") if @options[:javascript_class]
157
- r.send CONCAT, library_check
158
- r
159
- end
160
-
161
- def extend_js
162
- arglist = case
163
- when @options[:initialize].instance_of?(Array)
164
- @options[:initialize].map(&:to_json).join(",")
165
- when @options.has_key?(:initialize)
166
- @options[:initialize].to_json
167
- else
168
- ""
169
- end
170
- "Object.extend($('#{@options[:id]}'), #{@options[:javascript_class]}.prototype).initialize(#{arglist})"
171
- end
172
-
173
- def library_check
174
- return "" unless 'development' == ENV['RAILS_ENV']
175
- @view.javascript_tag(<<-"EOS")
176
- if (typeof swfobject == 'undefined') {
177
- document.getElementById('#{@options[:div_id]}').innerHTML = '<strong>Warning:</strong> SWFObject.js was not loaded properly. Make sure you <tt>&lt;%= javascript_include_tag :defaults %&gt;</tt> or <tt>&lt;%= javascript_include_tag :swfobject %&gt;</tt>';
178
- }
179
- EOS
180
- end
181
- end #class Generator
182
- end
183
- end
184
- end
@@ -1,72 +0,0 @@
1
- require 'fileutils'
2
-
3
- namespace :swf do
4
-
5
- task :app_env do
6
- if defined?(RAILS_ROOT)
7
- Rake::Task[:environment].invoke
8
- end
9
- end
10
-
11
- desc "Install swf_fu assets into your rails application"
12
- task :install => :app_env do
13
- if defined?(RAILS_ROOT)
14
- # Some paths
15
- src = File.dirname(__FILE__) + "/../../assets"
16
- dest = RAILS_ROOT + "/public"
17
-
18
- unless File.exist?("#{dest}/javascripts/swfobject.js")
19
- FileUtils.cp "#{src}/javascripts/swfobject.js", "#{dest}/javascripts/swfobject.js"
20
- puts "Copying 'swfobject.js'"
21
- end
22
-
23
- unless File.exist?("#{dest}/swfs/")
24
- FileUtils.mkdir "#{dest}/swfs/"
25
- puts "Creating new 'swfs' directory for swf assets"
26
- end
27
-
28
- unless File.exist?("#{dest}/swfs/expressInstall.swf")
29
- FileUtils.cp "#{src}/swfs/expressInstall.swf", "#{dest}/swfs/expressInstall.swf"
30
- puts "Copying 'expressInstall.swf', the default flash auto-installer."
31
- end
32
-
33
- puts "Installation done."
34
- else
35
- puts "Unable to do installation. We need to be in the root of a Rails Application."
36
- end
37
- end
38
-
39
- task :rm_swfobject do
40
- if defined?(RAILS_ROOT)
41
- begin
42
- FileUtils.rm "#{RAILS_ROOT}/public/javascripts/swfobject.js"
43
- rescue Exception => e
44
- puts "Warning: swfobject.js could not be deleted"
45
- end
46
- end
47
- end
48
-
49
- task :rm_express_install do
50
- if defined?(RAILS_ROOT)
51
- begin
52
- FileUtils.rm "#{RAILS_ROOT}/public/swfs/expressInstall.swf"
53
- rescue Exception => e
54
- puts "Warning: expressInstall.swf could not be deleted"
55
- end
56
- end
57
- end
58
-
59
- task :rm_swf_dir do
60
- if defined?(RAILS_ROOT)
61
- begin
62
- Dir.rmdir "#{RAILS_ROOT}/public/swfs/"
63
- rescue Exception => e
64
- puts "Don't remove swf directory if directory is not empty"
65
- end
66
- end
67
- end
68
-
69
- desc "Uninstall swf_fu assets from your rails application"
70
- task :uninstall => [:app_env, :rm_swfobject, :rm_express_install, :rm_swf_dir]
71
-
72
- end
@@ -1,11 +0,0 @@
1
- require 'action_view/helpers/asset_tag_helper'
2
-
3
- require 'swf_fu'
4
-
5
- # ActionView::Helpers is for recent rails version, ActionView::Base for older ones
6
- # (in which case ActionView::Helpers::AssetTagHelper is also needed for tests...)
7
- ActionView::Helpers.class_eval { include ActionView::Helpers::SwfFuHelper } # For recent rails version...
8
- ActionView::Base.class_eval { include ActionView::Helpers::SwfFuHelper } # ...and for older ones
9
- ActionView::TestCase.class_eval { include ActionView::Helpers::SwfFuHelper } if defined? ActionView::TestCase # ...for tests in older versions
10
-
11
- ActionView::Helpers::AssetTagHelper.register_javascript_include_default 'swfobject'
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '/../lib/swf_fu/tasks')
@@ -1,131 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require File.dirname(__FILE__) + '/results'
3
-
4
- class SwfFuTest < ActionView::TestCase
5
-
6
- def assert_same_stripped(expect, test)
7
- expect, test = [expect, test].map{|s| s.split("\n").map(&:strip)}
8
- same = expect & test
9
- delta_expect, delta_test = [expect, test].map{|a| a-same}
10
- STDOUT << "\n\n---- Actual result: ----\n" << test.join("\n") << "\n---------\n" unless delta_expect == delta_test
11
- assert_equal delta_expect, delta_test
12
- end
13
-
14
- context "swf_path" do
15
- context "with no special asset host" do
16
- should "deduce the extension" do
17
- assert_equal swf_path("example.swf"), swf_path("example")
18
- assert_starts_with "/swfs/example.swf", swf_path("example.swf")
19
- end
20
-
21
- should "accept relative paths" do
22
- assert_starts_with "/swfs/whatever/example.swf", swf_path("whatever/example.swf")
23
- end
24
-
25
- should "leave full paths alone" do
26
- ["/full/path.swf", "http://www.example.com/whatever.swf"].each do |p|
27
- assert_starts_with p, swf_path(p)
28
- end
29
- end
30
- end
31
-
32
- context "with custom asset host" do
33
- HOST = "http://assets.example.com"
34
- setup do
35
- ActionController::Base.asset_host = HOST
36
- end
37
-
38
- teardown do
39
- ActionController::Base.asset_host = nil
40
- end
41
-
42
- should "take it into account" do
43
- assert_equal "#{HOST}/swfs/whatever.swf", swf_path("whatever")
44
- end
45
- end
46
- end
47
-
48
- context "swf_tag" do
49
- COMPLEX_OPTIONS = { :width => "456", :height => 123,
50
- :flashvars => {:myVar => "value 1 > 2"}.freeze,
51
- :javascript_class => "SomeClass",
52
- :initialize => {:be => "good"}.freeze,
53
- :parameters => {:play => true}.freeze
54
- }.freeze
55
-
56
- should "understand size" do
57
- assert_equal swf_tag("hello", :size => "123x456"),
58
- swf_tag("hello", :width => 123, :height => "456")
59
- end
60
-
61
- should "only accept valid modes" do
62
- assert_raise(ArgumentError) { swf_tag("xyz", :mode => :xyz) }
63
- end
64
-
65
- context "with custom defaults" do
66
- setup do
67
- test = {:flashvars=> {:xyz => "abc", :hello => "world"}.freeze, :mode => :static, :size => "400x300"}.freeze
68
- @expect = swf_tag("test", test)
69
- @expect_with_hello = swf_tag("test", :flashvars => {:xyz => "abc", :hello => "my friend"}, :mode => :static, :size => "400x300")
70
- ActionView::Base.swf_default_options = test
71
- end
72
-
73
- should "respect them" do
74
- assert_equal @expect, swf_tag("test")
75
- end
76
-
77
- should "merge suboptions" do
78
- assert_equal @expect_with_hello, swf_tag("test", :flashvars => {:hello => "my friend"}.freeze)
79
- end
80
-
81
- teardown { ActionView::Base.swf_default_options = {} }
82
- end
83
-
84
- context "with static mode" do
85
- setup { ActionView::Base.swf_default_options = {:mode => :static} }
86
-
87
- should "deal with string flashvars" do
88
- assert_equal swf_tag("hello", :flashvars => "xyz=abc", :mode => :static),
89
- swf_tag("hello", :flashvars => {:xyz => "abc"}, :mode => :static)
90
- end
91
-
92
- should "produce the expected code" do
93
- assert_same_stripped STATIC_RESULT, swf_tag("mySwf", COMPLEX_OPTIONS.merge(:html_options => {:class => "lots"}.freeze).freeze)
94
- end
95
-
96
- teardown { ActionView::Base.swf_default_options = {} }
97
- end
98
-
99
- context "with dynamic mode" do
100
- should "produce the expected code" do
101
- assert_same_stripped DYNAMIC_RESULT, swf_tag("mySwf", COMPLEX_OPTIONS)
102
- end
103
-
104
- end
105
-
106
- should "treat initialize arrays as list of parameters" do
107
- assert_match 'initialize("hello","world")', swf_tag("mySwf", :initialize => ["hello", "world"], :javascript_class => "SomeClass")
108
- end
109
- end
110
-
111
- context "flashobject_tag" do
112
- should "be the same as swf_tag with different defaults" do
113
- assert_same_stripped swf_tag("mySwf",
114
- :auto_install => nil,
115
- :parameters => {:scale => "noscale", :bgcolor => "#ffffff"},
116
- :flashvars => {:lzproxied => false},
117
- :id => "myFlash"
118
- ), flashobject_tag("mySwf", :flash_id => "myFlash")
119
- end
120
-
121
- should "be the same with custom settings" do
122
- assert_same_stripped swf_tag("mySwf",
123
- :auto_install => nil,
124
- :parameters => {:scale => "noborder", :bgcolor => "#ffffff"},
125
- :flashvars => {:answer_is => 42},
126
- :id => "myFlash"
127
- ), flashobject_tag("mySwf", :flash_id => "myFlash", :parameters => {:scale => "noborder"}, :variables => {:answer_is => 42})
128
- end
129
- end
130
- end
131
-