Skip to content

Commit

Permalink
v2.0: Engine for Rails 3.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Mar 21, 2012
1 parent 564673e commit c47419d
Show file tree
Hide file tree
Showing 64 changed files with 1,381 additions and 550 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,9 @@
= swf_fu --- History

== Version 2.0.0 - March 20, 2012

* Refactored in an engine. Rails 3.1+ compatibility only.

== Version 1.4.0 - May 8, 2010

* Any option can be a block, in which case it is called (with the source swf passed as argument)
Expand Down
31 changes: 0 additions & 31 deletions FLASH_OBJECT.rdoc

This file was deleted.

17 changes: 17 additions & 0 deletions Gemfile
@@ -0,0 +1,17 @@
source "http://rubygems.org"

# Declare your gem's dependencies in swf_fu.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
107 changes: 107 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,107 @@
PATH
remote: .
specs:
swf_fu (2.0.0)
coffee-script
rails (~> 3.1)

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.2)
actionpack (= 3.2.2)
mail (~> 2.4.0)
actionpack (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activerecord (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.2)
actionmailer (= 3.2.2)
actionpack (= 3.2.2)
activerecord (= 3.2.2)
activeresource (= 3.2.2)
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
shoulda-context (1.0.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.32)

PLATFORMS
ruby

DEPENDENCIES
coffee-script
jquery-rails
shoulda-context
sqlite3
swf_fu!
36 changes: 17 additions & 19 deletions README.rdoc
Expand Up @@ -6,22 +6,21 @@ With the +swf_fu+ plugin, rails treats your swf files like any other asset (imag
SWFObject 2 is such a nice library that Adobe now uses it as the official way to embed swf!
SWFObject's project can be found at http://code.google.com/p/swfobject

+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
Version 2 of +swf_fu+ is an engine for Rails 3.1+ and Ruby 1.8.7+. Use version 1.x for previous versions of Rails.

== Install
Comments and pull requests welcome: http://github.com/marcandre/swf_fu

Assuming you have git[http://git-scm.com/] installed (check with <tt>git version</tt>), it is easy to install from your applications directory:
== Install

rails plugin install git://github.com/marcandre/swf_fu.git # rails 3
Add to your +Gemfile+:

script/plugin install git://github.com/marcandre/swf_fu.git # rails 2 (starting at 2.0.2)
gem "swf_fu", "~> 2.0"

For older versions of +rails+ or without +git+, you can always download
+swf_fu+ from github[http://github.com/marcandre/swf_fu/archives/master] and then install it manually:
Then run `bundle install`.

rails plugin install ~/Download/swf_fu # rails 3
You also need to require some javascripts, so in your `app/assets/javascripts/application.js` you want to append:

script/plugin install ~/Downloads/swf_fu # rails 2.x
\\= require swf_fu

== Usage

Expand All @@ -31,7 +30,7 @@ To embed a swf file, use +swf_tag+:
<%= swf_tag "i_like_flashing" %>

Exactly like images and javascripts, +swf_tag+ will use +swf_path+
to determine the path of the swf file; it will assume it is in <tt>/public/swfs/</tt>
to determine the path of the swf file; it will assume it is in <tt>/assets/swfs/</tt> or in <tt>/public/swfs/</tt>
unless specified otherwise and it will add the ".swf" extension automatically.

You can specify alternate content either with the options <tt>:alt => "Get Flash!"</tt> or you can use +swf_tag+ as a block:
Expand All @@ -52,7 +51,7 @@ You can specify alternate content either with the options <tt>:alt => "Get Flash
* <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.
* <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
* <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by +swf_fu+)
* <tt>:javascript_class</tt> - specify a javascript class (e.g. "MyFlash") for your flash object. If it exists, the initialize method will be called.
* <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
* <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
* <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}_div"</tt>
* <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.
Expand All @@ -61,17 +60,16 @@ You can override these default options with a global setting:

ActionView::Base.swf_default_options = {:mode => :static} # All swf_tag will use the static mode by default

In your config files, you can write this as:

config.action_view.swf_default_options = {:mode => :static} # All swf_tag will use the static mode by default

Any of these options can be a +Proc+, in which case it will be called each time swf_tag is called.

For example, the following will generate unique IDs:

my_swf_counter = 0
ActionView::Base.swf_default_options[:id] = Proc.new{"swf_unique_id_#{my_swf_counter+=1}"}

=== Javascript

+swf_fu+ will add 'swfobject' to the list of default javascript files. If you don't include
the default javascripts, a simple <tt>javascript_include "swfobject"</tt> is needed.
config.action_view.swf_default_options[:id] = Proc.new{"swf_unique_id_#{my_swf_counter+=1}"}

=== swf_path

Expand All @@ -87,6 +85,6 @@ It takes into account the global setting +asset_host+, like any other asset:

ActionController::Base.asset_host = "http://assets.example.com"
image_path("logo.jpg") => "http://assets.example.com/images/logo.jpg"
swf_path("fonts/optima") => "http://assets.example.com/swfs/fonts/optima.swf""
swf_path("fonts/optima") => "http://assets.example.com/swfs/fonts/optima.swf"

Copyright (c) 2010 Marc-André Lafortune, released under the BSD license
Copyright (c) 2010-2012 Marc-André Lafortune, released under the BSD license
46 changes: 31 additions & 15 deletions Rakefile
@@ -1,22 +1,38 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Swf Fu'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end


desc 'Default: run unit tests.'
task :default => :test

desc 'Test the swf_fu plugin.'

Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
t.verbose = false
end

desc 'Generate documentation for the swf_fu plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Swf Fu'
rdoc.options << '--line-numbers' << '--inline-source' << '-m README.rdoc'
rdoc.rdoc_files.include('*.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

task :default => :test
7 changes: 7 additions & 0 deletions app/assets/javascripts/swf_fu.js.coffee
@@ -0,0 +1,7 @@
#= require_tree .

@SwfFu =
setup: (object, klass, init_args) ->
object extends klass.prototype
object.initialize?(init_args...)
null
File renamed without changes.
51 changes: 51 additions & 0 deletions app/helpers/swf_fu_helper.rb
@@ -0,0 +1,51 @@
module SwfFuHelper
# Returns a set of tags that display a Flash object within an
# HTML page.
#
# Options:
# * <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+
# * <tt>:width, :height</tt> - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
# * <tt>:size</tt> - the size of the Flash object, in the form "400x300".
# * <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?]
# * <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>
# * <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]
# * <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.
# * <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
# * <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by swf_fu)
# * <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.
# * <tt>:initialize</tt> - arguments to pass to the initialization method of your javascript class.
# * <tt>:div_id</tt> - the DOM +id+ of the containing div itself. Defaults to <tt>"#{option[:id]}"_div</tt>
#
def swf_tag(source, options={}, &block)
::SwfFu::Generator.new(source, options, self).generate(&block)
end


# Computes the path to an swf asset in the public 'swfs' directory.
# Full paths from the document root will be passed through.
# Used internally by +swf_tag+ to build the swf path.
#
# ==== Examples
# swf_path("example") # => /swfs/example.swf
# swf_path("example.swf") # => /swfs/example.swf
# swf_path("fonts/optima") # => /swfs/fonts/optima.swf
# swf_path("/fonts/optima") # => /fonts/optima.swf
# swf_path("http://www.example.com/game.swf") # => http://www.example.com/game.swf
#
# It takes into account the global setting +asset_host+, like any other asset:
#
# ActionController::Base.asset_host = "http://assets.example.com"
# image_path("logo.jpg") # => http://assets.example.com/images/logo.jpg
# swf_path("fonts/optima") # => http://assets.example.com/swfs/fonts/optima.swf
def swf_path(source)
asset_paths.compute_public_path(source, 'swfs', :ext => 'swf')
end
alias_method :path_to_swf, :swf_path # aliased to avoid conflicts with an image_path named route

# Computes the full URL to a swf asset in the public swf directory.
# This will use +swf_path+ internally, so most of their behaviors will be the same.
def swf_url(source)
URI.join(current_host, path_to_swf(source)).to_s
end
alias_method :url_to_swf, :swf_url # aliased to avoid conflicts with an swf_url named route
end

0 comments on commit c47419d

Please sign in to comment.