Permalink
Browse files

haml lives

  • Loading branch information...
1 parent c850784 commit fc0a4c53b41ae2a1856564cba22e992794586c4a blake.mizerany@gmail.com committed Sep 25, 2007
Showing with 34 additions and 13 deletions.
  1. +13 −0 lib/sinatra/event.rb
  2. +2 −13 vendor/erb/lib/erb.rb
  3. +3 −0 vendor/haml/init.rb
  4. +16 −0 vendor/haml/lib/haml.rb
View
@@ -92,6 +92,19 @@ def params
@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
View
@@ -1,23 +1,12 @@
-require 'erb'
-
module Sinatra
module Erb
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
View
@@ -0,0 +1,3 @@
+require File.dirname(__FILE__) + '/lib/haml'
+
+Sinatra::EventContext.send(:include, Sinatra::Haml::InstanceMethods)
View
@@ -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

0 comments on commit fc0a4c5

Please sign in to comment.