[stringtemplate-interest] Html encoding

Terence Parr parrt at cs.usfca.edu
Tue Aug 1 11:44:47 PDT 2006


You can try adding default properties to any string by overriding  
setAttribute.  Wrap in a class that knows how to encode with a  
property name.
Ter
On Aug 1, 2006, at 11:34 AM, brian at protexis.com wrote:

> Hi
>
> When using string template to render html, some of the attributes  
> need to
> be html encoded and some do not. At present, I create wrapper  
> classes to
> perform the encoding. Does anyone have a simpler or cleaner solution.
>
> Thanks
>
> For example ...
>
> Here's the wrapper class ...
>
> internal class StructureWrapper
> {
>   Structure m_structure;
>
>   internal StructureWrapper(Structure structure)
>   {
>     this.m_structure = structure;
>   }
>
>   internal string NeedsEncoding
>   {
>     get { return SomeHtmlEncodingFunction(m_structure.ValueOne); }
>   }
>
>   internal string DoesNotNeedEncoding
>   {
>     get { return m_structure.ValueTwo; }
>   }
> }
>
> Here's the set attribute ...
>
> stringTemplate.SetAttribute("structure", structureWrapper);
>
> Here's the st file ...
>
>
>
> $structure.NeedsEncoding$
>
>
>
>
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list