class JsDuck::Inline::Img
Implementation of inline tag {@img}
Attributes
doc_context[RW]
Sets up instance to work in context of particular doc object. Used for error reporting.
images[RW]
Instance of Img::Dir
or Img::DirSet
that's used for looking up image information.
Public Class Methods
new(opts=OpenStruct.new)
click to toggle source
# File lib/jsduck/inline/img.rb, line 18 def initialize(opts=OpenStruct.new) @tpl = opts.img || '<img src="%u" alt="%a" width="%w" height="%h"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m end
Public Instance Methods
apply_tpl(url, alt_text)
click to toggle source
applies the image template
# File lib/jsduck/inline/img.rb, line 38 def apply_tpl(url, alt_text) img = @images.get(url) if !img Logger.warn(:image, "Image #{url} not found.", @doc_context) img = {} end @tpl.gsub(/(%\w)/) do case $1 when '%u' img[:relative_path] when '%a' Util::HTML.escape(alt_text||"") when '%w' img[:width] when '%h' img[:height] else $1 end end end
replace(input)
click to toggle source
Takes StringScanner instance.
Looks for inline tag at the current scan pointer position, when found, moves scan pointer forward and performs the apporpriate replacement.
# File lib/jsduck/inline/img.rb, line 29 def replace(input) if input.check(@re) input.scan(@re).sub(@re) { apply_tpl($1, $2) } else false end end