class Slimmer::Processors::TitleInserter

Public Instance Methods

filter(src, dest) click to toggle source
# 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) click to toggle source
# 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