Module: SwfobjectHelper

Defined in:
app/helpers/swfobject_helper.rb

Instance Method Summary collapse

Instance Method Details

#swf_path(source) ⇒ Object



3
4
5
# File 'app/helpers/swfobject_helper.rb', line 3

def swf_path(source)
  asset_path(source)
end

#swf_tag(name, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/swfobject_helper.rb', line 7

def swf_tag(name, options = {})
  width = height = nil
  if options[:size]
    width, height = options[:size].split("x")
  else
    width = options.delete(:width)
    height = options.delete(:height)
  end

  if options[:flashvars]
    # we need to urlencode flashvars, see question 9 at
    # http://code.google.com/p/swfobject/wiki/faq
    flashvars = {}
    options[:flashvars].each_pair do |k, v|
      flashvars[CGI.escape(k.to_s)] = CGI.escape(v.to_s)
    end
  else
    flashvars = options[:flashvars]
  end

  code = "swfobject.embedSWF('%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s);" % [
    swf_path("#{name}.swf"),
    options[:dom_id] || name,
    width,
    height,
    options[:version] || "9.0.0",
    swf_path("expressInstall.swf"),
    flashvars.to_json,
    options[:params].to_json,
    options[:attributes].to_json,
    options[:callback] ? options[:callback] : "null",
  ]

  javascript_tag(code)
end

#swfoject(*args) ⇒ Object



43
44
45
# File 'app/helpers/swfobject_helper.rb', line 43

def swfoject(*args)
  swf_tag(*args)
end