Class: TypographerHelper::Parsers::AddToLastParagraph

Inherits:
Object
  • Object
show all
Defined in:
lib/typographer-addons/add_to_last_paragraph.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AddToLastParagraph

Returns a new instance of AddToLastParagraph.



5
6
7
8
9
# File 'lib/typographer-addons/add_to_last_paragraph.rb', line 5

def initialize(options = {})
  @options = options
  @options[:text] ||= ''
  @options[:matcher] ||= 'p:last-of-type'
end

Instance Method Details

#parse(string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/typographer-addons/add_to_last_paragraph.rb', line 11

def parse(string)
  #TODO: swap code after resolving issue https://github.com/tenderlove/nokogiri/issues/454
  #doc = Nokogiri::HTML.fragment(string)
  #doc.css(@options[:matcher]).first.add_child(@options[:text])
  #doc.to_s

  doc = Nokogiri.HTML string
  doc.css(@options[:matcher]).first.add_child(@options[:text])
  doc.search('body').children.to_xhtml
end