$:.unshift File.dirname(__FILE__) 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, 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 = @root.dir(path) else @output_dir = @cotta.dir(path) end end def content_dir=(path) if (@root) @content_dir = @root.dir(path) else @content_dir = @cotta.dir(path) end end def page_layout=(yaml) @template = TreeToObject.from_yaml(yaml, TemplateBuilder.new).content end def properties @properties = Hash.new unless @properties return @properties end def validate_inputs validate_dir(content_dir, :content_dir) end def load_template templatelets = load_templatelets template_source = load_template_source return XTemplate.new(template_source, templatelets) end def load_templatelets hash = Hash.new hash['href'] = Href.new(self) hash['attribute'] = Attribute.new(self) hash['each'] = Each.new(self) hash['include'] = Include.new(self) hash['link'] = Link.new(self) hash['text'] = Text.new(properties) hash['when'] = When.new(self, self) return hash end def load_template_source if (@template) return @template else return @template_file.load end end def load_document(path) content_dir.file(path).read {|file| REXML::Document.new(file)} end def relative_to_root(path) 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 end def center_class(content_path) if index_file? content_path return 'Content3Column' else return 'Content2Column' end end def index_file?(content_path) result = content_path.to_s == 'index.html' return result end private def path_name(path) return Pathname.new(path.gsub(/\\/, '/')) end def validate_dir(directory, symbol) if not directory raise "Directory for #{symbol.id2name} not specified" end if not directory.exists? raise "Directory for #{symbol.id2name} -- <#{directory}> does not exist" end if not directory.exists? raise "<#{directory}> should be a directory for #{symbol.id2name}" end end =begin def validate_file(file, symbol) if not file raise "File for #{symbol.id2name} not specified" end if (not File.exists? file) raise "File for #{symbol.id2name} -- <#{file}> does not exist" end if not File.file? file raise "#<{file} should be a file for #{symbol.id2name}" end end =end end end