Permalink
Browse files

Add support for internal partials in Sinatra.

  • Loading branch information...
1 parent de7cf9d commit b68aad48dee16a41a322f5f34fefcfd5df2d195e @blambeau committed Jun 13, 2012
Showing with 25 additions and 5 deletions.
  1. +9 −0 lib/wlang/scope/sinatra_scope.rb
  2. +16 −5 spec/integration/sinatra/test_partials.rb
View
9 lib/wlang/scope/sinatra_scope.rb
@@ -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]
View
21 spec/integration/sinatra/test_partials.rb
@@ -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.