Module: Infoboxer::Parser::Image
Instance Method Summary collapse
Instance Method Details
#image ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/infoboxer/parser/image.rb', line 8 def image @context.skip(re.file_namespace) or @context.fail!("Something went wrong: it's not image?") path = @context.scan_until(/\||\]\]/) attrs = @context.matched == '|' ? image_attrs : {} Tree::Image.new(path, **attrs) end |
#image_attr(nodes) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/infoboxer/parser/image.rb', line 30 def image_attr(nodes) # it's caption, and can have inline markup! return {caption: ImageCaption.new(nodes)} unless nodes.count == 1 && nodes.first.is_a?(Text) case (str = nodes.first.text) when /^(thumb)(?:nail)?$/, /^(frame)(?:d)?$/ {type: Regexp.last_match(1)} when 'frameless' {type: str} when 'border' {border: str} when /^(baseline|middle|sub|super|text-top|text-bottom|top|bottom)$/ {alignment: str} when /^(\d*)(?:x(\d+))?px$/ {width: Regexp.last_match(1), height: Regexp.last_match(2)} when /^link=(.*)$/i {link: Regexp.last_match(1)} when /^alt=(.*)$/i {alt: Regexp.last_match(1)} else # text-only caption {caption: ImageCaption.new(nodes)} end end |
#image_attrs ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/infoboxer/parser/image.rb', line 17 def image_attrs nodes = [] loop do nodes << long_inline(/\||\]\]/) break if @context.matched == ']]' end nodes.map(&method(:image_attr)) .inject(&:merge) .reject { |_k, v| v.nil? || v.empty? } end |