mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
haml lives
This commit is contained in:
parent
c85078476a
commit
fc0a4c53b4
4 changed files with 34 additions and 13 deletions
|
@ -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
|
||||
|
|
15
vendor/erb/lib/erb.rb
vendored
15
vendor/erb/lib/erb.rb
vendored
|
@ -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
|
||||
|
|
3
vendor/haml/init.rb
vendored
Normal file
3
vendor/haml/init.rb
vendored
Normal 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
16
vendor/haml/lib/haml.rb
vendored
Normal 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
|
Loading…
Reference in a new issue