Sha256: 9a0f9ce55b1dfb6a99a6a2255cf6aa0945d08f087fefb36990592ff8225e9ee5

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

$:.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 = <<HTML
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>#{title}</title>
</head>
<body>      
    #{html_body}
</body>
</html>
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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
BuildMaster-0.5.0 lib/buildmaster/file_processor.rb
BuildMaster-0.6.0 lib/buildmaster/file_processor.rb