Created
December 15, 2009 19:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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