Skip to content

Commit

Permalink
Add support for internal partials in Sinatra.
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Jun 13, 2012
1 parent de7cf9d commit b68aad4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/wlang/scope/sinatra_scope.rb
Expand Up @@ -14,6 +14,15 @@ def inspect
private

def find_partial(key, app)
find_internal_partial(key, app) || find_external_partial(key, app)
end

def find_internal_partial(key, app)
return unless app.settings.templates[key]
app.send(:compile_template, :wlang, key, {}, app.settings.views)
end

def find_external_partial(key, app)
views = app.settings.views
find_files(views, key) do |file|
if engine = Tilt[file]
Expand Down
21 changes: 16 additions & 5 deletions spec/integration/sinatra/test_partials.rb
Expand Up @@ -7,18 +7,29 @@
sinatra_app do
set :accessible, "world"
set :views, fixtures_folder/'templates'
template :internal_partial do
"Hello ${who}!"
end
helpers do
def accessible; settings.accessible; end
end
get '/' do
wlang :hello_from_sinatra, :locals => {:who => "sinatra"}
get '/external' do
wlang ">{hello}", :locals => {:who => "sinatra"}
end
get '/internal' do
wlang ">{internal_partial}", :locals => {:who => "sinatra"}
end
end
}

it 'renders partials correcty' do
get '/'
last_response.body.should eq("Hello Hello sinatra!!\n")
it 'renders external partials correcty' do
get '/external'
last_response.body.should eq("Hello sinatra!")
end

it 'renders internal partials correcty' do
get '/internal'
last_response.body.should eq("Hello sinatra!")
end

end

0 comments on commit b68aad4

Please sign in to comment.