Class: TypographerHelper::Parsers::AddClassToFirstParagraph

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

Instance Method Summary collapse

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 = 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