Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Created December 15, 2009 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/257211 to your computer and use it in GitHub Desktop.
Save plukevdh/257211 to your computer and use it in GitHub Desktop.
Web page scrubbing util to pull content from a main non-Rails driven site and create a template from it.
#!/usr/bin/ruby
require 'rubygems'
require 'hpricot'
require 'yaml'
require 'open-uri'
site = "http://www2.hargray.com"
settings = YAML::load( File.open("template_options.yml") )
settings.each_key do |page|
begin
doc = open(site) {|f| Hpricot(f)}
head = doc.search("//head")
head.prepend(settings[page]["js"].to_s)
head.append(settings[page]["css"].to_s)
(head/"title").inner_html(settings[page]["title"])
(head/"base").remove
(head/"script").remove
(head/"link[@rel='alternate']").remove
(doc/"body script").remove
doc.search("*[@href]") do |link|
unless link.attributes['href'].index("http")
link.attributes['href'] = site + link.attributes['href']
end
end
page_content = doc.at("//table[@class='contentpaneopen']/tr/td")
page_content.inner_html(settings[page]["body_html"].to_s)
File.open("#{settings[page]["path"]}/signal.erb", "w+") { |f| f.write doc.to_html }
puts "Template generated for #{page.to_s}"
rescue Exception => exc
puts "Failed to update templates: #{exc}"
exit(0)
end
end
---
trouble-ticket:
path: /code/trouble-ticket/app/views/layouts
title: Trouble Ticket
js: <%= javascript_include_tag 'prototype', 'effects', 'application' %>
css: " "
body_html: <%= render :file => 'layouts/application' %>
serv-av:
path: /code/serv-av/app/views/layouts
title: "Service Availability"
js: <%= javascript_include_tag 'jquery', 'application' %>
css: <%= stylesheet_link_tag 'default' %>
body_html: <%= render :file => 'layouts/application' %>
online-billing:
path: /code/online-billing/app/views/layouts
title: Online Billpay
js: <%= javascript_include_tag 'jquery', 'jquery-ui', 'jrails', 'application' %>
css: <%= stylesheet_link_tag 'the_aftermath' %>
body_html: <%= render :file => 'layouts/application' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment