module Angelo::Tilt::ERB

Constants

ACCEPT_ALL
DEFAULT_LAYOUT
DEFAULT_TYPE
LAYOUTS_DIR

Public Instance Methods

erb(view, opts = {}) click to toggle source
# 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() click to toggle source
# 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