Module: SwfFuHelper

Defined in:
app/helpers/swf_fu_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) swf_path(source) Also known as: path_to_swf

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


40
41
42
43
44
45
46
# File 'app/helpers/swf_fu_helper.rb', line 40

def swf_path(source)
  if respond_to? :path_to_asset
    path_to_asset(source, :ext => 'swf')
  else
    asset_paths.compute_public_path(source, 'swfs', :ext => 'swf')
  end
end

- (Object) swf_tag(source, options = {}, &block)

Returns a set of tags that display a Flash object within an HTML page.

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"

  • :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.

  • :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. The initialize method will be called when the flash object is ready.

  • :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



19
20
21
# File 'app/helpers/swf_fu_helper.rb', line 19

def swf_tag(source, options={}, &block)
  ::SwfFu::Generator.new(source, options, self).generate(&block)
end

- (Object) swf_url(source) Also known as: url_to_swf

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.



51
52
53
# File 'app/helpers/swf_fu_helper.rb', line 51

def swf_url(source)
  URI.join(current_host, path_to_swf(source)).to_s
end