Class: TypographerHelper::Parsers::AddClassToFirstParagraph
- Inherits:
-
Object
- Object
- TypographerHelper::Parsers::AddClassToFirstParagraph
- Defined in:
- lib/typographer-addons/add_class_to_first_paragraph.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AddClassToFirstParagraph
constructor
A new instance of AddClassToFirstParagraph.
- #parse(string) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AddClassToFirstParagraph
Returns a new instance of AddClassToFirstParagraph.
5 6 7 8 9 |
# File 'lib/typographer-addons/add_class_to_first_paragraph.rb', line 5 def initialize( = {}) @options = @options[:class] ||= 'first_paragraph' @options[:matcher] ||= 'p' end |
Instance Method Details
#parse(string) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/typographer-addons/add_class_to_first_paragraph.rb', line 11 def parse(string) doc = Nokogiri.HTML string target = doc.css(@options[:matcher]).first target['class'] = target['class'].blank? ? @options[:class] : target['class'] + ' ' + @options[:class] doc.search('body').children.to_xhtml end |