#!/usr/bin/env ruby require 'erb' require 'fileutils' require 'bluecloth' puts puts "Building #{ARGV[0]}" def render(opts) if opts.is_a? Hash if opts[:markdown] print "m" BlueCloth.new(File.read(opts[:markdown])).to_html end else File.read(ARGV[0]+"/src/"+opts) end end def build_directory(indent, fromname, toname) unless File.exist?(toname) FileUtils.mkdir toname end fromname.gsub("//", "/") Dir.glob(fromname+"/*").sort.each do |fn| continue if fn.include? "/." path = fn.gsub(fromname+"/", "") if File.directory?(fn) print " "*indent + path puts "/" build_directory(indent+2, fn, toname+"/"+path) else path1 = " "*indent + path +" " if [".html", ".css", ".htm", ".js"].include? File.extname(fn) print(path1 + "."*(40-path1.length) + " [") contents = File.read(fn) output = contents while output.include? "<%=" print "%" output = ERB.new(output).result end File.open(toname+"/"+path, "w") {|f| f.puts output} puts "]" else print path1 FileUtils.cp fn, toname+"/"+path puts end end end end FileUtils.rm_rf ARGV[0]+"/site" build_directory(2, ARGV[0]+"/src", ARGV[0]+"/site") puts "done."