$:.unshift File.dirname(__FILE__)
module BuildMaster
class FileProcessor
def initialize(template, content_path, evaluator)
@template = template
@content_path = content_path
@evaluator = evaluator
end
def process_textile()
textile_content = IO.read(@content_path)
match_result = TEXTILE_REGX.match(textile_content)
title = ''
if match_result != nil
title = match_result[2]
textile_content = match_result.post_match
end
html_body = RedCloth.new(textile_content).to_html
html_content = <
#{title}
#{html_body}
HTML
return process_html_content(html_content)
end
def process_html()
return process_html_content(File.open(@content_path))
end
private
def process_html_content(source)
document_with_skin = @template.process(source) do |message|
begin
method = @evaluator.method(message)
if (method.arity == 0)
method.call
else
method.call(@content_path)
end
rescue NameError
raise TemplateException,
"unable to process message: #{message}: #{$!}" ,
caller
end
end
return document_with_skin
end
end
end