class Rack::ServerPages::Template

Attributes

file[R]

Public Class Methods

[](file) click to toggle source
# File lib/rack/server_pages.rb, line 183
def [](file)
  engine.new(file).find_template
end
engine() click to toggle source
# File lib/rack/server_pages.rb, line 187
def engine
  tilt? ? TiltTemplate : ERBTemplate
end
new(file) click to toggle source
# File lib/rack/server_pages.rb, line 202
def initialize(file)
  @file = file
end
tilt?() click to toggle source
# File lib/rack/server_pages.rb, line 191
def tilt?
  @use_tilt.nil? ? (@use_tilt ||= !!defined?(Tilt)) : @use_tilt && defined?(Tilt)
end
use_tilt(bool = true) click to toggle source
# File lib/rack/server_pages.rb, line 195
def use_tilt(bool = true)
  @use_tilt = !!bool
end

Public Instance Methods

mime_type() click to toggle source
# File lib/rack/server_pages.rb, line 206
def mime_type
  ext = @file[/(\.\w+)?(?:\.\w+)$/, 1]
  Mime.mime_type(ext, default_mime_type)
end
mime_type_with_charset(charset = 'utf-8') click to toggle source
# File lib/rack/server_pages.rb, line 211
def mime_type_with_charset(charset = 'utf-8')
  if (m = mime_type) =~ %r{^(text/\w+|application/(?:javascript|(xhtml\+)?xml|json))$}
    "#{m}; charset=#{charset}"
  else
    m
  end
end
render_with_layout(scope, locals = {}, &block) click to toggle source
# File lib/rack/server_pages.rb, line 219
def render_with_layout(scope, locals = {}, &block)
  content = render(scope, locals, &block)
  if (layout = scope.layout) && (layout_file = Dir["#{layout}{.*,}"].first)
    scope.layout(false)
    Template[layout_file].render_with_layout(scope) { content }
  else
    content
  end
end