Canny
Home Download Documentation/ Examples Mailing list ChangeLog Todo Donate SF project page License: LGPL |
Canny
Smarty-like template library for Ruby.
About
Canny is a template library for Ruby. Its template format and features are
very similar to that of the Smarty template
system for PHP.
Canny "compiles" each template into Ruby code when it first encounters it, so subsequent accesses execute without the overhead of template parsing.
Important differences from Smarty
Note:
See the list below also for differences with specific functions.
There are two important differences to be aware of when using Canny+Ruby if you're used to Smarty+PHP:
Smarty:
{ if $section == 1 }
Canny: { if $section == "1" } Smarty: { if $options[0] == "yes" } Canny: { if $options["0"] == "yes" } Non-literal values do not need to be quoted: Smarty/Canny: { if $section == $section_one } Smarty/Canny: { if $options[$num] == $saved_options[$num] }
C.assign('name', '')
C.assign('widgets', 0) { if $name } Welcome, { $name }! { if $widgets } You have { $widgets } widgets. {/if} {else} Welcome, Guest! {/if} Will output: Welcome,! You have 0 widgets.
You can change this behavior, however.
C.empty_string_is_nil = true
C.zero_is_nil = true C.assign('name', '') C.assign('widgets', 0) Using the same template as above, this will output: Welcome, Guest!
What works / what doesn't
|