lib/brochure/template.rb in brochure-0.5.0 vs lib/brochure/template.rb in brochure-0.5.1

- old
+ new

@@ -6,31 +6,40 @@ @app = app @path = path end def template - @template ||= Tilt.new(path, nil, :outvar => '@_out_buf') + @template ||= Tilt.new(path, nil, :outvar => '@_out_buf') if engine_extension end - def engine_extension - @engine_extension ||= File.extname(path) + def basename + @basename ||= File.basename(path) end + def extensions + @extensions ||= basename.scan(/\.[^.]+/) + end + def format_extension - @format_extension ||= begin - ext = File.extname(File.basename(path, engine_extension)) - ext.empty? ? ".html" : ext - end + extensions.first end + def engine_extension + extensions[1] + end + def content_type @content_type ||= begin type = Rack::Mime.mime_type(format_extension) type[/^text/] ? "#{type}; charset=utf-8" : type end end def render(env, locals = {}, &block) - template.render(app.context_for(self, env), locals, &block) + if template + template.render(app.context_for(self, env), locals, &block) + else + File.read(path) + end end end end