Created
October 16, 2008 16:18
-
-
Save trevrosen/17184 to your computer and use it in GitHub Desktop.
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/env ruby | |
require "rubygems" | |
require "hpricot" | |
# File to alter and suffix to add | |
HEADER_FILE = "/path/to/your/file" | |
suffix = "?time=" + Time.now.strftime('%Y%m%d%H%M%S') | |
# Use Hpricot to open and parse file as well as to find path | |
doc = open(HEADER_FILE) { |f| Hpricot(f) } | |
path = (doc/"#default-stylesheet").first['href'] | |
# Grab the path, sans timestamp if necessary | |
base = path.split("?").first | |
# Alter path | |
(doc/"#default-stylesheet").first['href'] = base + suffix | |
# Write the fixed doc back out to the file | |
begin | |
open(HEADER_FILE, 'w') do |f| | |
f.write(doc) | |
f.close | |
end | |
puts "The CSS path '#{base}' in '#{HEADER_FILE}' has been appended with '#{suffix}'" | |
rescue Exception => e | |
puts "Error: #{e}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment