# The MIT License # # Copyright (c) 2008 Ryan Funduk # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # This rakefile automates the 'compilation' of html/css/whatever files, it # has the following tasks: # # build => go through all files in ./sources/ not ending in # '.partial' and run them through ERB, these files # should call the function 'partial' with an argument # like 'something.html' which will insert the entire # text of 'something.html.partial' and replace V% with # <% and %V with %> (so you can include ERB snippets # as part of your partials if necessary but also allow # executing ERB inside them). # # colorize => if you have the python project 'pygments' installed and # in your path you can run this task to take files in # ./sources/color/ and turn them into partials in # ./sources/. # # deploy => using the configuration variables at the beginning of # this file, deploy will take compiled files (that is, # everything not under ./sources) and tar+ssh them to # the remote server specified. # # [default] => the default is to run [ :colorize, :build ] # # Note: Be sure to name this file 'Rakefile' and place it somewhere where the # files in it's current directory aren't critical as it could, depending # on your source filenames, overwrite them. require 'erb' SRCDIR = 'sources' $partials = 0 REMOTE_HOST = { :hostname => '---', :destination => '.', :username => '---' } def write_output( filename, result ) ext = filename.split( '.' ).last filename = filename.split '/' filename.delete SRCDIR filename.insert -2, ext unless ext == 'html' filename = filename.join '/' result.gsub! /V%/, '<%' result.gsub! /%V/, '%>' File.open( filename, 'wb' ).write( result ) puts "WROTE : #{filename}" end def partial( name ) filename = "#{SRCDIR}/#{name}.partial" if File.exists? filename $partials += 1 puts "LOADED : #{name}.partial" File.open( filename, 'rb' ).read.chomp else puts "ERROR : #{filename}" end end task :colorize do FileList["#{SRCDIR}/color/*.*"].each do |f| d = "sources/#{f.split( '/' ).last}.partial" puts "COLORING : #{f}" sh "pygmentize -f html -o #{d} #{f}" end end task :build do sources = FileList["#{SRCDIR}/*.*"].exclude( "#{SRCDIR}/*.partial" ) sources.each do |f| puts "\nCOMPILING : #{f}" page = ERB.new( File.open( f, 'rb' ).read ) write_output f, page.result end puts "\nDONE : Compiled #{sources.size} sources w/ " \ "#{$partials} partials." end task :deploy do sh "tar --exclude ./sources -czf - ./ | " \ "ssh #{REMOTE_HOST[:username]}@#{REMOTE_HOST[:hostname]} " \ "tar -xzf - -C #{REMOTE_HOST[:destination]}" end task :default => [ :colorize, :build ]