mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
looking for layouts in files if not inline
This commit is contained in:
parent
1d2a7043ef
commit
9d0ce7cddd
2 changed files with 27 additions and 2 deletions
|
@ -68,7 +68,7 @@ module Sinatra
|
|||
|
||||
def render(content, options={})
|
||||
@content = _evaluate_render(%Q{"#{content}"})
|
||||
layout = resolve_layout(options[:layout])
|
||||
layout = resolve_layout(options[:layout], options)
|
||||
@content = _evaluate_render(layout) if layout
|
||||
@content
|
||||
end
|
||||
|
@ -81,12 +81,24 @@ module Sinatra
|
|||
instance_eval(content)
|
||||
when Proc
|
||||
instance_eval(&content)
|
||||
when File
|
||||
instance_eval(%Q{"#{content.read}"})
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_layout(name, options={})
|
||||
return if name == false
|
||||
layouts[name || :layout]
|
||||
if layout = layouts[name || :layout]
|
||||
return layout
|
||||
end
|
||||
filename = (options[:views_directory] || 'views') + "/#{name}.#{ext}"
|
||||
if File.file?(filename)
|
||||
File.new(filename)
|
||||
end
|
||||
end
|
||||
|
||||
def ext
|
||||
:html
|
||||
end
|
||||
|
||||
def layouts
|
||||
|
|
|
@ -44,4 +44,17 @@ context "Layouts (in general)" do
|
|||
|
||||
end
|
||||
|
||||
specify "can be read from a file if they're not inlined" do
|
||||
|
||||
get '/foo' do
|
||||
@title = 'Welcome to the Hello Program'
|
||||
render 'Blake', :layout => :foo,
|
||||
:views_directory => File.dirname(__FILE__) + "/views"
|
||||
end
|
||||
|
||||
get_it '/foo'
|
||||
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue