swf_fu 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +45 -0
- data/FLASH_OBJECT.rdoc +31 -0
- data/LICENSE +29 -0
- data/README.rdoc +84 -0
- data/VERSION +1 -0
- data/assets/javascripts/swfobject.js +4 -0
- data/assets/swfs/expressInstall.swf +0 -0
- data/lib/action_view/helpers/asset_tag_helper/swf_asset.rb +61 -0
- data/lib/action_view/helpers/swf_fu_helper.rb +184 -0
- data/lib/swf_fu/tasks.rb +64 -0
- data/lib/swf_fu.rb +2 -0
- data/rails/init.rb +14 -0
- data/tasks/rails.rake +1 -0
- data/test/results.rb +42 -0
- data/test/swf_fu_test.rb +131 -0
- data/test/test_helper.rb +21 -0
- metadata +91 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
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.
|
data/FLASH_OBJECT.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
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/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# swf_fu plugin for rails
|
2
|
+
# Copyright (c) 2010, Marc-André Lafortune.
|
3
|
+
# All rights reserved.
|
4
|
+
# Inspired by FlashObject by Davide D'Agostino aka DAddYE (http://www.lipsiasoft.com)
|
5
|
+
# Uses SWFObject.js 2.1 (http://code.google.com/p/swfobject)
|
6
|
+
#
|
7
|
+
# Licensed under the terms of the (modified) BSD License below:
|
8
|
+
#
|
9
|
+
# Redistribution and use in source and binary forms, with or without
|
10
|
+
# modification, are permitted provided that the following conditions are met:
|
11
|
+
# * Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
# * Redistributions in binary form must reproduce the above copyright
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
16
|
+
# * Neither the name of the <organization> nor the
|
17
|
+
# names of its contributors may be used to endorse or promote products
|
18
|
+
# derived from this software without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY
|
21
|
+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
24
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
27
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= +swf_fu+
|
2
|
+
|
3
|
+
With the +swf_fu+ plugin, rails treats your swf files like any other asset (images, javascripts, etc...).
|
4
|
+
|
5
|
+
+swf_fu+ (pronounced "swif-fu", bonus joke for french speakers) uses SWFObject 2.2 to embed swf objects in HTML and supports all its options.
|
6
|
+
SWFObject 2 is such a nice library that Adobe now uses it as the official way to embed swf!
|
7
|
+
SWFObject's project can be found at http://code.google.com/p/swfobject
|
8
|
+
|
9
|
+
+swf_fu+ has been tested with rails v2.0 up to v3.0b and has decent test coverage so <tt>rake test:plugins</tt> should reveal any incompatibility. Comments and pull requests welcome: http://github.com/marcandre/swf_fu
|
10
|
+
|
11
|
+
== Install
|
12
|
+
|
13
|
+
Assuming you have git[http://git-scm.com/] installed (check with <q>git version</q>), it is easy to install from your applications directory:
|
14
|
+
|
15
|
+
rails plugin install git://github.com/marcandre/swf_fu.git # rails 3
|
16
|
+
|
17
|
+
script/plugin install git://github.com/marcandre/swf_fu.git # rails 2 (starting at 2.0.2)
|
18
|
+
|
19
|
+
For older versions of +rails+ or without +git+, you can always download
|
20
|
+
+swf_fu+ from github[http://github.com/marcandre/swf_fu/archives/master] and then install it manually:
|
21
|
+
|
22
|
+
rails plugin install ~/Download/swf_fu # rails 3
|
23
|
+
|
24
|
+
script/plugin install ~/Downloads/swf_fu # rails 2.x
|
25
|
+
|
26
|
+
== Usage
|
27
|
+
|
28
|
+
=== Embedding in HTML
|
29
|
+
|
30
|
+
To embed a swf file, use +swf_tag+:
|
31
|
+
<%= swf_tag "i_like_flashing" %>
|
32
|
+
|
33
|
+
Exactly like images and javascripts, +swf_tag+ will use +swf_path+
|
34
|
+
to determine the path of the swf file; it will assume it is in <tt>/public/swfs/</tt>
|
35
|
+
unless specified otherwise and it will add the ".swf" extension automatically.
|
36
|
+
|
37
|
+
You can specify alternate content either with the options <q>:alt => "Get Flash!"</q> or you can use +swf_tag+ as a block:
|
38
|
+
|
39
|
+
<% swf_tag "i_like_flashing" do %>
|
40
|
+
Get Flash
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
=== Options
|
44
|
+
|
45
|
+
* <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+
|
46
|
+
* <tt>:width, :height</tt> - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
|
47
|
+
* <tt>:size</tt> - the size of the Flash object, in the form "400x300".
|
48
|
+
* <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?]
|
49
|
+
* <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>. Defaults to <tt>{:id => the DOM id}</tt>
|
50
|
+
* <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]
|
51
|
+
* <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. This can also be specified as a block (see embedding section). In Rails 3, this text is _assumed_ to be HTML, so there is no need to call +html_safe+ on it.
|
52
|
+
* <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
|
53
|
+
* <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by +swf_fu+)
|
54
|
+
* <tt>:javascript_class</tt> - specify a javascript class (e.g. "MyFlash") for your flash object. If it exists, the initialize method will be called.
|
55
|
+
* <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
|
56
|
+
* <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}"_div</tt>
|
57
|
+
* <tt>:switch_off_auto_hide_show</tt> - switch off SWFObject's default hide/show behavior. SWFObject temporarily hides your SWF or alternative content until the library has decided which content to display. Defaults to nil.
|
58
|
+
|
59
|
+
You can override these default options with a global setting:
|
60
|
+
|
61
|
+
ActionView::Base.swf_default_options = {:mode => :static} # All swf_tag will use the static mode by default
|
62
|
+
|
63
|
+
=== Javascript
|
64
|
+
|
65
|
+
+swf_fu+ will add 'swfobject' to the list of default javascript files. If you don't include
|
66
|
+
the default javascripts, a simple <tt>javascript_include "swfobject"</tt> is needed.
|
67
|
+
|
68
|
+
=== swf_path
|
69
|
+
|
70
|
+
+swf_tag+ implements and relies on +swf_path+ which behaves in a similar fashion to +image_path+, +javascript_path+, etc...:
|
71
|
+
|
72
|
+
swf_path("example") => /swfs/example.swf
|
73
|
+
swf_path("example.swf") => /swfs/example.swf
|
74
|
+
swf_path("fonts/optima") => /swfs/fonts/optima.swf
|
75
|
+
swf_path("/fonts/optima") => /fonts/optima.swf
|
76
|
+
swf_path("http://www.example.com/game.swf") => http://www.example.com/game.swf
|
77
|
+
|
78
|
+
It takes into account the global setting +asset_host+, like any other asset:
|
79
|
+
|
80
|
+
ActionController::Base.asset_host = "http://assets.example.com"
|
81
|
+
image_path("logo.jpg") => http://assets.example.com/images/logo.jpg
|
82
|
+
swf_path("fonts/optima") => http://assets.example.com/swfs/fonts/optima.swf
|
83
|
+
|
84
|
+
Copyright (c) 2010 Marc-André Lafortune, released under the BSD license
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.2
|
@@ -0,0 +1,4 @@
|
|
1
|
+
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
2
|
+
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
3
|
+
*/
|
4
|
+
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
Binary file
|
@@ -0,0 +1,61 @@
|
|
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
|
+
|
@@ -0,0 +1,184 @@
|
|
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><%= javascript_include_tag :defaults %></tt> or <tt><%= javascript_include_tag :swfobject %></tt>';
|
178
|
+
}
|
179
|
+
EOS
|
180
|
+
end
|
181
|
+
end #class Generator
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
data/lib/swf_fu/tasks.rb
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
+
puts RAILS_ROOT + "/public"
|
17
|
+
dest = RAILS_ROOT + "/public"
|
18
|
+
|
19
|
+
filename = "#{dest}/javascripts/swfobject.js"
|
20
|
+
unless File.exist?(filename)
|
21
|
+
FileUtils.cp "#{src}/javascripts/swfobject.js", filename
|
22
|
+
puts "Copying 'swfobject.js'"
|
23
|
+
end
|
24
|
+
|
25
|
+
unless File.exist?("#{dest}/swfs/")
|
26
|
+
FileUtils.mkdir "#{dest}/swfs/"
|
27
|
+
puts "Creating new 'swfs' directory for swf assets"
|
28
|
+
end
|
29
|
+
|
30
|
+
filename = "#{dest}/swfs/expressInstall.swf"
|
31
|
+
unless File.exist?(filename)
|
32
|
+
FileUtils.cp "#{src}/swfs/expressInstall.swf", filename
|
33
|
+
puts "Copying 'expressInstall.swf', the default flash auto-installer."
|
34
|
+
end
|
35
|
+
puts "Installation done."
|
36
|
+
else
|
37
|
+
puts "Unable to do installation. We need to be in the root of a Rails Application."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Uninstall swf_fu assets from your rails application"
|
42
|
+
task :uninstall => :app_env do
|
43
|
+
if defined?(RAILS_ROOT)
|
44
|
+
dest = RAILS_ROOT + "/public"
|
45
|
+
begin
|
46
|
+
FileUtils.rm "#{dest}/javascripts/swfobject.js"
|
47
|
+
rescue Exception => e
|
48
|
+
puts "Warning: swfobject.js could not be deleted"
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
FileUtils.rm "#{dest}/swfs/expressInstall.swf"
|
52
|
+
rescue Exception => e
|
53
|
+
puts "Warning: expressInstall.swf could not be deleted"
|
54
|
+
end
|
55
|
+
begin
|
56
|
+
Dir.rmdir "#{dest}/swfs/"
|
57
|
+
rescue Exception => e
|
58
|
+
puts "Don't remove swf directory if directory is not empty"
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts "Unable to do uninstal. We need to be in the root of a Rails Application."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/swf_fu.rb
ADDED
data/rails/init.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path|
|
2
|
+
$LOAD_PATH.unshift path
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'action_view/helpers/asset_tag_helper'
|
6
|
+
|
7
|
+
require 'swf_fu'
|
8
|
+
|
9
|
+
# ActionView::Helpers is for recent rails version, ActionView::Base for older ones (in which case ActionView::Helpers::AssetTagHelper is also needed for tests...)
|
10
|
+
ActionView::Helpers.class_eval { include ActionView::Helpers::SwfFuHelper } # For recent rails version...
|
11
|
+
ActionView::Base.class_eval { include ActionView::Helpers::SwfFuHelper } # ...and for older ones
|
12
|
+
ActionView::TestCase.class_eval { include ActionView::Helpers::SwfFuHelper } if defined? ActionView::TestCase # ...for tests in older versions
|
13
|
+
|
14
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_include_default 'swfobject'
|
data/tasks/rails.rake
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../lib/swf_fu/tasks')
|
data/test/results.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
DYNAMIC_RESULT = <<'EOS'
|
2
|
+
<script type="text/javascript">
|
3
|
+
//<![CDATA[
|
4
|
+
swfobject.embedSWF("/swfs/mySwf.swf","mySwf_div","456","123","7","/swfs/expressInstall.swf",{"myVar":"value 1 \u003E 2","id":"mySwf"},{"play":true},{"id":"mySwf"})
|
5
|
+
//]]>
|
6
|
+
</script><div id="mySwf_div">
|
7
|
+
<a href="http://www.adobe.com/go/getflashplayer">
|
8
|
+
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
|
9
|
+
</a>
|
10
|
+
</div><script type="text/javascript">
|
11
|
+
//<![CDATA[
|
12
|
+
swfobject.addDomLoadEvent(function(){Object.extend($('mySwf'), SomeClass.prototype).initialize({"be":"good"})})
|
13
|
+
//]]>
|
14
|
+
</script>
|
15
|
+
EOS
|
16
|
+
|
17
|
+
STATIC_RESULT = <<'EOS'
|
18
|
+
<script type="text/javascript">
|
19
|
+
//<![CDATA[
|
20
|
+
swfobject.registerObject("mySwf_container", "7", "/swfs/expressInstall.swf");
|
21
|
+
//]]>
|
22
|
+
</script><div id="mySwf_div"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="456" height="123" id="mySwf_container" class="lots">
|
23
|
+
<param name="movie" value="/swfs/mySwf.swf" />
|
24
|
+
<param name="play" value="true"/>
|
25
|
+
<param name="flashvars" value="myVar=value+1+%3E+2&id=mySwf"/>
|
26
|
+
<!--[if !IE]>-->
|
27
|
+
<object type="application/x-shockwave-flash" data="/swfs/mySwf.swf" width="456" height="123" id="mySwf">
|
28
|
+
<param name="play" value="true"/>
|
29
|
+
<param name="flashvars" value="myVar=value+1+%3E+2&id=mySwf"/>
|
30
|
+
<!--<![endif]-->
|
31
|
+
<a href="http://www.adobe.com/go/getflashplayer">
|
32
|
+
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
|
33
|
+
</a>
|
34
|
+
<!--[if !IE]>-->
|
35
|
+
</object>
|
36
|
+
<!--<![endif]-->
|
37
|
+
</object></div><script type="text/javascript">
|
38
|
+
//<![CDATA[
|
39
|
+
Object.extend($('mySwf'), SomeClass.prototype).initialize({"be":"good"})
|
40
|
+
//]]>
|
41
|
+
</script>
|
42
|
+
EOS
|
data/test/swf_fu_test.rb
ADDED
@@ -0,0 +1,131 @@
|
|
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
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'activesupport', '~> 2.3'
|
4
|
+
require 'active_support'
|
5
|
+
gem 'activerecord', '~> 2.3'
|
6
|
+
require 'active_record'
|
7
|
+
gem 'actionpack', '~> 2.3'
|
8
|
+
require 'active_support'
|
9
|
+
require 'action_view'
|
10
|
+
require 'action_controller'
|
11
|
+
|
12
|
+
#require File.dirname(__FILE__)+'/../../../../config/environment.rb'
|
13
|
+
require 'action_view/test_case'
|
14
|
+
require "action_controller/test_process"
|
15
|
+
require 'shoulda'
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/../rails/init'
|
18
|
+
|
19
|
+
def assert_starts_with(start, what)
|
20
|
+
assert what.starts_with?(start), "#{what} does not start with #{start}"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swf_fu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Marc-Andr\xC3\xA9 Lafortune"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-19 00:00:00 +13:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
swf_fu (pronounced "swif-fu", bonus joke for french speakers) uses SWFObject 2.2 to embed swf objects in HTML and supports all its options.
|
27
|
+
SWFObject 2 is such a nice library that Adobe now uses it as the official way to embed swf!
|
28
|
+
SWFObject's project can be found at http://code.google.com/p/swfobject
|
29
|
+
|
30
|
+
swf_fu has been tested with rails v2.0 up to v3.0b and has decent test coverage so <tt>rake test:plugins</tt> should reveal any incompatibility. Comments and pull requests welcome: http://github.com/marcandre/swf_fu
|
31
|
+
email: marcus.wyatt@visfleet.com
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files:
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
files:
|
40
|
+
- CHANGELOG.rdoc
|
41
|
+
- FLASH_OBJECT.rdoc
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
- VERSION
|
45
|
+
- assets/javascripts/swfobject.js
|
46
|
+
- assets/swfs/expressInstall.swf
|
47
|
+
- lib/action_view/helpers/asset_tag_helper/swf_asset.rb
|
48
|
+
- lib/action_view/helpers/swf_fu_helper.rb
|
49
|
+
- lib/swf_fu.rb
|
50
|
+
- lib/swf_fu/tasks.rb
|
51
|
+
- rails/init.rb
|
52
|
+
- tasks/rails.rake
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/marcus-wyatt/swf_fu
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message: |+
|
58
|
+
|
59
|
+
swf_fu has rake tasks to install and uninstall the assets required
|
60
|
+
when running within a rails project. To enable the rake tasks, add
|
61
|
+
the following require to your Rakefile:
|
62
|
+
|
63
|
+
require 'swf_fu/tasks'
|
64
|
+
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: With the swf_fu gem, rails treats your swf files like any other asset (images, javascripts, etc...).
|
88
|
+
test_files:
|
89
|
+
- test/results.rb
|
90
|
+
- test/swf_fu_test.rb
|
91
|
+
- test/test_helper.rb
|