$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") require 'test/unit' require 'rexml/document' require 'pathname' require 'buildmaster/file_processor' require 'buildmaster/xtemplate' module BuildMaster class FileProcessorTest < Test::Unit::TestCase def test_should_know_content_and_target template = XTemplate.new(< CONTENT ) site_spec = SiteSpec.new current_dir = File.dirname(__FILE__) site_spec.content_dir = File.join(current_dir, "content") site_spec.output_dir = File.join(current_dir, "output") processor = FileProcessor.new(template, File.join(current_dir, 'content', 'index.html'), site_spec) assert_equal(File.join(current_dir, 'content', 'index.html'), processor.path_to_content_file) assert_equal(true, processor.is_html?) end def test_should_know_html_target template = XTemplate.new(< CONTENT ) site_spec = SiteSpec.new current_dir = File.dirname(__FILE__) site_spec.content_dir = File.join(current_dir, "content") site_spec.output_dir = File.join(current_dir, "output") processor = FileProcessor.new(template, File.join(current_dir, 'content', 'index.gif'), site_spec) assert_equal(File.join(current_dir, 'content', 'index.gif'), processor.path_to_content_file) assert_equal(false, processor.is_html?) assert_equal(nil, processor.generate_document) end def test_should_load_from_target template_content = < CONTENT site_spec = SiteSpec.new current_dir = File.dirname(__FILE__) site_spec.template = template_content site_spec.content_dir = File.join(current_dir, 'site', 'content') site_spec.output_dir = File.join(current_dir, "output") processor = FileProcessor.for_request_path('/index.html', site_spec) assert_equal(File.join(site_spec.content_dir, 'index.html'), processor.path_to_content_file) processor = FileProcessor.for_request_path('/index.gif', site_spec) assert_equal(File.join(site_spec.content_dir, 'index.gif'), processor.path_to_content_file) processor = FileProcessor.for_request_path('/textile.html', site_spec) assert_equal(File.join(site_spec.content_dir, 'textile.textile'), processor.path_to_content_file) processor = FileProcessor.for_request_path('/markdown.html', site_spec) assert_equal(File.join(site_spec.content_dir, 'markdown.markdown'), processor.path_to_content_file) end def output_dir return 'tmp' end def relative_to_root(path) return Pathname.new('tmp') end def test_mark_down_support 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, "content_path", self) markdown_content = <