Permalink
Browse files

Step 6: Inline template rendering

  • Loading branch information...
1 parent a5da103 commit f7929cee65a7563adacb4a5b79cd53fedecf9870 Carl Lerche committed Aug 27, 2009
Showing with 17 additions and 0 deletions.
  1. +17 −0 sinatrails.rb
View
17 sinatrails.rb
@@ -7,6 +7,7 @@ module Sinatra
class Base < ActionController::Metal
include ActionController::RackConvenience
include AbstractController::Callbacks
+ include ActionController::RenderingController
class << self
# Set @_routes on child classes
@@ -87,6 +88,10 @@ def _set_sessions(value)
@_sessions = value
include ActionController::Session if value
end
+
+ # Alias the method for settingup the views to
+ # the append view path method
+ alias _set_views append_view_path
end
# Halt can be implemented by simply throwing.
@@ -101,5 +106,17 @@ def process_action(*)
# when halting from a before callback.
self.response_body = catch(:halt) { super }
end
+
+ # Loop over the template render methods and define them
+ %w(haml erb builder).each do |type|
+ define_method(type) do |thing|
+ return sinatra_render_file(thing)
+ end
+ end
+
+ # Simple proxy to our render API
+ def sinatra_render_file(name)
+ render :template => name.to_s
+ end
end
end

0 comments on commit f7929ce

Please sign in to comment.