diff --git a/lib/sinatra/event.rb b/lib/sinatra/event.rb index 6444780c..7a6666b3 100644 --- a/lib/sinatra/event.rb +++ b/lib/sinatra/event.rb @@ -92,6 +92,19 @@ module Sinatra @params ||= @request.params.symbolize_keys 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 logger.info "#{request.request_method} #{request.path_info} | Status: #{status} | Params: #{params.inspect}" logger.exception(error) if error diff --git a/vendor/erb/lib/erb.rb b/vendor/erb/lib/erb.rb index 220f4936..b294e870 100644 --- a/vendor/erb/lib/erb.rb +++ b/vendor/erb/lib/erb.rb @@ -1,5 +1,3 @@ -require 'erb' - module Sinatra module Erb @@ -7,17 +5,8 @@ module Sinatra module InstanceMethods def erb(content) - s = if content.is_a?(Symbol) - open("%s/%s.erb" % [views_dir, content]).read - 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' + require 'erb' + body ERB.new(determine_template(content, :erb)).result(binding) end end diff --git a/vendor/haml/init.rb b/vendor/haml/init.rb new file mode 100644 index 00000000..6c393d22 --- /dev/null +++ b/vendor/haml/init.rb @@ -0,0 +1,3 @@ +require File.dirname(__FILE__) + '/lib/haml' + +Sinatra::EventContext.send(:include, Sinatra::Haml::InstanceMethods) diff --git a/vendor/haml/lib/haml.rb b/vendor/haml/lib/haml.rb new file mode 100644 index 00000000..5514605e --- /dev/null +++ b/vendor/haml/lib/haml.rb @@ -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