Class: SwfFu::Generator
- Inherits:
-
Object
- Object
- SwfFu::Generator
- Defined in:
- app/models/swf_fu/generator.rb
Overview
:nodoc:
Constant Summary collapse
- VALID_MODES =
[:static, :dynamic]
Instance Method Summary collapse
- #force_to_valid_id(id) ⇒ Object
- #generate(&block) ⇒ Object
-
#initialize(source, options, view) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(source, options, view) ⇒ Generator
Returns a new instance of Generator.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/swf_fu/generator.rb', line 17 def initialize(source, , view) @view = view @source = view.swf_path(source) = ActionView::Base..merge() .each do |key, value| [key] = value.call(source) if value.respond_to?(:call) end [:html_options, :parameters, :flashvars].each do |k| [k] = convert_to_hash([k]).reverse_merge convert_to_hash(ActionView::Base.[k]) end .reverse_merge!(DEFAULTS) [:id] ||= source.gsub(/^.*\//, '').gsub(/\.swf$/,'') [:id] = force_to_valid_id([:id]) [:div_id] ||= [:id]+"_div" [:div_id] = force_to_valid_id([:div_id]) [:width], [:height] = [:size].scan(/^(\d*%?)x(\d*%?)$/).first if [:size] [:auto_install] &&= @view.swf_path([:auto_install]) [:flashvars][:id] ||= [:id] @mode = .delete(:mode) @options = unless VALID_MODES.include? @mode raise ArgumentError, "options[:mode] should be either #{VALID_MODES.join(' or ')}" end end |
Instance Method Details
#force_to_valid_id(id) ⇒ Object
42 43 44 45 46 |
# File 'app/models/swf_fu/generator.rb', line 42 def force_to_valid_id(id) id = id.gsub /[^A-Za-z0-9\-_]/, "_" # HTML id can only contain these characters id = "swf_" + id unless id =~ /^[A-Z]/i # HTML id must start with alpha id end |
#generate(&block) ⇒ Object
48 49 50 51 |
# File 'app/models/swf_fu/generator.rb', line 48 def generate(&block) @options[:alt] = @view.capture(&block) if block_given? send(@mode) end |