Commit 1dcfeb5b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Allow for different types of videos.

For now implementing two types:

    {@video html5 some/url.mpeg Comment...}

    {@video vimeo 8791231354 Comment...}

With future possibility of allowing users define their own types.
parent bc3aa9c5
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -29,15 +29,6 @@ module JsDuck
    # Default value: '<img src="%u" alt="%a"/>'
    attr_accessor :img_tpl

    # Template HTML that replaces {@video URL alt text}
    # Can contain placeholders:
    #
    # %u - URL from @video tag (e.g. "some/path.mpeg")
    # %a - alt text for video
    #
    # Default value: '<video src="%u">%a</video>'
    attr_accessor :video_tpl

    # This will hold list of all image paths gathered from {@img} tags.
    attr_accessor :images

@@ -73,11 +64,23 @@ module JsDuck

      @link_tpl = opts[:link_tpl] || '<a href="%c%#%m">%a</a>'
      @img_tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>'
      @video_tpl = opts[:video_tpl] || '<video src="%u">%a</video>'
      @video_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
      }

      @link_re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m
      @img_re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m
      @video_re = /\{@video\s+(\S*?)(?:\s+(.+?))?\}/m
      @video_re = /\{@video\s+(\w+)\s+(\S*?)(?:\s+(.+?))?\}/m

      @example_annotation_re = /<pre><code>\s*@example( +[^\n]*)?\s+/m
    end
@@ -206,7 +209,7 @@ module JsDuck
    end

    def replace_video_tag(input)
      input.sub(@video_re) { video($1, $2) }
      input.sub(@video_re) { video($1, $2, $3) }
    end

    # Looks input text for patterns like:
@@ -293,9 +296,13 @@ module JsDuck
      end
    end

    # applies the video template
    def video(url, alt_text)
      @video_tpl.gsub(/(%\w)/) do
    # applies the video template of the specified type
    def video(type, url, alt_text)
      unless @video_templates.has_key?(type)
        Logger.instance.warn(nil, "Unknown video type #{type}")
      end

      @video_templates[type].gsub(/(%\w)/) do
        case $1
        when '%u'
          url
+0 −13
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ module JsDuck
    attr_accessor :images
    attr_accessor :link_tpl
    attr_accessor :img_tpl
    attr_accessor :video_tpl
    attr_accessor :export
    attr_accessor :seo
    attr_accessor :eg_iframe
@@ -93,18 +92,6 @@ module JsDuck
      # Note that we wrap image template inside <p> because {@img} often
      # appears inline within text, but that just looks ugly in HTML
      @img_tpl = '<p><img src="%u" alt="%a"></p>'
      # Template for embedding Vimeo videos.
      # For now there's no command line option to change this template.
      @video_tpl = [
        '<p><object width="640" height="360" id="video_player">',
          '<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
      @export = nil
      @seo = false
      @eg_iframe = nil
+7 −2
Original line number Diff line number Diff line
@@ -115,11 +115,16 @@ describe JsDuck::DocFormatter do

    # {@video ...}

    it "replaces {@video some/url.mpeg Alt text} with video markup" do
      @formatter.replace("{@video some/url.mpeg Alt text}").should ==
    it "replaces {@video html5 some/url.mpeg Alt text} with HTML5 video element" do
      @formatter.replace("{@video html5 some/url.mpeg Alt text}").should ==
        '<video src="some/url.mpeg">Alt text</video>'
    end

    it "replaces {@video vimeo 123456 Alt text} with Vimeo video markup" do
      @formatter.replace("{@video vimeo 123456 Alt text}").should =~
        /<object.*123456.*object>/
    end

    # auto-conversion of identifiable ClassNames to links
    describe "auto-detect" do
      before do