lib/buildmaster/site_spec.rb in BuildMaster-0.7.0 vs lib/buildmaster/site_spec.rb in BuildMaster-0.8.0

- old
+ new

@@ -1,58 +1,107 @@ +$:.unshift File.dirname(__FILE__) + require 'pathname' +require 'templatelets' +require 'tree_to_object' +require 'site/template_builder' module BuildMaster + class SiteSpec - def self.get_instance - self.new() + attr_reader :output_dir + attr_accessor :content_dir, :template, :template_file + + def initialize(file = nil) + @root = File.dirname(file) if file + if (block_given?) + yield self + end end - - attr_accessor :output_dir, :content_dir, :template, :template_file + def output_dir=(path) + if (@root) + @output_dir = File.join(@root, path) + else + @output_dir = path + end + end + + def content_dir=(path) + if (@root) + @content_dir = File.join(@root, path) + else + @content_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 XTemplate.new(@template) + return @template else - return XTemplate.new(File.open(@template_file)) + return File.open(@template_file) end end + + def load_document(path) + return REXML::Document.new(File.open(File.join(content_dir, path))) + end def relative_to_root(path) to = path_name(path) from = path_name(@content_dir) return to.relative_path_from(from) end - def evaluate(expression, path) - value_from_properties = properties()[expression] - if (value_from_properties) - return value_from_properties - end - if (!respond_to?(expression, true)) - raise "Neither property nor method found with name '#{expression}'" - end - relative_path = relative_to_root(path) - if (expression == 'relative_to_root') - return relative_path - else - send(expression, relative_to_root(path).to_s) - end - 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 @@ -65,11 +114,13 @@ end if not File.directory? directory 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) @@ -77,8 +128,9 @@ end if not File.file? file raise "#<{file} should be a file for #{symbol.id2name}" end end +=end end end \ No newline at end of file