Module: Angelo::Tilt::ERB
- Included in:
- Base
- Defined in:
- lib/angelo/tilt/erb.rb
Constant Summary collapse
- DEFAULT_LAYOUT =
'layout.%s'
- DEFAULT_TYPE =
:html
- LAYOUTS_DIR =
'layouts'
- ACCEPT_ALL =
'*/*'
Instance Method Summary collapse
Instance Method Details
#erb(view, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/angelo/tilt/erb.rb', line 12 def erb view, opts = {} type = opts.delete(:type) || template_type content_type type if view.is_a? Symbol view = :"#{view}.#{type}" end layout = case opts[:layout] when false false when Symbol :"#{LAYOUTS_DIR}/#{layout}.#{type}" else :"#{DEFAULT_LAYOUT % type}" end _erb view, layout: layout, locals: opts[:locals] end |
#template_type ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/angelo/tilt/erb.rb', line 33 def template_type accept = request.headers[ACCEPT_REQUEST_HEADER_KEY] mt = if accept.nil? or accept == ACCEPT_ALL MIME::Types[headers[CONTENT_TYPE_HEADER_KEY]] else MIME::Types[request.headers[ACCEPT_REQUEST_HEADER_KEY]] end mt.first.extensions.first.to_sym rescue DEFAULT_TYPE end |