Sha256: bdb9ffac903a2601f8e88abc1f23f12f9ae9d47c735724657392906fb1eb251e
Contents?: true
Size: 1.11 KB
Versions: 5
Compression:
Stored size: 1.11 KB
Contents
require 'erubis' module Saga class Formatter TEMPLATE_PATH = File.expand_path('../../../templates', __FILE__) def initialize(document, options={}) @document = document @options = options @options[:template] ||= File.join(self.class.template_path, 'default') end def format helpers_file = File.join(@options[:template], 'helpers.rb') if File.exist?(helpers_file) load helpers_file @document.extend(Helpers) end template_file = File.join(@options[:template], 'document.erb') if File.exist?(template_file) template = Erubis::Eruby.new(File.read(template_file)) template.result(@document.send(:binding)) else raise ArgumentError, "The template at path `#{template_file}' could not be found." end end def self.format(document, options={}) formatter = new(document, options) formatter.format end def self.template_path TEMPLATE_PATH end def self.saga_format(document) format(document, :template => File.join(template_path, 'saga')) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
saga-0.8.1 | lib/saga/formatter.rb |
saga-0.8.0 | lib/saga/formatter.rb |
saga-0.7.1 | lib/saga/formatter.rb |
saga-0.7.0 | lib/saga/formatter.rb |
saga-0.6.0 | lib/saga/formatter.rb |