Class: TypographerHelper::Parsers::AddToLastParagraph
- Inherits:
-
Object
- Object
- TypographerHelper::Parsers::AddToLastParagraph
- Defined in:
- lib/typographer-addons/add_to_last_paragraph.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AddToLastParagraph
constructor
A new instance of AddToLastParagraph.
- #parse(string) ⇒ Object
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( = {}) = [:text] ||= '' [: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([:matcher]).first.add_child([:text]) doc.search('body').children.to_xhtml end |