Module: Infoboxer::Parser::Image
Instance Method Summary collapse
Instance Method Details
#image ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/infoboxer/parser/image.rb', line 7 def image @context.skip(re.file_namespace) or @context.fail!("Something went wrong: it's not image?") path = @context.scan_until(/\||\]\]/) attrs = if @context.matched == '|' image_attrs else {} end Tree::Image.new(path, attrs) end |
#image_attr(nodes) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/infoboxer/parser/image.rb', line 33 def image_attr(nodes) if nodes.count == 1 && nodes.first.is_a?(Text) case (str = nodes.first.text) when /^(thumb)(?:nail)?$/, /^(frame)(?:d)?$/ {type: $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: $1, height: $2} when /^link=(.*)$/i {link: $1} when /^alt=(.*)$/i {alt: $1} else # text-only caption {caption: ImageCaption.new(nodes)} end else # it's caption, and can have inline markup! {caption: ImageCaption.new(nodes)} end end |
#image_attrs ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/infoboxer/parser/image.rb', line 20 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 |