Class: JsDuck::Inline::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/inline/video.rb

Overview

Implementation of inline tag @video

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Video

Returns a new instance of Video.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jsduck/inline/video.rb', line 13

def initialize(opts={})
  @doc_context = {}

  @templates = {
    "html5" => '<video src="%u">%a</video>',
    "vimeo" => [
      '<p><iframe src="http://player.vimeo.com/video/%u" width="640" height="360" frameborder="0" ',
          'webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>'
    ].join
  }

  @re = /\{@video\s+(\w+)\s+(\S*?)(?:\s+(.+?))?\}/m
end

Instance Attribute Details

#doc_contextObject

Sets up instance to work in context of particular doc object. Used for error reporting.



11
12
13
# File 'lib/jsduck/inline/video.rb', line 11

def doc_context
  @doc_context
end

Instance Method Details

#apply_tpl(type, url, alt_text) ⇒ Object

applies the video template of the specified type



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jsduck/inline/video.rb', line 41

def apply_tpl(type, url, alt_text)
  unless @templates.has_key?(type)
    Logger.warn(nil, "Unknown video type #{type}", @doc_context)
  end

  @templates[type].gsub(/(%\w)/) do
    case $1
    when '%u'
      url
    when '%a'
      Util::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.



32
33
34
35
36
37
38
# File 'lib/jsduck/inline/video.rb', line 32

def replace(input)
  if input.check(@re)
    input.scan(@re).sub(@re) { apply_tpl($1, $2, $3) }
  else
    false
  end
end