$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") require 'spec' require 'rexml/document' require 'pathname' require 'buildmaster/file_processor' require 'buildmaster/xtemplate' require 'buildmaster/cotta' require 'buildmaster/cotta/in_memory_system' module BuildMaster context 'File Processor' do setup do @cotta = Cotta.new(InMemorySystem.new) @cotta.file('content').save(< 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_equal(Pathname.new('content/index.html')) processor.is_html?.should_equal(true) end specify 'should know HTML target file' do template = XTemplate.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' processor = FileProcessor.new(template, current_dir.dir('content').file('index.gif'), site_spec) processor.content_file.path.should_equal current_dir.dir('content').file('index.gif').path processor.is_html?.should_equal false processor.generate_document.should_equal nil end specify 'should load from target file' do template_content = < CONTENT site_spec = SiteSpec.new(__FILE__, @cotta) current_dir = @cotta.dir(File.dirname(__FILE__)) current_dir.dir('site').dir('content').file('index.html').save current_dir.dir('site').dir('content').file('index.gif').save current_dir.dir('site').dir('content').file('textile.textile').save current_dir.dir('site').dir('content').file('markdown.markdown').save site_spec.template = template_content site_spec.content_dir = 'site/content' site_spec.output_dir = 'output' processor = FileProcessor.for_request_path('/index.html', site_spec) processor.content_file.should_equal site_spec.content_dir.file('index.html') processor = FileProcessor.for_request_path('/index.gif', site_spec) processor.content_file.should_equal site_spec.content_dir.file('index.gif') processor = FileProcessor.for_request_path('/textile.html', site_spec) processor.content_file.should_equal site_spec.content_dir.file('textile.textile') processor = FileProcessor.for_request_path('/markdown.html', site_spec) processor.content_file.should_equal site_spec.content_dir.file('markdown.markdown') 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(template_content, hash) processor = FileProcessor.new(template, @cotta.file('content_path'), self) markdown_content = <