Class: Slimmer::Processors::TitleInserter

Inherits:
Object
  • Object
show all
Defined in:
lib/slimmer/processors/title_inserter.rb

Instance Method Summary collapse

Instance Method Details

#filter(src, dest) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/slimmer/processors/title_inserter.rb', line 3

def filter(src, dest)
  title = src.at_css("head title")
  head  = dest.at_xpath("/html/head")
  if head && title
    insert_title(title, head)
  end
end

#insert_title(title, head) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/slimmer/processors/title_inserter.rb', line 11

def insert_title(title, head)
  if head.at_css("title").nil?
    head.first_element_child.nil? ? head << title : head.first_element_child.before(title)
  else
    head.at_css("title").replace(title)
  end
end