[stringtemplate-interest] Model/view separation and equality testing against literals...

Steven Atkinson satkinson at netflix.com
Thu Oct 25 10:18:15 PDT 2007


Folks,

 

I am trying to move people from a 'home-grown' tag language to
StringTemplate.

The home grown language has a very popular
equality-test-against-a-literal feature:

 

" At Halloween we have a large pumpkin $if(pumpkinCount ==1)$ patch
$else$ farm $endif$ in our yard. "

 

(I think they also have '<', '>' operators.)

 

So far as I currently understand it, the "separate model/view" way
around the need to compare literals is to make a view property reference
to a model method that does the comparison, right?

 

e.g. 

 

// Model object

Class Pumpkin {

   int pumpkinCount;

   

   Boolean isSinglePumpkin();

   Boolean isMultiplePumpkins();

}

 

Now we can say:

" At Halloween we have a large pumpkin $if(pumpkin.isSinglePumpkin)$
patch $else$ farm $endif$ in our yard. "

 

Now that's fine, and it would be nice to standardize these things into
"pumpkin" model objects.

Even when I need to do different things depending on if I have 1-50,
51-100, 100-500, 500+ pumpkins....then I can just add more methods to
deal with each band....

 

But - it imposes more work on the modeler to provide the right
properties, and imposes on the template author to learn the properties.

I guess these are both small prices to pay...I know it will feel very
limiting to my template authors who are used to the equality tests...

 

My question is - am I missing an easy way to conditionally branch on an
attribute's value using StringTemplate?

 

(Oh yeah, I have built a  variation on the
indirect-property-value-equality-map hack at
http://opensource.atlassian.com/projects/spring/browse/SPR-3266 but that
only works for non-literals, unless you add literals as attributes to a
map, and it feels and looks really awful :
$if(equals.(pumpkinCount).("1")$   with map.put("1", Integer.valueOf(1))
in the attributes... yuck)

 

 

Thanks

Steve Atkinson.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071025/386c259b/attachment.html 


More information about the stringtemplate-interest mailing list