$:.unshift File.join(File.dirname(__FILE__), '..') require 'fileutils' require 'file_processor' require 'site_spec' module BuildMaster class NullLogger def << message puts "IGNORED: #{message}" end end class Site def initialize(spec) @spec = spec @spec.validate_inputs @template = @spec.load_template end public def execute(arguments) action = 'build' if arguments.size > 0 action = arguments[0] end send action end def build @count = 0 build_directory(@spec.output_dir, @spec.content_dir, @template) puts "Generated file count: #{@count}" end def server(*args) require 'site_server' @server = SiteServer.new(*args) @server.start(@spec) end def test(port_number=2000) launch_server(port_number) {|port_number| SiteTester.test("http://localhost:#{port_number}")} end def test_offline(port_number=2000) launch_server(port_number) {|port_number| SiteTester.test_offline("http://localhost:#{port_number}")} end private def launch_server(port_number) require 'buildmaster/site_tester' Thread.new() {server(port_number, NullLogger.new, 0, NullLogger.new)} begin sleep(2) yield port_number ensure @server.stop end end def build_directory(out_dir, content_dir, template) out_dir.mkdirs content_dir.list.each do |item| if (item.name == '.svn' || item.name == 'CVS' || item.name == '_svn') elsif (item.respond_to? 'list') build_directory(out_dir.dir(item.name), item, template) elsif (item.respond_to? 'read') @current_file_name = item process_file(item, out_dir, content_dir, item) @count = @count + 1 end end end def process_file(content_file, out_dir, content_dir, item) print ">> #{content_file.path.to_s}\n" FileProcessor.new(@template, content_file, @spec).write_to_target end end end