Skip to content

Instantly share code, notes, and snippets.

@trevrosen
Created October 16, 2008 16:18
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 trevrosen/17184 to your computer and use it in GitHub Desktop.
Save trevrosen/17184 to your computer and use it in GitHub Desktop.
#! /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