... and I'd tend towards a modified version of what he's already done,
which is to strip out the TemplateTokens as they are parsed by the
TemplateParser.  However, what he's done could be improved just a bit.


public TemplateParser decorateTemplateParser(final TemplateParser delegate) {

  return new TemplateParser() {
   public ComponentTemplate parseTemplate(Resource templateResource) {
      final ComponentTemplate standard =
delegate.parseTemplate(templateResource);

      if (standard.isMissing()) return standard;

      final List<TemplateToken> filtered =
filterOutComments(standard.getTokens());

     return  new ComponentTemplate() {

public boolean isMissing() { return false; }

public boolean isExtension() { return standard.isExtension(); }

public List<TemplateToken> getTokens() { return filtered; }

/// etc.
// With special attention to getExtensionPointTokens()

   }


     }
  }
}


On Thu, Mar 10, 2011 at 1:45 PM, Robert Zeigler
<robert.zeig...@roxanemy.com> wrote:
> You could probably do this, if you felt so inclined.
> You can't override SaxTemplateParser directly.  Instead, you would override 
> TemplateParser (contributed by InternalModule), and use that to instantiate 
> your custom/overridden SaxTemplateParser.
> One clarification: template /parsing/ is different from template /rendering/. 
>  Parsing parses the static structure of the page and components.  That should 
> be done only once per page.  /Rendering/ is done every request.
> So using MarkupRendererFilter, the comment removal happens each time.  Using 
> the template parser, the comments never make it into the final rendered page. 
>  BUT.  Using MarkupRendererFilter doesn't involve any internal service 
> monkeying and will be much less bug prone/easier to implement.  Plus, the 
> template parser approach will only remove comments that are hard-coded into 
> the template files.  If someone dynamically adds a comment, you'll miss that.
>
> In general, I would advise going the MarkupRendererFilter route.  I think 
> you'll find it much more convenient and flexible.
>
> Robert
>
> On Mar 10, 2011, at 3/104:39 AM , stephanos2k wrote:
>
>> Would it make more sense (performance-wise) to remove the HTML comments in
>> the 'SaxTemplateParser'?
>>
>> I remembered that there was an option in Tapestry to compress whitespaces
>> from templates. I dug around the Tapestry source a bit and found the
>> 'SaxTemplateParser' which apparently parses each template once before
>> 'using' it for each request (correct me if I'm wrong).
>>
>> What do you think?
>> Can I override the parser somehow?
>>
>> --
>> View this message in context: 
>> http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3423090.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to