Class: JsDuck::InlineVideo
- Inherits:
-
Object
- Object
- JsDuck::InlineVideo
- Defined in:
- lib/jsduck/inline_video.rb
Overview
Implementation of inline tag @video
Instance Method Summary collapse
-
#apply_tpl(type, url, alt_text) ⇒ Object
applies the video template of the specified type.
-
#initialize(opts = {}) ⇒ InlineVideo
constructor
A new instance of InlineVideo.
-
#replace(input) ⇒ Object
Takes StringScanner instance.
Constructor Details
#initialize(opts = {}) ⇒ InlineVideo
Returns a new instance of InlineVideo.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jsduck/inline_video.rb', line 8 def initialize(opts={}) @templates = { "html5" => '<video src="%u">%a</video>', "vimeo" => [ '<p><object width="640" height="360">', '<param name="allowfullscreen" value="true" />', '<param name="allowscriptaccess" value="always" />', '<param name="flashvars" value="api=1" />', '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=%u&server=vimeo.com&color=4CC208&fullscreen=1" />', '<embed src="http://vimeo.com/moogaloop.swf?clip_id=%u&server=vimeo.com&color=4CC208&fullscreen=1" ', 'type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed>', '</object></p>', ].join } @re = /\{@video\s+(\w+)\s+(\S*?)(?:\s+(.+?))?\}/m end |
Instance Method Details
#apply_tpl(type, url, alt_text) ⇒ Object
applies the video template of the specified type
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jsduck/inline_video.rb', line 40 def apply_tpl(type, url, alt_text) unless @templates.has_key?(type) Logger.instance.warn(nil, "Unknown video type #{type}") end @templates[type].gsub(/(%\w)/) do case $1 when '%u' url when '%a' HTML.escape(alt_text||"") else $1 end end end |
#replace(input) ⇒ Object
Takes StringScanner instance.
Looks for inline tag at the current scan pointer position, when found, moves scan pointer forward and performs the apporpriate replacement.
31 32 33 34 35 36 37 |
# File 'lib/jsduck/inline_video.rb', line 31 def replace(input) if input.check(@re) input.scan(@re).sub(@re) { apply_tpl($1, $2, $3) } else false end end |