Loading lib/jsduck/doc_formatter.rb +4 −4 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ require 'rubygems' require 'strscan' require 'rdiscount' require 'jsduck/logger' require 'jsduck/inline_img' require 'jsduck/inline_video' require 'jsduck/inline/img' require 'jsduck/inline/video' require 'jsduck/html' module JsDuck Loading Loading @@ -49,8 +49,8 @@ module JsDuck @relations = relations @images = [] @inline_img = InlineImg.new(opts) @inline_video = InlineVideo.new(opts) @inline_img = Inline::Img.new(opts) @inline_video = Inline::Video.new(opts) @link_tpl = opts[:link_tpl] || '<a href="%c%#%m">%a</a>' @link_re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m Loading lib/jsduck/inline/img.rb 0 → 100644 +55 −0 Original line number Diff line number Diff line require 'jsduck/html' require 'jsduck/logger' module JsDuck module Inline # Implementation of inline tag {@img} class Img # Base path to prefix images from {@img} tags. # Defaults to no prefix. attr_accessor :base_path # This will hold list of all image paths gathered from {@img} tags. attr_accessor :images def initialize(opts={}) @tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m @base_path = nil @images = [] 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) } else false end end # applies the image template def apply_tpl(url, alt_text) @images << url @tpl.gsub(/(%\w)/) do case $1 when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' HTML.escape(alt_text||"") else $1 end end end end end end lib/jsduck/inline_video.rb→lib/jsduck/inline/video.rb +60 −0 Original line number Diff line number Diff line Loading @@ -2,9 +2,10 @@ require 'jsduck/html' require 'jsduck/logger' module JsDuck module Inline # Implementation of inline tag {@video} class InlineVideo class Video def initialize(opts={}) @templates = { "html5" => '<video src="%u">%a</video>', Loading Loading @@ -56,3 +57,4 @@ module JsDuck end end end lib/jsduck/inline_img.rbdeleted 100644 → 0 +0 −53 Original line number Diff line number Diff line require 'jsduck/html' require 'jsduck/logger' module JsDuck # Implementation of inline tag {@img} class InlineImg # Base path to prefix images from {@img} tags. # Defaults to no prefix. attr_accessor :base_path # This will hold list of all image paths gathered from {@img} tags. attr_accessor :images def initialize(opts={}) @tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m @base_path = nil @images = [] 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) } else false end end # applies the image template def apply_tpl(url, alt_text) @images << url @tpl.gsub(/(%\w)/) do case $1 when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' HTML.escape(alt_text||"") else $1 end end end end end Loading
lib/jsduck/doc_formatter.rb +4 −4 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ require 'rubygems' require 'strscan' require 'rdiscount' require 'jsduck/logger' require 'jsduck/inline_img' require 'jsduck/inline_video' require 'jsduck/inline/img' require 'jsduck/inline/video' require 'jsduck/html' module JsDuck Loading Loading @@ -49,8 +49,8 @@ module JsDuck @relations = relations @images = [] @inline_img = InlineImg.new(opts) @inline_video = InlineVideo.new(opts) @inline_img = Inline::Img.new(opts) @inline_video = Inline::Video.new(opts) @link_tpl = opts[:link_tpl] || '<a href="%c%#%m">%a</a>' @link_re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m Loading
lib/jsduck/inline/img.rb 0 → 100644 +55 −0 Original line number Diff line number Diff line require 'jsduck/html' require 'jsduck/logger' module JsDuck module Inline # Implementation of inline tag {@img} class Img # Base path to prefix images from {@img} tags. # Defaults to no prefix. attr_accessor :base_path # This will hold list of all image paths gathered from {@img} tags. attr_accessor :images def initialize(opts={}) @tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m @base_path = nil @images = [] 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) } else false end end # applies the image template def apply_tpl(url, alt_text) @images << url @tpl.gsub(/(%\w)/) do case $1 when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' HTML.escape(alt_text||"") else $1 end end end end end end
lib/jsduck/inline_video.rb→lib/jsduck/inline/video.rb +60 −0 Original line number Diff line number Diff line Loading @@ -2,9 +2,10 @@ require 'jsduck/html' require 'jsduck/logger' module JsDuck module Inline # Implementation of inline tag {@video} class InlineVideo class Video def initialize(opts={}) @templates = { "html5" => '<video src="%u">%a</video>', Loading Loading @@ -56,3 +57,4 @@ module JsDuck end end end
lib/jsduck/inline_img.rbdeleted 100644 → 0 +0 −53 Original line number Diff line number Diff line require 'jsduck/html' require 'jsduck/logger' module JsDuck # Implementation of inline tag {@img} class InlineImg # Base path to prefix images from {@img} tags. # Defaults to no prefix. attr_accessor :base_path # This will hold list of all image paths gathered from {@img} tags. attr_accessor :images def initialize(opts={}) @tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m @base_path = nil @images = [] 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) } else false end end # applies the image template def apply_tpl(url, alt_text) @images << url @tpl.gsub(/(%\w)/) do case $1 when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' HTML.escape(alt_text||"") else $1 end end end end end