test/buildmaster/tc_file_processor.rb in BuildMaster-0.7.0 vs test/buildmaster/tc_file_processor.rb in BuildMaster-0.8.0
- old
+ new
@@ -1,34 +1,101 @@
$:.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_expression_evaluation
- template = XTemplate.new(<<CONTENT
+ def test_should_know_content_and_target
+ template = XTemplate.new(<<CONTENT
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
-<p>
- <template:attribute name="class" eval="method_one"/>
-</p>
</html>
CONTENT
)
- processor = FileProcessor.new(template, "content_path", self)
- document = processor.process_html_content("<html></html>")
- assert_equal('method one result',
- REXML::XPath.first(REXML::Document.new(document.to_s), '/html/p/@class').value.strip)
-
+ 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 evaluate(expression, path)
- assert_equal('method_one', expression)
- assert_equal('content_path', path)
- return "method one result"
+ def test_should_know_html_target
+ template = XTemplate.new(<<CONTENT
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
+</html>
+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
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
+</html>
+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 = <<CONTENT
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
+<head><title><template:include elements="/html/head/title/text()"/></title></head>
+<body>
+ <template:include elements="/html/body/*"/>
+</body>
+</html>
+CONTENT
+ hash = {'include' => Include.new(self)}
+ template = XTemplate.new(template_content, hash)
+
+ processor = FileProcessor.new(template, "content_path", self)
+ markdown_content = <<CONTENT
+--------------------------------------------
+Title Here
+--------------------------------------------
+Header
+=====================
+CONTENT
+ document = processor.process_markdown(markdown_content)
+ document = REXML::Document.new(document.to_s)
+ assert_equal('Title Here', REXML::XPath.first(document, '/html/head/title').text)
+ assert_equal('Header', REXML::XPath.first(document, '/html/body/h1').text)
end
end
end
\ No newline at end of file