Class: Brochure::Template
- Inherits:
-
Object
- Object
- Brochure::Template
- Defined in:
- lib/brochure/template.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content_type ⇒ Object
- #engine_extension ⇒ Object
- #format_extension ⇒ Object
-
#initialize(app, path) ⇒ Template
constructor
A new instance of Template.
- #render(env, locals = {}, &block) ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(app, path) ⇒ Template
Returns a new instance of Template.
5 6 7 8 |
# File 'lib/brochure/template.rb', line 5 def initialize(app, path) @app = app @path = path end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/brochure/template.rb', line 3 def app @app end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/brochure/template.rb', line 3 def path @path end |
Instance Method Details
#content_type ⇒ Object
25 26 27 28 29 30 |
# File 'lib/brochure/template.rb', line 25 def content_type @content_type ||= begin type = Rack::Mime.mime_type(format_extension) type[/^text/] ? "#{type}; charset=utf-8" : type end end |
#engine_extension ⇒ Object
14 15 16 |
# File 'lib/brochure/template.rb', line 14 def engine_extension @engine_extension ||= File.extname(path) end |
#format_extension ⇒ Object
18 19 20 21 22 23 |
# File 'lib/brochure/template.rb', line 18 def format_extension @format_extension ||= begin ext = File.extname(File.basename(path, engine_extension)) ext.empty? ? ".html" : ext end end |
#render(env, locals = {}, &block) ⇒ Object
32 33 34 |
# File 'lib/brochure/template.rb', line 32 def render(env, locals = {}, &block) template.render(app.context_for(self, env), locals, &block) end |
#template ⇒ Object
10 11 12 |
# File 'lib/brochure/template.rb', line 10 def template @template ||= Tilt.new(path, nil, :outvar => '@_out_buf') end |