Dashboard > MonoRail > Home > Castle.NVelocity Discussions
Castle.NVelocity Discussions
Added by Fábio David Batista, last edited by Stuart Carnie on May 15, 2007  (view change)
Labels: 


Introduce here your idea for a possible new Castle.NVelocity.

Comments on each idea are appreciated.

Formal References to Directives 

Allowing formal references to directives, just like they added to the lastest Velocity, so cases like the following are possible:

<span class="#{if($test)}class1#{else}class2#{end}">

Discarding the Result of a Method Call

Just like JavaScript's void:

#void($myObject.someMethodThatReturnsSomethingIDontWant(...)})

Allow simple String.Format shortcuts

<td> $myObj.moneyProperty%n2 </td>
<td> $myObj.dateProperty%MM/dd/yyyy </td>
<td> ${myObj.dateProperty%MMM, dd yyyy}</td>

"Escaping Objects"

Allow "escaping objects", that can be supplied to the template engine, maybe implementing somethink like ITextEscape:

<td> $myObj.complexTextData%xmlescape </td>
<script> alert("$myObj.textData%jsescape") </script>
$myObj.text%customescape

Select Case

#switch ($var)
  #case (1)
    ...
  #case (2)
    ...
#end

Eval

#set ($templateText = 'Welcome, $name') ## would probably come from DB or something
#set ($name = 'Lord')

#eval ($templateText) ## renders the result
#eval ($result = $templateText) ## saves into a variable

With Block

#with ($customer)
  $name
  $address.street
#end

Support for Clearer Block Closing

In addition to use #end to finish blocks, Castle.NVelocity should accept a fully-specified end clause.

#if (...)
  ...
#endif

#with (...)
  ...
#endwith

Named Parameters on Method Calls

Add support for named parameters on method calls, using default values for unspecified parameters. Would make helpers a lot cleaner:

$ajaxHelper.buttonToRemote(innerContent: "test", url: "...")

Line Breaks on Long Method Calls

Support for line breaks on method calls (I never tested, maybe it already works):

$ajaxHelper.buttonToRemote(
  innerContent: "test",
  url: "..."
)

Better dictionary notation

Already discussed a lot.

Extension Methods

Support for C# 3.0 style extensions methods in the engine, would make it easier to extend the engine. This would simplify the ability to implement the Castle specific to_quote and to_squote functions.

$myObj.StringProperty.to_quote()
$myObj.StringProperty.to_squote()

In addition, the syntax for 'Escaping Objects' could be via extension methods and implementation would be trivial.

<td> $myObj.complexTextData.XmlEscape() </td>
<script> alert("$myObj.textData.JsEscape()") </script>
$myObj.text.CustomEscape()

#options directive

Add support for an options directive to allow specific templates to configure the engine at render time.
The #options directive should be extensible via configuration, such that new options could be easily registered.

Existing directives, such as #foreach could implement an IOptions (or similar) interface, to register for configuration. The options could use a dotted notation, and exposed via a series of name / value pairs. An example of an option for #foreach could be

#options ( foreach.NewLines=off, foreach.SomeOtherOption=value )

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators