| Class | Texy::Modules::Link |
| In: |
lib/texy/modules/link.rb
|
| Parent: | Base |
Links module class
| email_on_click | [RW] | ‘this.href=""+this.href.match(/./g).reverse().slice(0,-7).join("")’; |
| force_no_follow | [RW] | always use rel="nofollow" for absolute links |
| handler | [RW] | Proc that will be called with newly created element */ |
| image_on_click | [RW] | image popup event |
| popup_on_click | [RW] | popup popup event |
| root | [RW] | root of relative links |
# File lib/texy/modules/link.rb, line 56 def initialize(texy) super self.allowed = { :link => true, # classic link "xxx":URL and [reference] :email => true, # emails replacement :url => true, # direct url replacement :quick_link => true, # quick link xxx:[url] or [reference] :references => true, # [ref]: URL reference definitions } self.email_on_click = nil self.force_no_follow = false self.image_on_click = 'return !popupImage(this.href)' self.popup_on_click = 'return !popup(this.href)' end
Add new named image
# File lib/texy/modules/link.rb, line 106 def add_reference(name, obj) texy.add_reference(name, obj) end
Module initialization.
# File lib/texy/modules/link.rb, line 76 def init if allowed[:quick_link] texy.register_line_pattern( method(:process_line_quick), /([\w0-9@#\$%&\.,_-]+?)(?=:\[)#{PATTERN_LINK}()/ ) end # [reference] texy.register_line_pattern(method(:process_line_reference), /(#{PATTERN_LINK_REF})/) # direct url and email if allowed[:url] texy.register_line_pattern( method(:process_line_url), /([\s^\(\[<:])((?:https?:\/\/|www\.|ftp:\/\/|ftp\.)[a-z0-9.-][\/a-z\d+\.~%&?@=_:;#,-]+[\/\w\d+~%?@=_#])/i ) end if allowed[:email] texy.register_line_pattern( method(:process_line_url), /([\s^\(\[\<:])(#{PATTERN_EMAIL})/ ) end end
Preprocessing
# File lib/texy/modules/link.rb, line 135 def pre_process(text) # [la trine]: http://www.dgx.cz/trine/ text odkazu .(title)[class]{style} if allowed[:references] text.gsub(/^\[([^\[\]#\?\*\n]+?)\]:\ +(#{PATTERN_LINK_IMAGE}|(?!\[)\S+)(\ .+?)?#{PATTERN_MODIFIER}?()$/) do el_ref = LinkReference.new(texy, $2, $3) el_ref.modifier.set_properties($4, $5, $6) add_reference($1, el_ref) '' end else text end end
Callback function: .…:LINK
# File lib/texy/modules/link.rb, line 153 def process_line_quick(parser, matches) m_content, m_link = matches[1..2] return m_content unless allowed[:quick_link] el_link = LinkElement.new(texy) el_link.set_link_raw(m_link, m_content) parser.element.append_child(el_link, m_content) end
Callback function: [ref]
# File lib/texy/modules/link.rb, line 165 def process_line_reference(parser, matches) match, m_ref = matches return match unless allowed[:link] el_link = LinkRefElement.new(texy) return match unless el_link.set_link(m_ref) parser.element.append_child(el_link) end
Callback function: www.dgx.cz
# File lib/texy/modules/link.rb, line 178 def process_line_url(parser, matches) el_link = LinkElement.new(texy) el_link.set_link_raw(matches[2]) matches[1] + parser.element.append_child(el_link, el_link.link.as_textual) end
Receive new named link. If not exists, try call user function to create one.
# File lib/texy/modules/link.rb, line 112 def reference(ref_name) el = texy.reference(ref_name) query = '' unless el query_pos = ref_name.index('?') query_pos ||= ref_name.index('#') if query_pos # try to extract ?... #... part el = texy.reference(ref_name[0, query_pos]) query = ref_name[query_pos..-1] end end return false unless el.kind_of?(LinkReference) el.query = query el end