class JsDuck::Inline::Video

Implementation of inline tag {@video}

Attributes

doc_context[RW]

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

Public Class Methods

new(opts=OpenStruct.new) click to toggle source
# File lib/jsduck/inline/video.rb, line 14
def initialize(opts=OpenStruct.new)
  @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

Public Instance Methods

apply_tpl(type, url, alt_text) click to toggle source

applies the video template of the specified type

# File lib/jsduck/inline/video.rb, line 42
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) click to toggle source

Takes StringScanner instance.

Looks for inline tag at the current scan pointer position, when found, moves scan pointer forward and performs the apporpriate replacement.

# File lib/jsduck/inline/video.rb, line 33
def replace(input)
  if input.check(@re)
    input.scan(@re).sub(@re) { apply_tpl($1, $2, $3) }
  else
    false
  end
end