github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

marcandre / swf_fu

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 95
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (7)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (7)
    • v1.3.1
    • v1.3.0
    • v1.2.0
    • v1.1.0
    • v1.0.3
    • v1.0.2
    • v1.0.1
Sending Request…
Click here to lend your support to: swf_fu and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Rails plugin: treat your Adobe Flash swf files like any other asset (images, javascripts, etc...) and embed them using SWFObject 2.2 — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

v1.3.1: Compatibility with Rails 3.0: swf_tag now outputs html_safe 
content. 
marcandre (author)
Fri Feb 05 07:40:12 -0800 2010
commit  156431ff470fb6dbdb537ce5c88a57ebb7c8cffb
tree    2009e1e0e0de6b0e1763b6368d8020cee8db5607
parent  8401a39f90bc3e767c1279be7c5a60a9eb9841e1
swf_fu /
name age
history
message
file CHANGELOG.rdoc Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
file FLASH_OBJECT.rdoc Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
file LICENSE Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
file README.rdoc Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
file Rakefile Wed Jan 14 18:47:54 -0800 2009 v1.2.0, with better handling of flashvars (see ... [marcandre]
directory assets/ Sat Jun 20 15:10:36 -0700 2009 Updated to SWFObject v2.2 Change should not be... [marcandre]
file init.rb Fri Jan 02 15:52:58 -0800 2009 File reorganization. Fixed small bug with defau... [marcandre]
file install.rb Thu Dec 25 23:22:52 -0800 2008 Fixed installer [marcandre]
directory lib/ Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
directory test/ Fri Feb 05 07:46:04 -0800 2010 v1.3.1: Compatibility with Rails 3.0: swf_tag n... [marcandre]
file uninstall.rb Thu Dec 25 23:22:52 -0800 2008 Fixed installer [marcandre]
README.rdoc

swf_fu

With the swf_fu plugin, rails treats your swf files like any other asset (images, javascripts, etc…).

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. 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 code.google.com/p/swfobject

swf_fu has been tested with rails v2.0 up to v3.0b and has decent test coverage so rake test:plugins should reveal any incompatibility. Comments and pull requests welcome: github.com/marcandre/swf_fu

Install

Assuming you have git installed (check with <q>git version</q>), it is easy to install from your applications directory:

  rails plugin install git://github.com/marcandre/swf_fu.git   # rails 3

  script/plugin install git://github.com/marcandre/swf_fu.git  # rails 2 (starting at 2.0.2)

For older versions of rails or without git, you can always download swf_fu from github and then install it manually:

  rails plugin install ~/Download/swf_fu    # rails 3

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

Usage

Embedding in HTML

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 /public/swfs/ unless specified otherwise and it will add the ".swf" extension automatically.

You can specify alternate content either with the options <q>:alt => "Get Flash!"</q> or you can use swf_tag as a block:

  <% swf_tag "i_like_flashing" do %>
    Get Flash
  <% end %>

Options

  • :id - 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
  • :width, :height - the width & height of the Flash object. Defaults to "100%". These could also specified using :size
  • :size - the size of the Flash object, in the form "400x300".
  • :mode - Either :dynamic (default) or :static. Refer to SWFObject’s doc
  • :flashvars - a Hash of variables that are passed to the swf. Can also be a string like "foo=bar&hello=world". Defaults to {:id => the DOM id}
  • :parameters - a Hash of configuration parameters for the swf. See Adobe’s doc
  • :alt - 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.
  • :flash_version - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
  • :auto_install - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by swf_fu)
  • :javascript_class - specify a javascript class (e.g. "MyFlash") for your flash object. If it exists, the initialize method will be called.
  • :initialize - arguments to pass to the initialization method of your javascript class.
  • :div_id - the DOM id of the containing div itself. Defaults to "#{option[:id]}"_div
  • :switch_off_auto_hide_show - 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.

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

Javascript

swf_fu will add ‘swfobject’ to the list of default javascript files. If you don’t include the default javascripts, a simple javascript_include "swfobject" is needed.

swf_path

swf_tag implements and relies on swf_path which behaves in a similar fashion to image_path, javascript_path, etc…:

  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

Copyright © 2010 Marc-AndrĂ© Lafortune, released under the BSD license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server