Skip to content

Commit

Permalink
Step 6: Inline template rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed Aug 27, 2009
1 parent a5da103 commit f7929ce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sinatrails.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.