1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

haml lives

This commit is contained in:
blake.mizerany@gmail.com 2007-09-25 01:07:31 +00:00
parent c85078476a
commit fc0a4c53b4
4 changed files with 34 additions and 13 deletions

View file

@ -92,6 +92,19 @@ module Sinatra
@params ||= @request.params.symbolize_keys @params ||= @request.params.symbolize_keys
end end
def views_dir(value = nil)
@views_dir = value if value
@views_dir || File.dirname($0) + '/views'
end
def determine_template(content, ext)
if content.is_a?(Symbol)
File.read("%s/%s.%s" % [views_dir, content, ext])
else
content
end
end
def log_event def log_event
logger.info "#{request.request_method} #{request.path_info} | Status: #{status} | Params: #{params.inspect}" logger.info "#{request.request_method} #{request.path_info} | Status: #{status} | Params: #{params.inspect}"
logger.exception(error) if error logger.exception(error) if error

15
vendor/erb/lib/erb.rb vendored
View file

@ -1,5 +1,3 @@
require 'erb'
module Sinatra module Sinatra
module Erb module Erb
@ -7,17 +5,8 @@ module Sinatra
module InstanceMethods module InstanceMethods
def erb(content) def erb(content)
s = if content.is_a?(Symbol) require 'erb'
open("%s/%s.erb" % [views_dir, content]).read body ERB.new(determine_template(content, :erb)).result(binding)
else
content
end
body ERB.new(s).result(binding)
end
def views_dir(value = nil)
@views_dir = value if value
@views_dir || File.dirname($0) + '/views'
end end
end end

3
vendor/haml/init.rb vendored Normal file
View file

@ -0,0 +1,3 @@
require File.dirname(__FILE__) + '/lib/haml'
Sinatra::EventContext.send(:include, Sinatra::Haml::InstanceMethods)

16
vendor/haml/lib/haml.rb vendored Normal file
View file

@ -0,0 +1,16 @@
module Sinatra
module Haml
module InstanceMethods
def haml(content)
require 'haml'
body ::Haml::Engine.new(determine_template(content, :haml)).render(self)
end
end
end
end