lib/buildmaster/site_spec.rb in BuildMaster-0.8.1 vs lib/buildmaster/site_spec.rb in BuildMaster-0.9.0

- old
+ new

@@ -2,37 +2,39 @@ require 'pathname' require 'templatelets' require 'tree_to_object' require 'site/template_builder' +require 'cotta' module BuildMaster class SiteSpec attr_reader :output_dir attr_accessor :content_dir, :template, :template_file - def initialize(file = nil) - @root = File.dirname(file) if file + def initialize(file = nil, cotta = Cotta.new()) + @root = cotta.file(file).parent if file + @cotta = cotta if (block_given?) yield self end end def output_dir=(path) if (@root) - @output_dir = File.join(@root, path) + @output_dir = @root.dir(path) else - @output_dir = path + @output_dir = @cotta.dir(path) end end def content_dir=(path) if (@root) - @content_dir = File.join(@root, path) + @content_dir = @root.dir(path) else - @content_dir = path + @content_dir = @cotta.dir(path) end end def page_layout=(yaml) @template = TreeToObject.from_yaml(yaml, TemplateBuilder.new).content @@ -42,11 +44,11 @@ @properties = Hash.new unless @properties return @properties end def validate_inputs - validate_dir(@content_dir, :content_dir) + validate_dir(content_dir, :content_dir) end def load_template templatelets = load_templatelets template_source = load_template_source @@ -67,21 +69,21 @@ def load_template_source if (@template) return @template else - return File.open(@template_file) + return @template_file.load end end def load_document(path) - return REXML::Document.new(File.open(File.join(content_dir, path))) + content_dir.file(path).read {|file| REXML::Document.new(file)} end def relative_to_root(path) - to = path_name(path) - from = path_name(@content_dir) + to = path_name(path.path.to_s) + from = path_name(@content_dir.path.to_s) return to.relative_path_from(from) end def add_property(name, value) properties()[name] = value @@ -107,13 +109,13 @@ def validate_dir(directory, symbol) if not directory raise "Directory for #{symbol.id2name} not specified" end - if not File.exists? directory + if not directory.exists? raise "Directory for #{symbol.id2name} -- <#{directory}> does not exist" end - if not File.directory? directory + if not directory.exists? raise "<#{directory}> should be a directory for #{symbol.id2name}" end end \ No newline at end of file