diff --git a/CHANGELOG.md b/CHANGELOG.md index 0962972..007ee60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ * Dialect#evaluate (through Scope#evaluate) now accepts an optional block for specifying a computed default value instead of failing. +* WLang::Html partial tag >{...} now recognizes a Proc and simply renders the result of + calling it. This allows to use >{yield} in layouts instead of the less idomatic +{yield}. + # 2.0.1 / 2012-06-12 * Fix support for 1.8.7 and jruby (undefined method `ord' for String) diff --git a/lib/wlang/html.rb b/lib/wlang/html.rb index 505ab3e..82578bf 100644 --- a/lib/wlang/html.rb +++ b/lib/wlang/html.rb @@ -72,6 +72,7 @@ def star(buf, coll_fn, elm_fn, between_fn) def greater(buf, fn) val = evaluate(fn) val = Html.compile(val) if String === val + val = val.call if Proc === val render(val, nil, buf) end diff --git a/spec/integration/html/test_greater.rb b/spec/integration/html/test_greater.rb index f4a7aa0..760b53b 100644 --- a/spec/integration/html/test_greater.rb +++ b/spec/integration/html/test_greater.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'wlang/html' module WLang describe Html, ">{...}" do @@ -25,5 +24,10 @@ def render(tpl, scope = {}) render("Hello >{partial}", binding).should eq("Hello World") end + it 'call a Proc as +{...} does' do + partial = Proc.new{ "World" } + render("Hello >{partial}", binding).should eq("Hello World") + end + end end