Class: TextHyphenRails::HtmlHyphenator

Inherits:
Hyphenator
  • Object
show all
Defined in:
lib/text_hyphen_rails/html_hyphenator.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, lang, options) ⇒ HtmlHyphenator

Returns a new instance of HtmlHyphenator.



5
6
7
8
# File 'lib/text_hyphen_rails/html_hyphenator.rb', line 5

def initialize(text, lang, options)
  super
  @doc = Nokogiri::HTML.fragment text
end

Instance Method Details

#resultObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/text_hyphen_rails/html_hyphenator.rb', line 10

def result
  @doc.traverse do |n|
    if n.is_a? Nokogiri::XML::Text
      n.content = n.content.gsub regex do |tok|
        hyphenator.visualize(tok, @opts[:hyphen])
      end
    end
  end
  @doc.to_s
end