Module: ActionView::Helpers::FlexObjectHelper::InstanceMethods
- Defined in:
- lib/flexobject_view_helper.rb
Instance Method Summary collapse
-
#flexobject_path(source) ⇒ Object
Returns a path to a Flash object.
-
#flexobject_tags(source, options = {}) ⇒ Object
Returns a set of tags that display a Flash object within an HTML page.
-
#flexobject_version(options = {}) ⇒ Object
Returns a set of tags that display a Flash object within an HTML page.
Instance Method Details
#flexobject_path(source) ⇒ Object
Returns a path to a Flash object. The src
can be supplied as:
-
a full path, such as “/swfs/flex_scaffold/phones.swf”
-
a file name such “phones.swf”
-
a file name without an extension, such as “phones”
22 23 24 |
# File 'lib/flexobject_view_helper.rb', line 22 def flexobject_path source compute_public_path source, File.join('swfs', FlexScaffold::Config.plugin_name), 'swf' end |
#flexobject_tags(source, options = {}) ⇒ Object
Returns a set of tags that display a Flash object within an HTML page.
Options:
-
:div_id
- the HTMLid
of thediv
element that is used to contain the Flash object; default “flashcontent” -
:flash_id
- theid
of the Flash object itself. -
:background_color
- the background color of the Flash object; default white -
:flash_version
- the version of the Flash player that is required; default “7.0.0” -
:size
- the size of the Flash object, in the form “100x100”. Defaults to “100%x100%” -
:variables
- a Hash of initialization variables that are passed to the object; default{:lzproxied => false}
-
:parameters
- a Hash of parameters that configure the display of the object; default{:scale => 'noscale'}
-
:fallback_html
- HTML text that is displayed when the Flash player is not available.
The following options are for developers. They default to true in development mode, and false otherwise.
-
:check_for_javascript_include
- if true, the return value will cause the browser to display a diagnostic message if the FlashObject JavaScript was not included. -
:verify_file_exists
- if true, the return value will cause the browser to display a diagnostic message if the Flash object does not exist.
(This method is called flexobject_tags instead of flashobject_tag because it returns a sequence of HTML tags: a div
, followed by a script
.)
It is also renamed to flex rather than the original flash so that there are not naming clashes if you use openLaszlo at the same time.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/flexobject_view_helper.rb', line 50 def source, ={} path = flexobject_path source #TODO check why RAILS_ROOT is not absolute #verify_file_exists = options.fetch(:verify_file_exists, ENV['RAILS_ENV'] == 'development') #if verify_file_exists and not File.exists?(File.join(RAILS_ROOT, 'public', path)) # return "<div><strong>Warning:</strong> The file <code>#{File.join('public', path)}</code> does not exist. Did you forget to execute <tt>rake flex:compile</tt>?</div>" #end div_id = [:div_id] || 'flashcontent' flash_id = [:flash_id] || File.basename(source, '.swf') width, height = ([:size]||'100%x100%').scan(/^(\d*%?)x(\d*%?)$/).first background_color = [:background_color] || '#ffffff' flash_version = [:flash_version] || "7.0.0" variables = .fetch(:variables, {:lzproxied => false}) parameters = .fetch(:parameters, {:scale => 'noscale'}) fallback_html = [:fallback_html] || %q{<p>Requires the Flash plugin. If the plugin is already installed, click <a href="?detectflash=false">here</a>.</p>} if .fetch(:check_for_javascript_include, ENV['RAILS_ENV'] == 'development') check_for_javascript ="if (typeof FlashObject == 'undefined') document.getElementById('#{div_id}').innerHTML = '<strong>Warning:</strong> FlashObject is undefined. Did you forget to execute <tt>rake update_javascripts</tt>, or to include <tt><%= javascript_include_tag :defaults %></tt> in your view file?';" end return <<-"EOF" <div id="#{div_id}" style="height:#{height}; width:#{width}"> #{fallback_html} </div> <script type="text/javascript">//<![CDATA[ #{check_for_javascript} var fo = new FlashObject("#{path}", "#{flash_id}", "#{width}", "#{height}", "#{flash_version}", "#{background_color}"); #{parameters.map{|k,v|%Q[fo.addVariable("#{k}", "#{v}");]}.join("\n")} #{variables.map{|k,v|%Q[fo.addVariable("#{k}", "#{v}");]}.join("\n")} fo.write("#{div_id}"); //]]> </script> EOF end |
#flexobject_version(options = {}) ⇒ Object
Returns a set of tags that display a Flash object within an HTML page. Defaults to v9.0.0
Options:
-
:major
- default to version 9 -
:minor
- default to 0 -
:revision
- default to 0
Example output:
<script language="JavaScript" type="text/javascript">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------
// -->
</script>
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/flexobject_view_helper.rb', line 107 def flexobject_version ={} major = [:major] || 9 minor = [:minor] || 0 revision = [:revision] || 0 return <<-"EOF" <script language="JavaScript" type="text/javascript">//<![CDATA[ var requiredMajorVersion = #{major}; var requiredMinorVersion = #{minor}; var requiredRevision = #{revision}; //]]> </script> EOF end |