Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sinatra/sinatra
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Jun 19, 2012
2 parents a8c8ac0 + 8752085 commit 31e7834
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ gem 'maruku'
gem 'creole'
gem 'markaby'
gem 'radius'
gem 'wlang', '>= 2.0.1'

if RUBY_ENGINE == 'jruby'
gem 'nokogiri', '!= 1.5.0'
Expand Down
10 changes: 10 additions & 0 deletions README.fr.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ pour décorer l'objet retourné.

var resource = {"foo":"bar","baz":"qux"}; present(resource);

=== Templates WLang

Dependency:: {wlang}[https://github.com/blambeau/wlang/]
File Extensions:: <tt>.wlang</tt>
Example:: <tt>wlang :index, :locals => { :key => 'value' }</tt>

L'appel de code ruby au sein des templates n'est pas idiomatique en wlang. L'écriture de
templates sans logique est encouragé, via le passage de variables locales. Il est néanmoins
possible d'écrire un +layout+ en wlang et d'y utiliser +yield+.

=== Templates embarqués

get '/' do
Expand Down
9 changes: 9 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@ The <tt>:callback</tt> and <tt>:variable</tt> options can be used to decorate th

var resource = {"foo":"bar","baz":"qux"}; present(resource);

=== WLang Templates

Dependency:: {wlang}[https://github.com/blambeau/wlang/]
File Extensions:: <tt>.wlang</tt>
Example:: <tt>wlang :index, :locals => { :key => 'value' }</tt>

Since calling ruby methods is not idiomatic in wlang, you almost always want to pass locals
to it. Layouts written in wlang and +yield+ are supported, though.

=== Embedded Templates

get '/' do
Expand Down
4 changes: 4 additions & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,10 @@ def creole(template, options={}, locals={})
render :creole, template, options, locals
end

def wlang(template, options={}, locals={})
render :wlang, template, options, locals
end

def yajl(template, options={}, locals={})
options[:default_content_type] = :json
render :yajl, template, options, locals
Expand Down
1 change: 1 addition & 0 deletions test/views/hello.wlang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello from wlang!
2 changes: 2 additions & 0 deletions test/views/layout2.wlang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WLang Layout!
+{yield}
70 changes: 70 additions & 0 deletions test/wlang_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require File.expand_path('../helper', __FILE__)

begin
require 'wlang'

class WLangTest < Test::Unit::TestCase
def engine
Tilt::WLangTemplate
end

def wlang_app(&block)
mock_app {
set :views, File.dirname(__FILE__) + '/views'
get '/', &block
}
get '/'
end

it 'uses the correct engine' do
assert_equal engine, Tilt[:wlang]
end

it 'renders .wlang files in views path' do
wlang_app { wlang :hello }
assert ok?
assert_equal "Hello from wlang!\n", body
end

it 'renders in the app instance scope' do
mock_app do
helpers do
def who; "world"; end
end
get('/') { wlang 'Hello +{who}!' }
end
get '/'
assert ok?
assert_equal 'Hello world!', body
end

it 'takes a :locals option' do
wlang_app do
locals = {:foo => 'Bar'}
wlang 'Hello ${foo}!', :locals => locals
end
assert ok?
assert_equal 'Hello Bar!', body
end

it "renders with inline layouts" do
mock_app do
layout { 'THIS. IS. +{yield.upcase}!' }
get('/') { wlang 'Sparta' }
end
get '/'
assert ok?
assert_equal 'THIS. IS. SPARTA!', body
end

it "renders with file layouts" do
wlang_app { wlang 'Hello World', :layout => :layout2 }
assert ok?
assert_body "WLang Layout!\nHello World"
end

end

rescue LoadError
warn "#{$!.to_s}: skipping wlang tests"
end

0 comments on commit 31e7834

Please sign in to comment.