Skip to content
This repository
Browse code

Add support for wlang templating engine.

  • Loading branch information...
commit 46f2547cf44a4ae92a7a63fe1afb5444d7c8f5c5 1 parent 4f5a2fd
Bernard Lambeau blambeau authored
1  Gemfile
@@ -42,6 +42,7 @@ gem 'maruku'
42 42 gem 'creole'
43 43 gem 'markaby'
44 44 gem 'radius'
  45 +gem 'wlang', '>= 2.0.1'
45 46
46 47 if RUBY_ENGINE == 'jruby'
47 48 gem 'nokogiri', '!= 1.5.0'
4 lib/sinatra/base.rb
@@ -645,6 +645,10 @@ def creole(template, options={}, locals={})
645 645 render :creole, template, options, locals
646 646 end
647 647
  648 + def wlang(template, options={}, locals={})
  649 + render :wlang, template, options, locals
  650 + end
  651 +
648 652 def yajl(template, options={}, locals={})
649 653 options[:default_content_type] = :json
650 654 render :yajl, template, options, locals
1  test/views/hello.wlang
... ... @@ -0,0 +1 @@
  1 +Hello from wlang!
2  test/views/layout2.wlang
... ... @@ -0,0 +1,2 @@
  1 +WLang Layout!
  2 ++{yield}
64 test/wlang_test.rb
... ... @@ -0,0 +1,64 @@
  1 +require File.expand_path('../helper', __FILE__)
  2 +require 'wlang'
  3 +
  4 +class WLangTest < Test::Unit::TestCase
  5 + def engine
  6 + Tilt::WLangTemplate
  7 + end
  8 +
  9 + def wlang_app(&block)
  10 + mock_app {
  11 + set :views, File.dirname(__FILE__) + '/views'
  12 + get '/', &block
  13 + }
  14 + get '/'
  15 + end
  16 +
  17 + it 'uses the correct engine' do
  18 + assert_equal engine, Tilt[:wlang]
  19 + end
  20 +
  21 + it 'renders .wlang files in views path' do
  22 + wlang_app { wlang :hello }
  23 + assert ok?
  24 + assert_equal "Hello from wlang!\n", body
  25 + end
  26 +
  27 + it 'renders in the app instance scope' do
  28 + mock_app do
  29 + helpers do
  30 + def who; "world"; end
  31 + end
  32 + get('/') { wlang 'Hello +{who}!' }
  33 + end
  34 + get '/'
  35 + assert ok?
  36 + assert_equal 'Hello world!', body
  37 + end
  38 +
  39 + it 'takes a :locals option' do
  40 + wlang_app do
  41 + locals = {:foo => 'Bar'}
  42 + wlang 'Hello ${foo}!', :locals => locals
  43 + end
  44 + assert ok?
  45 + assert_equal 'Hello Bar!', body
  46 + end
  47 +
  48 + it "renders with inline layouts" do
  49 + mock_app do
  50 + layout { 'THIS. IS. +{yield.upcase}!' }
  51 + get('/') { wlang 'Sparta' }
  52 + end
  53 + get '/'
  54 + assert ok?
  55 + assert_equal 'THIS. IS. SPARTA!', body
  56 + end
  57 +
  58 + it "renders with file layouts" do
  59 + wlang_app { wlang 'Hello World', :layout => :layout2 }
  60 + assert ok?
  61 + assert_body "WLang Layout!\nHello World"
  62 + end
  63 +
  64 +end

0 comments on commit 46f2547

Please sign in to comment.
Something went wrong with that request. Please try again.