Class: Mato::HtmlFilters::TokenLink
- Inherits:
-
Object
- Object
- Mato::HtmlFilters::TokenLink
- Includes:
- Concerns::HtmlNodeCheckable
- Defined in:
- lib/mato/html_filters/token_link.rb
Instance Attribute Summary collapse
- #builder ⇒ Proc readonly
- #pattern ⇒ Regexp readonly
Instance Method Summary collapse
- #call(doc) ⇒ Object
-
#initialize(pattern, &builder) ⇒ TokenLink
constructor
A new instance of TokenLink.
Methods included from Concerns::HtmlNodeCheckable
Constructor Details
#initialize(pattern, &builder) ⇒ TokenLink
Returns a new instance of TokenLink.
18 19 20 21 |
# File 'lib/mato/html_filters/token_link.rb', line 18 def initialize(pattern, &builder) @pattern = pattern @builder = builder end |
Instance Attribute Details
#builder ⇒ Proc (readonly)
14 15 16 |
# File 'lib/mato/html_filters/token_link.rb', line 14 def builder @builder end |
#pattern ⇒ Regexp (readonly)
11 12 13 |
# File 'lib/mato/html_filters/token_link.rb', line 11 def pattern @pattern end |
Instance Method Details
#call(doc) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/mato/html_filters/token_link.rb', line 24 def call(doc) doc.xpath('.//text()').each do |text_node| next if has_ancestor?(text_node, 'a', 'code') text_node.replace(text_node.content.gsub(pattern, &builder)) end end |