Created
February 19, 2009 05:22
-
-
Save tjstankus/66738 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
namespace :static do | |
desc 'Create a static html version of the site' | |
task :build do | |
# Make static directory | |
Dir.mkdir "#{RAILS_ROOT}/static" unless File.exists? "#{RAILS_ROOT}/static" | |
# wget our local rails site. | |
%x{ wget --recursive --convert-links --html-extension --no-host-directories --directory-prefix=static http://localhost:3000/ } | |
# Write out a 'disallow all' robots.txt file. | |
# open("#{RAILS_ROOT}/static/robots.txt", 'w') do |f| | |
# f.puts 'User-agent: *' | |
# f.puts 'Disallow: /' | |
# end | |
# Copy over files referenced in stylesheet. | |
open("#{RAILS_ROOT}/public/stylesheets/yir.css").each do |line| | |
if line.include?('url(') | |
start_index = line.rindex("/") + 1 | |
end_index = line.rindex(")") - start_index | |
filename = line[start_index, end_index] | |
%x{ cp "#{RAILS_ROOT}/public/images/#{filename}" "#{RAILS_ROOT}/static/images/" } | |
end | |
end | |
# Copy over background image files (_bg.jpg). | |
bg_images = Dir.entries("#{RAILS_ROOT}/public/images").collect { |filename| filename if filename.index('_bg.jpg') }.compact | |
bg_images.each do |image| | |
%x{ cp "#{RAILS_ROOT}/public/images/#{image}" "#{RAILS_ROOT}/static/images/" } | |
end | |
# Make archive | |
# To avoid 'dot underscore' files in static.tgz make sure these environment | |
# variables are set for MacOSX: | |
# export COPY_EXTENDED_ATTRIBUTES_DISABLE=true (on Tiger) | |
# export COPYFILE_DISABLE=true (on Leopard) | |
%x{ cd "#{RAILS_ROOT}/static/"; rm static.tgz; tar cvzf static.tgz * } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment