Skip to content

Commit

Permalink
Merge radius updates from trans/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed May 13, 2010
2 parents 4bdc4a8 + c43c8d1 commit b8e105b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,8 @@ Support for these template engines is included with the package:
Mustache .mustache mustache
RDiscount .markdown rdiscount
RedCloth .textile redcloth
RDoc .rdoc rdoc
Radius .radius radius

See [TEMPLATES.md][t] for detailed information on template engine
options and supported features.
Expand Down
53 changes: 53 additions & 0 deletions TEMPLATES.md
Expand Up @@ -432,3 +432,56 @@ engine in a threaded environment.
### See also

* [RDoc](http://rdoc.sourceforge.net/doc/index.html)


<a name='radius'></a>
Radius (`radius`)
-----------------

Radius is the template language used by Radiant CMS. It is a tag
language designed to be valid XML/HTML.

### Example

<html>
<body>
<h1><r:title /></h1>
<ul class="<r:type />">
<r:repeat times="3">
<li><r:hello />!</li>
</r:repeat>
</ul>
<r:yield />
</body>
</html>

### Usage

To render a template such as the one above.

scope = OpenStruct.new
scope.title = "Radius Example"
scope.hello = "Hello, World!"

require 'radius'
template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
template.render(scope, :type=>'hlist'){ "Jackpot! }

The result will be:

<html>
<body>
<h1>Radius Example</h1>
<ul class="hlist">
<li>Hello, World!</li>
<li>Hello, World!</li>
<li>Hello, World!</li>
</ul>
Jackpot!
</body>
</html>

### See also

* [Radius](http://radius.rubyforge.org/)
* [Radiant](http://radiantcms.org/)
11 changes: 8 additions & 3 deletions lib/tilt.rb
Expand Up @@ -753,6 +753,7 @@ def evaluate(scope, locals, &block)
end
register 'coffee', CoffeeTemplate


# Radius Template
# http://github.com/jlong/radius/
class RadiusTemplate < Template
Expand All @@ -774,12 +775,16 @@ def evaluate(scope, locals, &block)
if locals.key?(tag.to_sym)
locals[tag.to_sym]
else
scope.__send__(tag) # any way to support attr as args?
if scope.respond_to?(:__tilt__) # FIXME: is this right?
scope.__send__(tag) # any way to support attr as args?
else
scope.instance_eval(tag)
end
end
end
end
# TODO: how to config tag prefix?
parser = Radius::Parser.new(@context, :tag_prefix => 'r')
options = {:tag_prefix => 'r'}.merge(@options)
parser = Radius::Parser.new(@context, options)
parser.parse(data)
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/tilt_radiustemplate_test.rb
Expand Up @@ -41,6 +41,16 @@ def whisky; 'wetter'; end
template.render(scope, :beer => 'great', :whisky => 'greater')
end

#test "handles local scope" do
# beer = 'wet'
# whisky = 'wetter'
#
# template = Tilt::RadiusTemplate.new {
# 'Beer is <r:beer /> but Whisky is <r:whisky />.'
# }
# assert_equal "Beer is wet but Whisky is wetter.", template.render(self)
#end

test "passing a block for yield" do
template = Tilt::RadiusTemplate.new {
'Beer is <r:yield /> but Whisky is <r:yield />ter.'
Expand Down

0 comments on commit b8e105b

Please sign in to comment.