swf-guess 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +29 -0
  3. data/README.rdoc +94 -0
  4. data/Rakefile +38 -0
  5. data/app/assets/javascripts/swf_fu.js.coffee +7 -0
  6. data/app/assets/javascripts/swfobject.js +4 -0
  7. data/app/assets/swfs/expressInstall.swf +0 -0
  8. data/app/helpers/swf_fu_helper.rb +55 -0
  9. data/app/models/swf_fu/generator.rb +140 -0
  10. data/lib/swf_fu.rb +15 -0
  11. data/lib/swf_fu/version.rb +3 -0
  12. data/lib/tasks/swf_fu_tasks.rake +4 -0
  13. data/test/dummy/Gemfile +38 -0
  14. data/test/dummy/Gemfile.lock +117 -0
  15. data/test/dummy/README.rdoc +261 -0
  16. data/test/dummy/Rakefile +7 -0
  17. data/test/dummy/app/assets/images/rails.png +0 -0
  18. data/test/dummy/app/assets/javascripts/application.js +16 -0
  19. data/test/dummy/app/assets/javascripts/example.js.coffee +9 -0
  20. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  21. data/test/dummy/app/assets/swfs/example.swf +0 -0
  22. data/test/dummy/app/assets/swfs/source/Example.as +26 -0
  23. data/test/dummy/app/assets/swfs/source/example.fla +0 -0
  24. data/test/dummy/app/controllers/application_controller.rb +5 -0
  25. data/test/dummy/app/helpers/application_helper.rb +2 -0
  26. data/test/dummy/app/views/application/example.html.erb +7 -0
  27. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/test/dummy/config.ru +4 -0
  29. data/test/dummy/config/application.rb +67 -0
  30. data/test/dummy/config/boot.rb +6 -0
  31. data/test/dummy/config/database.yml +25 -0
  32. data/test/dummy/config/environment.rb +5 -0
  33. data/test/dummy/config/environments/development.rb +37 -0
  34. data/test/dummy/config/environments/production.rb +67 -0
  35. data/test/dummy/config/environments/test.rb +37 -0
  36. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  37. data/test/dummy/config/initializers/inflections.rb +15 -0
  38. data/test/dummy/config/initializers/mime_types.rb +5 -0
  39. data/test/dummy/config/initializers/secret_token.rb +7 -0
  40. data/test/dummy/config/initializers/session_store.rb +8 -0
  41. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  42. data/test/dummy/config/locales/en.yml +5 -0
  43. data/test/dummy/config/routes.rb +58 -0
  44. data/test/dummy/db/development.sqlite3 +0 -0
  45. data/test/dummy/db/production.sqlite3 +0 -0
  46. data/test/dummy/db/seeds.rb +7 -0
  47. data/test/dummy/db/test.sqlite3 +0 -0
  48. data/test/dummy/doc/README_FOR_APP +2 -0
  49. data/test/dummy/log/development.log +68 -0
  50. data/test/dummy/log/production.log +666 -0
  51. data/test/dummy/log/test.log +395 -0
  52. data/test/dummy/public/404.html +26 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +25 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/dummy/public/robots.txt +5 -0
  57. data/test/dummy/script/rails +6 -0
  58. data/test/dummy/test/test_helper.rb +13 -0
  59. data/test/dummy/tmp/cache/assets/C4D/E10/sprockets%2Fc047976633a340cdce345035269560f4 +0 -0
  60. data/test/dummy/tmp/cache/assets/C7D/5D0/sprockets%2Fa50a564d1a39a5058679294d142b259d +0 -0
  61. data/test/dummy/tmp/cache/assets/CA5/7E0/sprockets%2F405243a95c7fe62c5f1e13384bd52007 +0 -0
  62. data/test/dummy/tmp/cache/assets/CD0/400/sprockets%2Fe939b3c887723847718bef9263b545fe +0 -0
  63. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  64. data/test/dummy/tmp/cache/assets/CEC/8F0/sprockets%2Fda530500a7f58a5049b41df99e7784e9 +0 -0
  65. data/test/dummy/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
  66. data/test/dummy/tmp/cache/assets/D0C/F20/sprockets%2F25319c41bf6665cc6f9ceb161d9055a0 +0 -0
  67. data/test/dummy/tmp/cache/assets/D1B/B70/sprockets%2F264d8ed9497d7df507e761a240016fde +0 -0
  68. data/test/dummy/tmp/cache/assets/D1D/090/sprockets%2F309c8b49c8b56c65a4f528745bf2e3c6 +0 -0
  69. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  70. data/test/dummy/tmp/cache/assets/D41/740/sprockets%2F414358cbdcf6fbb7d59c54ea24824407 +0 -0
  71. data/test/dummy/tmp/cache/assets/D42/580/sprockets%2F1c45ae7a3cffe91e16b5364466531d8e +0 -0
  72. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  73. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  74. data/test/dummy/tmp/cache/assets/D5E/410/sprockets%2F0c6df3662a1326977ba1fb520cedb17a +0 -0
  75. data/test/dummy/tmp/cache/assets/D71/FD0/sprockets%2F3b1ada17db7b9fae7d40d971226385f9 +0 -0
  76. data/test/dummy/tmp/cache/assets/D83/1B0/sprockets%2F0106065ad8a5142ec6e805cabda5d1ae +0 -0
  77. data/test/dummy/tmp/cache/assets/DAA/3D0/sprockets%2F40a1f8ebd3c717ece6ec73c673871e8e +0 -0
  78. data/test/dummy/tmp/cache/assets/DCD/4B0/sprockets%2Fefe3fa2f4d5970fe935c56eadd20131c +0 -0
  79. data/test/dummy/tmp/cache/assets/DD9/1F0/sprockets%2Fe9f37f4cdf34aa6f149790ccead56d15 +0 -0
  80. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  81. data/test/dummy/tmp/cache/assets/DF6/300/sprockets%2F6818827aaaafddb35bc386d1c6cbd40e +0 -0
  82. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  83. data/test/dummy/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
  84. data/test/dummy/tmp/cache/assets/E6D/DA0/sprockets%2F753c6b9fddf2dffb5f978cd1ae50cda8 +0 -0
  85. data/test/support/assert_same_striped.rb +9 -0
  86. data/test/support/fixtures/results.rb +41 -0
  87. data/test/swf_path_test.rb +35 -0
  88. data/test/swf_tag_test.rb +95 -0
  89. data/test/test_helper.rb +12 -0
  90. metadata +249 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc11d051bbd92d08caa381b851ffeb2ef6c5b266
4
+ data.tar.gz: 71868fc62b31f58d0db173f1ddf65cf0533a3651
5
+ SHA512:
6
+ metadata.gz: 8ab60c479120237a0636710d09cb06a3d972936c09b6518c02ea2d1a17c292c12a49e286a09f9c366ba036fe1a6a887e9f3882c6fe24b377e2f48553b6c0172d
7
+ data.tar.gz: e4b22459db3331c5f8f40ca1a7509f0ea48f16b02bc4c538f40670adc4aabfa8e21825a74078478e4b1e03bf4a74c0323ddcae0e5209aa2bcda414af875cf6bb
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.2 (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,94 @@
1
+ = +swf_fu+ {<img src="https://travis-ci.org/marcandre/swf_fu.png?branch=master">}[https://travis-ci.org/marcandre/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
+ Comments and pull requests welcome: http://github.com/marcandre/swf_fu
10
+
11
+ == Compatibility
12
+
13
+ Version 2 of +swf_fu+ is an engine for Rails 3.1+ and Ruby 1.8.7+.
14
+
15
+ Version 1.x was a plugin for previous versions of Rails and should not be used with Rails 3.1+. If you want to use it, checkout the v1.x branch[https://github.com/marcandre/swf_fu/tree/v1.x]. If you are upgrading to Rails 3.1+, remove the plugin!
16
+
17
+ == Install
18
+
19
+ Add to your +Gemfile+:
20
+
21
+ gem "swf_fu", "~> 2.0"
22
+
23
+ Then run `bundle install`.
24
+
25
+ You also need to require some javascripts, so in your `app/assets/javascripts/application.js` you want to append:
26
+
27
+ \\= require swf_fu
28
+
29
+ == Usage
30
+
31
+ === Embedding in HTML
32
+
33
+ To embed a swf file, use +swf_tag+:
34
+ <%= swf_tag "i_like_flashing" %>
35
+
36
+ Exactly like images and javascripts, +swf_tag+ will use +swf_path+
37
+ to determine the path of the swf file; it will assume it is in <tt>/assets/swfs/</tt> or in <tt>/public/swfs/</tt>
38
+ unless specified otherwise and it will add the ".swf" extension automatically.
39
+
40
+ You can specify alternate content either with the options <tt>:alt => "Get Flash!"</tt> or you can use +swf_tag+ as a block:
41
+
42
+ <% swf_tag "i_like_flashing" do %>
43
+ Get Flash
44
+ <% end %>
45
+
46
+ === Options
47
+
48
+ * <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+
49
+ * <tt>:width, :height</tt> - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
50
+ * <tt>:size</tt> - the size of the Flash object, in the form "400x300".
51
+ * <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?]
52
+ * <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>
53
+ * <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]
54
+ * <tt>:html_options</tt> - a Hash of extra html options for the <tt>object</tt> tag.
55
+ * <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.
56
+ * <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
57
+ * <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by +swf_fu+)
58
+ * <tt>:javascript_class</tt> - specify a javascript class (e.g. "MyFlash") for your flash object. If it exists, the +initialize+ method will be called. See the 'dummy' example in the test folder
59
+ * <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
60
+ * <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}_div"</tt>
61
+ * <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.
62
+
63
+ You can override these default options with a global setting:
64
+
65
+ ActionView::Base.swf_default_options = {:mode => :static} # All swf_tag will use the static mode by default
66
+
67
+ In your config files, you can write this as:
68
+
69
+ config.action_view.swf_default_options = {:mode => :static} # All swf_tag will use the static mode by default
70
+
71
+ Any of these options can be a +Proc+, in which case it will be called each time swf_tag is called.
72
+
73
+ For example, the following will generate unique IDs:
74
+
75
+ my_swf_counter = 0
76
+ config.action_view.swf_default_options[:id] = Proc.new{"swf_unique_id_#{my_swf_counter+=1}"}
77
+
78
+ === swf_path
79
+
80
+ +swf_tag+ implements and relies on +swf_path+ which behaves in a similar fashion to +image_path+, +javascript_path+, etc...:
81
+
82
+ swf_path("example") => "/swfs/example.swf" or "/assets/example.swf"
83
+ swf_path("example.swf") => "/swfs/example.swf" or "/assets/example.swf"
84
+ swf_path("fonts/optima") => "/swfs/fonts/optima.swf" or "/assets/fonts/optima.swf"
85
+ swf_path("/fonts/optima") => "/fonts/optima.swf"
86
+ swf_path("http://www.example.com/game.swf") => "http://www.example.com/game.swf"
87
+
88
+ It takes into account the global setting +asset_host+, like any other asset:
89
+
90
+ ActionController::Base.asset_host = "http://assets.example.com"
91
+ image_path("logo.jpg") => "http://assets.example.com/images/logo.jpg"
92
+ swf_path("fonts/optima") => "http://assets.example.com/swfs/fonts/optima.swf"
93
+
94
+ Copyright (c) 2010-2013 Marc-André Lafortune, released under the BSD license
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Swf Fu'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ #= require_tree .
2
+
3
+ @SwfFu =
4
+ setup: (object, klass, init_args) ->
5
+ object extends klass.prototype
6
+ object.initialize?(init_args...)
7
+ null
@@ -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,55 @@
1
+ module SwfFuHelper
2
+ # Returns a set of tags that display a Flash object within an
3
+ # HTML page.
4
+ #
5
+ # Options:
6
+ # * <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+
7
+ # * <tt>:width, :height</tt> - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
8
+ # * <tt>:size</tt> - the size of the Flash object, in the form "400x300".
9
+ # * <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?]
10
+ # * <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>
11
+ # * <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]
12
+ # * <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.
13
+ # * <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
14
+ # * <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by swf_fu)
15
+ # * <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.
16
+ # * <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
17
+ # * <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}"_div</tt>
18
+ #
19
+ def swf_tag(source, options={}, &block)
20
+ ::SwfFu::Generator.new(source, options, self).generate(&block)
21
+ end
22
+
23
+
24
+ # Computes the path to an swf asset in the public 'swfs' directory.
25
+ # Full paths from the document root will be passed through.
26
+ # Used internally by +swf_tag+ to build the swf path.
27
+ #
28
+ # ==== Examples
29
+ # swf_path("example") # => /swfs/example.swf
30
+ # swf_path("example.swf") # => /swfs/example.swf
31
+ # swf_path("fonts/optima") # => /swfs/fonts/optima.swf
32
+ # swf_path("/fonts/optima") # => /fonts/optima.swf
33
+ # swf_path("http://www.example.com/game.swf") # => http://www.example.com/game.swf
34
+ #
35
+ # It takes into account the global setting +asset_host+, like any other asset:
36
+ #
37
+ # ActionController::Base.asset_host = "http://assets.example.com"
38
+ # image_path("logo.jpg") # => http://assets.example.com/images/logo.jpg
39
+ # swf_path("fonts/optima") # => http://assets.example.com/swfs/fonts/optima.swf
40
+ def swf_path(source)
41
+ if respond_to? :path_to_asset
42
+ path_to_asset(source, :ext => 'swf')
43
+ else
44
+ asset_paths.compute_public_path(source, 'swfs', :ext => 'swf')
45
+ end
46
+ end
47
+ alias_method :path_to_swf, :swf_path # aliased to avoid conflicts with an image_path named route
48
+
49
+ # Computes the full URL to a swf asset in the public swf directory.
50
+ # This will use +swf_path+ internally, so most of their behaviors will be the same.
51
+ def swf_url(source)
52
+ URI.join(current_host, path_to_swf(source)).to_s
53
+ end
54
+ alias_method :url_to_swf, :swf_url # aliased to avoid conflicts with an swf_url named route
55
+ end
@@ -0,0 +1,140 @@
1
+ module SwfFu
2
+ DEFAULTS = {
3
+ :width => "100%",
4
+ :height => "100%",
5
+ :flash_version => 7,
6
+ :mode => :dynamic,
7
+ :auto_install => "expressInstall",
8
+ :alt => <<-"EOS".squeeze(" ").strip.freeze
9
+ <a href="//www.adobe.com/go/getflashplayer">
10
+ <img src="//www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
11
+ </a>
12
+ EOS
13
+ }.freeze
14
+
15
+ class Generator # :nodoc:
16
+ VALID_MODES = [:static, :dynamic]
17
+ def initialize(source, options, view)
18
+ @view = view
19
+ @source = view.swf_path(source)
20
+ options = ActionView::Base.swf_default_options.merge(options)
21
+ options.each do |key, value|
22
+ options[key] = value.call(source) if value.respond_to?(:call)
23
+ end
24
+ [:html_options, :parameters, :flashvars].each do |k|
25
+ options[k] = convert_to_hash(options[k]).reverse_merge convert_to_hash(ActionView::Base.swf_default_options[k])
26
+ end
27
+ options.reverse_merge!(DEFAULTS)
28
+ options[:id] ||= source.gsub(/^.*\//, '').gsub(/\.swf$/,'')
29
+ options[:id] = force_to_valid_id(options[:id])
30
+ options[:div_id] ||= options[:id]+"_div"
31
+ options[:div_id] = force_to_valid_id(options[:div_id])
32
+ options[:width], options[:height] = options[:size].scan(/^(\d*%?)x(\d*%?)$/).first if options[:size]
33
+ options[:auto_install] &&= @view.swf_path(options[:auto_install])
34
+ options[:flashvars][:id] ||= options[:id]
35
+ @mode = options.delete(:mode)
36
+ @options = options
37
+ unless VALID_MODES.include? @mode
38
+ raise ArgumentError, "options[:mode] should be either #{VALID_MODES.join(' or ')}"
39
+ end
40
+ end
41
+
42
+ def force_to_valid_id(id)
43
+ id = id.gsub /[^A-Za-z0-9\-_]/, "_" # HTML id can only contain these characters
44
+ id = "swf_" + id unless id =~ /^[A-Z]/i # HTML id must start with alpha
45
+ id
46
+ end
47
+
48
+ def generate(&block)
49
+ @options[:alt] = @view.capture(&block) if block_given?
50
+ send(@mode)
51
+ end
52
+
53
+ private
54
+ def convert_to_hash(s)
55
+ case s
56
+ when Hash
57
+ s
58
+ when nil
59
+ {}
60
+ when String
61
+ s.split("&").inject({}) do |h, kvp|
62
+ key, value = kvp.split("=")
63
+ h[key.to_sym] = CGI::unescape(value)
64
+ h
65
+ end
66
+ else
67
+ raise ArgumentError, "#{s} should be a Hash, a String or nil"
68
+ end
69
+ end
70
+
71
+ def convert_to_string(h)
72
+ h.map do |key_value|
73
+ key_value.map{|val| CGI::escape(val.to_s)}.join("=")
74
+ end.join("&")
75
+ end
76
+
77
+ def static
78
+ param_list = @options[:parameters].map{|k,v| %(<param name="#{k}" value="#{v}"/>) }.join("\n")
79
+ param_list += %(\n<param name="flashvars" value="#{convert_to_string(@options[:flashvars])}"/>) unless @options[:flashvars].empty?
80
+ html_options = @options[:html_options].map{|k,v| %(#{k}="#{v}")}.join(" ")
81
+ r = @view.javascript_tag(
82
+ %(swfobject.registerObject("#{@options[:id]}_container", "#{@options[:flash_version]}", #{convert_to_escaped_arguments(@options[:auto_install])});)
83
+ )
84
+ r << <<-"EOS".strip.html_safe
85
+ <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}>
86
+ <param name="movie" value="#{@source}" />
87
+ #{param_list}
88
+ <!--[if !IE]>-->
89
+ <object type="application/x-shockwave-flash" data="#{@source}" width="#{@options[:width]}" height="#{@options[:height]}" id="#{@options[:id]}">
90
+ #{param_list}
91
+ <!--<![endif]-->
92
+ #{@options[:alt]}
93
+ <!--[if !IE]>-->
94
+ </object>
95
+ <!--<![endif]-->
96
+ </object></div>
97
+ EOS
98
+ r << @view.javascript_tag(extend_js) if @options[:javascript_class]
99
+ r << library_check
100
+ r
101
+ end
102
+
103
+ def dynamic
104
+ @options[:html_options] = @options[:html_options].merge(:id => @options[:id])
105
+ @options[:parameters] = @options[:parameters].dup # don't modify the original parameters
106
+ args = convert_to_escaped_arguments(@source,
107
+ *(@options.values_at(:div_id,:width,:height,:flash_version).map(&:to_s) +
108
+ @options.values_at(:auto_install,:flashvars,:parameters,:html_options))
109
+ )
110
+ args << ", #{@options[:callback]}" if @options[:callback]
111
+
112
+ preambule = @options[:switch_off_auto_hide_show] ? "swfobject.switchOffAutoHideShow();" : ""
113
+ r = @view.javascript_tag(preambule + "swfobject.embedSWF(#{args})")
114
+ r << @view.content_tag("div", @options[:alt].html_safe, :id => @options[:div_id])
115
+ r << @view.javascript_tag("swfobject.addDomLoadEvent(function(){#{extend_js}})") if @options[:javascript_class]
116
+ r << library_check
117
+ r
118
+ end
119
+
120
+ def convert_to_escaped_arguments(*values)
121
+ # Note: Rails used to escape <>& but it's now a setting
122
+ values.map(&:to_json).join(",").gsub('>', '\u003E').gsub('<', '\u003C').gsub('&', '\u0026')
123
+ end
124
+
125
+ def extend_js
126
+ args = @options[:initialize]
127
+ args = [args] unless args.is_a?(Array)
128
+ "SwfFu.setup($('##{@options[:id]}')[0], #{@options[:javascript_class]}, [#{convert_to_escaped_arguments(*args)}])"
129
+ end
130
+
131
+ def library_check
132
+ return "" unless 'development' == ENV['RAILS_ENV']
133
+ @view.javascript_tag(<<-"EOS")
134
+ if (typeof swfobject == 'undefined') {
135
+ document.getElementById('#{@options[:div_id]}').innerHTML = '<strong>Warning:</strong> SWFObject.js was not loaded properly. Make sure you require "swfobject" in your main javascript file.';
136
+ }
137
+ EOS
138
+ end
139
+ end #class Generator
140
+ end
data/lib/swf_fu.rb ADDED
@@ -0,0 +1,15 @@
1
+ module SwfFu
2
+ class Engine < Rails::Engine
3
+ # Thanks to http://robots.thoughtbot.com/post/159805560/tips-for-writing-your-own-rails-engine for:
4
+ config.to_prepare do
5
+ ActionView::Helpers.class_eval { include SwfFuHelper }
6
+ end
7
+ # Thanks to http://jonswope.com/2010/07/25/rails-3-engines-plugins-and-static-assets/ for:
8
+ initializer "static assets" do |app|
9
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
10
+ end
11
+ end
12
+
13
+ ::ActionView::Base.cattr_accessor :swf_default_options
14
+ ::ActionView::Base.swf_default_options = {}
15
+ end
@@ -0,0 +1,3 @@
1
+ module SwfFu
2
+ VERSION = '2.0.4'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :swf_fu do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,38 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.6'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ # gem 'sqlite3'
9
+
10
+ # Gems used only for assets and not required
11
+ # in production environments by default.
12
+ group :assets do
13
+ gem 'sass-rails', '~> 3.2.3'
14
+ gem 'coffee-rails', '~> 3.2.1'
15
+
16
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
17
+ # gem 'therubyracer', :platforms => :ruby
18
+
19
+ gem 'uglifier', '>= 1.0.3'
20
+ end
21
+
22
+ gem 'jquery-rails'
23
+
24
+ gem 'swf_fu', :path => "../.."
25
+ # To use ActiveModel has_secure_password
26
+ # gem 'bcrypt-ruby', '~> 3.0.0'
27
+
28
+ # To use Jbuilder templates for JSON
29
+ # gem 'jbuilder'
30
+
31
+ # Use unicorn as the app server
32
+ # gem 'unicorn'
33
+
34
+ # Deploy with Capistrano
35
+ # gem 'capistrano'
36
+
37
+ # To use debugger
38
+ # gem 'debugger'