Module: SwfobjectHelper
- Defined in:
- app/helpers/swfobject_helper.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options for the #swfobject helper.
{ :width => "100%", :height => "100%", :version => "9.0.0", :partial => "shared/swfobject" }
- DEFAULT_PARAMS =
Default <param> tags.
{ :allowfullscreen => true, :allowscriptaccess => "always", :wmode => "transparent" }
Instance Method Summary collapse
-
#swf_path(source) ⇒ Object
Computes the path to a SWF file in the assets pipeline.
-
#swf_tag(file, options = {}, &block) ⇒ Object
(also: #swfobject)
Generates static embed HTML using the method recommend here: code.google.com/p/swfobject/wiki/documentation.
Instance Method Details
#swf_path(source) ⇒ Object
Computes the path to a SWF file in the assets pipeline. If the source
filename has no extension, .swf will be appended (except for explicit URIs) Full paths from the document root will be passed through. Used internally by #swf_tag to build the path to the SWF file.
Examples
swf_path "file" # => /assets/file.swf
swf_path "dir/file.swf" # => /assets/dir/file.swf
swf_path "/dir/file.swf" # => /dir/file.swf
swf_path "http://www.example.com/file" # => http://www.example.com/file
swf_path "http://www.example.com/file.swf" # => http://www.example.com/file.swf
84 85 86 87 |
# File 'app/helpers/swfobject_helper.rb', line 84 def swf_path(source) source = source + ".swf" if source !~ /^http/ && File.extname(source) == "" asset_path(source) end |
#swf_tag(file, options = {}, &block) ⇒ Object Also known as: swfobject
Generates static embed HTML using the method recommend here: code.google.com/p/swfobject/wiki/documentation
file
is the path to the SWF. Alternate content can be used by passing a block
Other Options:
* <tt>:id</tt> - The ID on the outer <object> tag. Defaults to
an underscored version of the filename.
* <tt>:width</tt> - The width of the SWF. Defaults to "100%".
* <tt>:height</tt> - The height of the SWF. Defaults to "100%".
* <tt>:version</tt> - The minimum version of the Flash player required.
Defaults to "9.0.0".
* <tt>:params</tt> - A hash of parameters to configure the SWF. Will be used
to generate <param> tags. Defaults to DEFAULT_PARAMS.
* <tt>:flashvars</tt> - A hash of variables to send to the flash file. Will
be sent using an encoded value in a <param> tag.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/swfobject_helper.rb', line 36 def swf_tag(file, = {}, &block) = .reverse_merge(DEFAULT_OPTIONS) # Get path to asset file = swf_path(file) # Extract params from options params = .delete(:params) || {} params.reverse_merge!(DEFAULT_PARAMS) # Extract flashvars and add to params if flashvars = .delete(:flashvars) params[:flashvars] = flashvars.to_query end # Generate ID from file if necessary id = .delete(:id) || File.basename(file, File.extname(file)).underscore # Extract other specific options version = .delete(:version) partial = .delete(:partial) alt_content = .delete(:alternate_content) alt_content = capture(&block) if block_given? # And finally, render the partial render partial, :file => file, :id => id, :version => version, :params => params, :attributes => , :alternate_content => alt_content end |