Module: ThemeBandit::HTMLParser
- Included in:
- DocumentWriter
- Defined in:
- lib/theme_bandit/parser/html.rb
Instance Method Summary collapse
- #inject_link_nodes ⇒ Object
- #inject_script_nodes ⇒ Object
- #link_nodes ⇒ Object
- #local_link_names ⇒ Object
- #local_script_names ⇒ Object
- #remove_base_tags ⇒ Object
- #remove_link_tags ⇒ Object
- #remove_script_tags ⇒ Object
- #revise_head_tags ⇒ Object
- #script_nodes ⇒ Object
Instance Method Details
#inject_link_nodes ⇒ Object
64 65 66 67 68 |
# File 'lib/theme_bandit/parser/html.rb', line 64 def inject_link_nodes link_nodes.each do |node| document.search('head').first.add_child(node) end end |
#inject_script_nodes ⇒ Object
70 71 72 73 74 |
# 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 |
#link_nodes ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/theme_bandit/parser/html.rb', line 43 def link_nodes [].tap do |arr| local_link_names.each do |link_path| link = Nokogiri::XML::Node.new 'link', document link.set_attribute('rel', 'stylesheet') link.set_attribute('href', "#{link_path}") arr << link end end end |
#local_link_names ⇒ Object
29 30 31 32 33 34 |
# File 'lib/theme_bandit/parser/html.rb', line 29 def local_link_names path = "#{Dir.pwd}/theme/public/css/" Dir.entries(path).map do |file_name| "#{path}#{file_name}" if file_name['css'] end.compact end |
#local_script_names ⇒ Object
36 37 38 39 40 41 |
# 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 ⇒ Object
11 12 13 |
# File 'lib/theme_bandit/parser/html.rb', line 11 def document.search('base').remove end |
#remove_link_tags ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/theme_bandit/parser/html.rb', line 15 def document.search('link').each do |node| if node[:rel] == 'stylesheet' node.remove end end end |
#remove_script_tags ⇒ Object
23 24 25 26 27 |
# File 'lib/theme_bandit/parser/html.rb', line 23 def document.search('script').each do |node| node.remove if node[:src] end end |
#revise_head_tags ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/theme_bandit/parser/html.rb', line 3 def inject_link_nodes inject_script_nodes end |
#script_nodes ⇒ Object
54 55 56 57 58 59 60 61 62 |
# 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 |