lib/buildmaster/site/site.rb in BuildMaster-0.9.1 vs lib/buildmaster/site/site.rb in BuildMaster-1.0.6
- old
+ new
@@ -1,26 +1,46 @@
-$:.unshift File.join(File.dirname(__FILE__), '..')
+$:.unshift File.join(File.dirname(__FILE__))
require 'fileutils'
require 'file_processor'
-require 'site_spec'
+require 'site_server'
module BuildMaster
class NullLogger
def << message
puts "IGNORED: #{message}"
end
end
class Site
+ def Site::setup(spec, templates_dir = spec.cotta.dir(__FILE__).parent.dir('templates'))
+ command_line = spec.cotta.command_interface
+ command_line.puts 'setting up site'
+ candidates = collect_candidates(templates_dir).collect {|item| item.name}
+ selection = command_line.prompt_for_choice('Select the template that you want to use', candidates)
+ selected_dir = templates_dir.dir(selection)
+ selected_dir.file('template.html').copy_to(spec.template_file)
+ selected_dir.dir('content').copy_to(spec.content_dir)
+ end
+
+ def Site::collect_candidates(dir)
+ dir.list.select do |item|
+ item.respond_to?(:file) && item.file('template.html').exists?
+ end
+ end
+
def initialize(spec)
@spec = spec
@spec.validate_inputs
@template = @spec.load_template
end
public
+ def output_dir
+ @spec.output_dir
+ end
+
def execute(arguments)
action = 'build'
if arguments.size > 0
action = arguments[0]
end
@@ -33,19 +53,22 @@
puts "Generated file count: #{@count}"
end
def server(*args)
require 'site_server'
- @server = SiteServer.new(*args)
- @server.start(@spec)
+ @server = SiteServer.new(@spec, *args)
+ ['INT', 'TERM'].each { |signal|
+ trap(signal){ @server.stop}
+ }
+ @server.start
end
def test(port_number=2000)
- launch_server(port_number) {|port_number| SiteTester.test("http://localhost:#{port_number}")}
+ launch_server(port_number) {|port_number| SiteTester.test("http://localhost:#{port_number}/index.html")}
end
def test_offline(port_number=2000)
- launch_server(port_number) {|port_number| SiteTester.test_offline("http://localhost:#{port_number}")}
+ launch_server(port_number) {|port_number| SiteTester.test_offline("http://localhost:#{port_number}/index.html")}
end
private
def launch_server(port_number)