Sha256: 8a7fd7c9deb7cba31c4abb41f0006dc8febff6105a7c917cade1b75b4316d6be

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

require 'jsduck/util/html'
require 'jsduck/logger'

module JsDuck
  module Inline

    # Implementation of inline tag {@video}
    class Video
      # Sets up instance to work in context of particular doc object.
      # Used for error reporting.
      attr_accessor :doc_context

      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

      # 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.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
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jsduck-5.3.4 lib/jsduck/inline/video.rb
jsduck-5.3.3 lib/jsduck/inline/video.rb
jsduck-5.3.2 lib/jsduck/inline/video.rb
jsduck-5.3.1 lib/jsduck/inline/video.rb
jsduck-5.3.0 lib/jsduck/inline/video.rb
jsduck-5.2.0 lib/jsduck/inline/video.rb
jsduck-5.1.0 lib/jsduck/inline/video.rb
jsduck-5.0.1 lib/jsduck/inline/video.rb
jsduck-5.0.0 lib/jsduck/inline/video.rb
jsduck-5.0.0.beta5 lib/jsduck/inline/video.rb
jsduck-5.0.0.beta4 lib/jsduck/inline/video.rb
jsduck-5.0.0.beta3 lib/jsduck/inline/video.rb