Sha256: 0dfce3b718bf00ce01fbcf71ab5a4db0dd9d9dfbe6533df681a8ca943a013212

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

require 'cgi'
require 'jsduck/logger'

module JsDuck

  # Implementation of inline tag {@video}
  class InlineVideo
    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&amp;server=vimeo.com&amp;color=4CC208&amp;fullscreen=1" />',
            '<embed src="http://vimeo.com/moogaloop.swf?clip_id=%u&amp;server=vimeo.com&amp;color=4CC208&amp;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

    # Takes StringScanner instance.
    #
    # Looks for inline tag at the current scan pointer position, when
    # found, moves scan pointer forward and performs the apporpriate
    # replacement.
    def replace(input)
      if input.check(@re)
        input.scan(@re).sub(@re) { apply_tpl($1, $2, $3) }
      else
        false
      end
    end

    # applies the video template of the specified type
    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'
          CGI.escapeHTML(alt_text||"")
        else
          $1
        end
      end
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jsduck-3.10.0 lib/jsduck/inline_video.rb
jsduck-3.9.1 lib/jsduck/inline_video.rb
jsduck-3.9.0 lib/jsduck/inline_video.rb
jsduck-3.9.0.pre lib/jsduck/inline_video.rb
jsduck-3.8.4 lib/jsduck/inline_video.rb
jsduck-3.8.3 lib/jsduck/inline_video.rb
jsduck-3.8.2 lib/jsduck/inline_video.rb
jsduck-3.8.1 lib/jsduck/inline_video.rb
jsduck-3.8.0 lib/jsduck/inline_video.rb