| Class | Texy::Modules::Image |
| In: |
lib/texy/modules/image.rb
|
| Parent: | Base |
Images module class
| default_alt | [RW] | default image alternative text |
| handler | [RW] | Proc that will be called with newly created element |
| left_class | [RW] | left-floated image class |
| linked_root | [RW] | root of linked images (http) |
| right_class | [RW] | right-floated image class |
| root | [RW] | root of relative images (http) |
| root_prefix | [RW] | physical location on server |
# File lib/texy/modules/image.rb, line 57 def initialize(texy) super self.root = 'images/' self.linked_root = 'images/' self.root_prefix = '' self.left_class = nil self.right_class = nil self.default_alt = '' end
Add new named image
# File lib/texy/modules/image.rb, line 78 def add_reference(name, obj) texy.add_reference("*#{name}*", obj) end
Module initialization.
# File lib/texy/modules/image.rb, line 70 def init # [*image*]:LINK where LINK is: url | [ref] | [*image*] texy.register_line_pattern(method(:process_line), /#{PATTERN_IMAGE}#{PATTERN_LINK_N}?()/) end
Preprocessing
# File lib/texy/modules/image.rb, line 95 def pre_process(text) # [*image*]: urls .(title)[class]{style} text.gsub(/^\[\*([^\n]+?)\*\]:\ +(.+?)\ *#{PATTERN_MODIFIER}?()$/) do el_ref = ImageReference.new(texy, $2) el_ref.modifier.set_properties($3, $4, $5) add_reference($1, el_ref) '' end end
Callback function: [* small.jpg | small-over.jpg | big.jpg .(alternative text)[class]{style}>]:LINK
# File lib/texy/modules/image.rb, line 109 def process_line(parser, matches) return '' unless allowed m_urls, m_link = matches.values_at(1, 6) el_image = ImageElement.new(texy) el_image.set_images_raw(m_urls) el_image.modifier.set_properties(*matches[2..5]) if m_link el_link = LinkElement.new(texy) if m_link == ':' el_image.require_link_image el_link.link = el_image.link_image.dup else el_link.set_link_raw(m_link) end parser.element.append_child(el_link, parser.element.append_child(el_image)) else if handler return '' unless handler.call(el_image) end parser.element.append_child(el_image) end end