Class: Validifier::FlashMovie
- Inherits:
-
Object
- Object
- Validifier::FlashMovie
- Defined in:
- lib/validifier.rb
Instance Attribute Summary collapse
-
#classid ⇒ Object
Returns the value of attribute classid.
-
#codebase ⇒ Object
Returns the value of attribute codebase.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#height ⇒ Object
Returns the value of attribute height.
-
#params ⇒ Object
Returns the value of attribute params.
-
#source ⇒ Object
Returns the value of attribute source.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.from_source(html_str) ⇒ Object
Build a FlashMovie based on chunk of HTML (with object and/or embed code).
-
.validify(html_str) ⇒ Object
Convert html to valid XHTML.
Instance Method Summary collapse
-
#clean(str) ⇒ Object
nodoc.
-
#initialize(source, options = {}) ⇒ FlashMovie
constructor
A new instance of FlashMovie.
-
#to_s ⇒ Object
The valid XHTML markup for this flash movie.
Constructor Details
#initialize(source, options = {}) ⇒ FlashMovie
Returns a new instance of FlashMovie.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/validifier.rb', line 14 def initialize(source, ={}) @source = source @width = [:width] || WIDTH @height = [:height] || HEIGHT @codebase = [:codebase] || @classid = [:classid] || @params = [:params] || {} @comment = [:comment] || "" @coder = HTMLEntities.new end |
Instance Attribute Details
#classid ⇒ Object
Returns the value of attribute classid.
12 13 14 |
# File 'lib/validifier.rb', line 12 def classid @classid end |
#codebase ⇒ Object
Returns the value of attribute codebase.
12 13 14 |
# File 'lib/validifier.rb', line 12 def codebase @codebase end |
#comment ⇒ Object
Returns the value of attribute comment.
12 13 14 |
# File 'lib/validifier.rb', line 12 def comment @comment end |
#height ⇒ Object
Returns the value of attribute height.
12 13 14 |
# File 'lib/validifier.rb', line 12 def height @height end |
#params ⇒ Object
Returns the value of attribute params.
12 13 14 |
# File 'lib/validifier.rb', line 12 def params @params end |
#source ⇒ Object
Returns the value of attribute source.
12 13 14 |
# File 'lib/validifier.rb', line 12 def source @source end |
#width ⇒ Object
Returns the value of attribute width.
12 13 14 |
# File 'lib/validifier.rb', line 12 def width @width end |
Class Method Details
.from_source(html_str) ⇒ Object
Build a FlashMovie based on chunk of HTML (with object and/or embed code)
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/validifier.rb', line 52 def from_source(html_str) html = Hpricot(html_str) if object = (html/:object).first movie = scrape_object(object) elsif = (html/:embed).first movie = () else return nil end movie end |
.validify(html_str) ⇒ Object
Convert html to valid XHTML
65 66 67 |
# File 'lib/validifier.rb', line 65 def validify(html_str) FlashMovie.from_source(html_str).to_s end |
Instance Method Details
#clean(str) ⇒ Object
nodoc
27 28 29 |
# File 'lib/validifier.rb', line 27 def clean(str) @coder.encode(@coder.decode(str.to_s)) end |
#to_s ⇒ Object
The valid XHTML markup for this flash movie
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/validifier.rb', line 32 def to_s output = %Q{<!--[if !IE]> --> <object type="application/x-shockwave-flash" data="#{clean(source)}" width="#{clean(width)}" height="#{clean(height)}"> <!-- <![endif]--> <!--[if IE]> <object classid="#{clean(classid)}" codebase="#{clean(codebase)}" width="#{clean(width)}" height="#{clean(height)}"> <param name="movie" value="#{clean(source)}" /> <!--><!-- #{comment} --> } params ||= {} params.each do |name, value| output << %Q{ <param name="#{clean(name)}" value="#{clean(value)}" />\n} end output + " </object>\n<!-- <![endif]-->" end |