Class: JsDuck::InlineImg
- Inherits:
-
Object
- Object
- JsDuck::InlineImg
- Defined in:
- lib/jsduck/inline_img.rb
Overview
Implementation of inline tag @img
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Base path to prefix images from @img tags.
-
#images ⇒ Object
This will hold list of all image paths gathered from @img tags.
Instance Method Summary collapse
-
#apply_tpl(url, alt_text) ⇒ Object
applies the image template.
-
#initialize(opts = {}) ⇒ InlineImg
constructor
A new instance of InlineImg.
-
#replace(input) ⇒ Object
Takes StringScanner instance.
Constructor Details
#initialize(opts = {}) ⇒ InlineImg
Returns a new instance of InlineImg.
15 16 17 18 19 20 21 22 |
# File 'lib/jsduck/inline_img.rb', line 15 def initialize(opts={}) @tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>' @re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m @base_path = nil @images = [] end |
Instance Attribute Details
#base_path ⇒ Object
Base path to prefix images from @img tags. Defaults to no prefix.
10 11 12 |
# File 'lib/jsduck/inline_img.rb', line 10 def base_path @base_path end |
#images ⇒ Object
This will hold list of all image paths gathered from @img tags.
13 14 15 |
# File 'lib/jsduck/inline_img.rb', line 13 def images @images end |
Instance Method Details
#apply_tpl(url, alt_text) ⇒ Object
applies the image template
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jsduck/inline_img.rb', line 38 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 |
#replace(input) ⇒ Object
Takes StringScanner instance.
Looks for inline tag at the current scan pointer position, when found, moves scan pointer forward and performs the apporpriate replacement.
29 30 31 32 33 34 35 |
# 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 |