Sha256: ee677c298b7dd1f4c2f1bf5dda44c1ba11427d0958879c0e24bbb5926aacd035

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

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

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=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

      # 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

16 entries across 16 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/inline/video.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.10 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.9 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.8 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.7 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.5 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.4 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.3 lib/jsduck/inline/video.rb
jsduck-troopjs-0.0.1 lib/jsduck/inline/video.rb
jsduck-6.0.0beta lib/jsduck/inline/video.rb