diff --git a/Gemfile b/Gemfile index 62f6f5ecce..2f1e159c77 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 36ec2a2fb3..43600edf69 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/views/hello.wlang b/test/views/hello.wlang new file mode 100644 index 0000000000..43a86509b3 --- /dev/null +++ b/test/views/hello.wlang @@ -0,0 +1 @@ +Hello from wlang! diff --git a/test/views/layout2.wlang b/test/views/layout2.wlang new file mode 100644 index 0000000000..6055260e1e --- /dev/null +++ b/test/views/layout2.wlang @@ -0,0 +1,2 @@ +WLang Layout! ++{yield} diff --git a/test/wlang_test.rb b/test/wlang_test.rb new file mode 100644 index 0000000000..8baf5400c8 --- /dev/null +++ b/test/wlang_test.rb @@ -0,0 +1,64 @@ +require File.expand_path('../helper', __FILE__) +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 \ No newline at end of file