module ThemeBandit::HTMLParser

Public Instance Methods

inject_script_nodes() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 70
def inject_script_nodes
  script_nodes.each do |node|
    document.search('head').first.add_child(node)
  end
end
local_script_names() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 36
def local_script_names
  path = "#{Dir.pwd}/theme/public/js/"
  Dir.entries(path).map do |file_name|
    "#{path}#{file_name}" if file_name['js']
  end.compact.sort
end
remove_base_tags() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 11
def remove_base_tags
  document.search('base').remove
end
remove_script_tags() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 23
def remove_script_tags
  document.search('script').each do |node|
    node.remove if node[:src]
  end
end
revise_head_tags() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 3
def revise_head_tags
  remove_base_tags
  remove_link_tags
  remove_script_tags
  inject_link_nodes
  inject_script_nodes
end
script_nodes() click to toggle source
# File lib/theme_bandit/parser/html.rb, line 54
def script_nodes
  [].tap do |arr|
    local_script_names.each do |script_path|
      script = Nokogiri::XML::Node.new 'script', document
      script.set_attribute('src', "#{script_path}")
      arr << script
    end
  end
end