$:.unshift File.join(File.dirname(__FILE__), "..", "..", '..', "lib", 'buildmaster') require 'spec' require 'rexml/document' require 'pathname' require 'site/file_processor' require 'site/xtemplate' require 'cotta' require 'cotta/in_memory_system' module BuildMaster context 'File Processor' do setup do @cotta = Cotta.new(InMemorySystem.new) @cotta.file('content').save(< CONTENT template = XTemplate.new(REXML::Document.new(content), {}) site_spec = SiteSpec.new('file.txt', @cotta) site_spec.content_dir = 'content' site_spec.output_dir = 'output' processor = FileProcessor.new(template, @cotta.file('content/index.html'), site_spec) processor.content_file.path.should ==(Pathname.new('content/index.html')) processor.is_html?.should ==(true) end specify 'should copy the content if no content engine found' do content = < CONTENT template = XTemplate.new(REXML::Document.new(content), {}) site_spec = SiteSpec.new(nil, @cotta) current_dir = @cotta.dir('root') site_spec.content_dir = 'root/content' site_spec.output_dir = 'root/output' source = current_dir.dir('content').file('index.gif') source.save('content for a gif') processor = FileProcessor.new(template, source, site_spec) processor.content_file.path.should == source.path processor.is_html?.should == false processor.write_to_target processor.target_file.load.should == source.load end def output_dir return @cotta.dir('tmp') end def relative_to_root(path) return Pathname.new('tmp') end specify 'should have support for markdown content' do template_content = < <template:include elements="/html/head/title/text()"/> CONTENT hash = {'include' => Include.new(self)} template = XTemplate.new(REXML::Document.new(template_content), ElementProcessorByName.new(hash)) sitespec = SiteSpec.new('root', Cotta.new(InMemorySystem.new())) do |spec| spec.content_dir = 'content_dir' spec.output_dir = 'output_dir' end source = @cotta.file('content_path.markdown') processor = FileProcessor.new(template, source, sitespec) source.save(< <template:include elements="/html/head/title/text()"/> CONTENT hash = {'include' => Include.new(self)} template = XTemplate.new(REXML::Document.new(template_content), ElementProcessorByName.new(hash)) sitespec = SiteSpec.new('root', Cotta.new(InMemorySystem.new())) do |spec| spec.content_dir = 'content_dir' spec.output_dir = 'output_dir' spec.properties['property'] = 'property value' end source = @cotta.file('content_path.markdown') processor = FileProcessor.new(template, source, sitespec) source.save(< CONTENT processor.write_to_target document = REXML::Document.new(processor.target_file.load) REXML::XPath.first(document, '/html/head/title').text.should == 'Title Here' REXML::XPath.first(document, '/html/body/div').text.strip.should == 'property value' end end end