Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add documentation for Radius and improve implementation

  • Loading branch information...
commit c43c8d1d3811a4658312d3d8f3935ee4923b26e0 1 parent b280796
@trans trans authored
View
2  README.md
@@ -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.
View
54 TEMPLATES.md
@@ -432,3 +432,57 @@ 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! }
@rkh Collaborator
rkh added a note

There is a quote missing after "Jackpot!.

@rtomayko Owner

Nice catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+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/)
+
View
11 lib/tilt.rb
@@ -753,6 +753,7 @@ def evaluate(scope, locals, &block)
end
register 'coffee', CoffeeTemplate
+
# Radius Template
# http://github.com/jlong/radius/
class RadiusTemplate < Template
@@ -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
View
10 test/tilt_radiustemplate_test.rb
@@ -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.'
Please sign in to comment.
Something went wrong with that request. Please try again.