You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by stephanos2k <st...@googlemail.com> on 2011/03/09 09:07:35 UTC

remove HTML comments from output

I think Tapestry should be able to remove the HTML comments from the rendered
result
 - IF the user explicitly enables this. I saw that this was discussed
before, but apparently no actions were taken (right?). 

The only reasons I can think of NOT to do it are:

a) slower rendering because of additional computing overhead
-> the overhead is probably quite small, if it isn't, I bet the stripped
version could easily be cached
b) problems with browser specific 'comments' ([if lt IE 6])
-> the  section could simply be ignored (or Javascript can be used for those
conditional commands)

In the end the benefits would be:
-> smaller output
-> comments are kept private - they are for internal purposes only anyway

What do you think?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3415110.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: remove HTML comments from output

Posted by Robert Zeigler <ro...@roxanemy.com>.
MarkupRendererFilter: 
   renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
              renderer.renderMarkup(writer);//allow the rest of the filters to work.
              Document doc = writer.getDocument();
	      //now you can manipulate the dom via the doc variable.
  }


On Mar 10, 2011, at 3/104:14 AM , stephanos2k wrote:

> That sounds interesting.
> 
> #1: Is there any 'documentation' to get started with the
> MarkupRendererFilter? 
> I can't see where exactly I can manipulate the DOM in
> [renderMarkup(MarkupWriter writer, MarkupRenderer renderer)].
> 
> #2: And do you think it's the fastest method? 
> - since, if I understand correctly, this is called for each pageview.
> Couldn't the template itself be filtered only once and the 're-used'?
> 
> Cheers,
> Stephanos
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3423068.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: remove HTML comments from output

Posted by stephanos2k <st...@googlemail.com>.
Cool - thanks for the info!

I just implemented it, works like a charm. In case anyone is interested in
this - here is my code (Scala):

# AppModule
def decorateTemplateParser(parser: TemplateParser) =
        new TemplateParser() {
            import scala.collection.JavaConversions._
            def parseTemplate(templateResource: Resource) = {
                val res = parser.parseTemplate(templateResource)
                val tokens = res.getTokens.filter(t => t.getTokenType !=
TokenType.COMMENT)
                new ComponentTemplateImpl(res.getResource, tokens,
res.getComponentIds, res.isExtension, null)
            }
        }

The only thing I'm confused about is the last constructor parameter of the
ComponentTemplate (Map&lt;String, List&lt;TemplateToken&gt;> overrides)
which I had to set to null because I can't get the data out of the result
object. 

Is this problematic?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3424135.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: remove HTML comments from output

Posted by Howard Lewis Ship <hl...@gmail.com>.
You could decorate the TemplateParser service  and convert its output
to drop the CommentToken objects inside the returned ComponentTemplate
object (that is, return a new ComponentTemplate that filters its
output somewhat).

On Thu, Mar 10, 2011 at 2:39 AM, stephanos2k
<st...@googlemail.com> 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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: remove HTML comments from output

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Fri, Mar 11, 2011 at 3:15 AM, stephanos2k
<st...@googlemail.com> wrote:
> Thanks to you two - I think the TemplateParser option does everything I need
> now. I'm quite amazed how simply Tapestry can be customized.

Thanks. That's an important message, but a hard one to get out.

>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3424881.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: remove HTML comments from output

Posted by stephanos2k <st...@googlemail.com>.
Thanks to you two - I think the TemplateParser option does everything I need
now. I'm quite amazed how simply Tapestry can be customized.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3424881.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: remove HTML comments from output

Posted by Howard Lewis Ship <hl...@gmail.com>.
... 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
<ro...@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-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: remove HTML comments from output

Posted by Robert Zeigler <ro...@roxanemy.com>.
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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: remove HTML comments from output

Posted by stephanos2k <st...@googlemail.com>.
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: remove HTML comments from output

Posted by stephanos2k <st...@googlemail.com>.
That sounds interesting.

#1: Is there any 'documentation' to get started with the
MarkupRendererFilter? 
I can't see where exactly I can manipulate the DOM in
[renderMarkup(MarkupWriter writer, MarkupRenderer renderer)].

#2: And do you think it's the fastest method? 
- since, if I understand correctly, this is called for each pageview.
Couldn't the template itself be filtered only once and the 're-used'?

Cheers,
Stephanos

--
View this message in context: http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3423068.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: remove HTML comments from output

Posted by Cezary Biernacki <ce...@gmail.com>.
Hi,
you can use <t:remove>..</t:remove> to mark parts of template that should
not be rendered
http://tapestry.apache.org/component-templates.html#ComponentTemplates-%3Ct%3Aremove%3E

If you really need to remove comments, you can contribute a
MarkupRendererFilter to MarkupRenderer and just remove all (or some) comment
nodes from DOM before rendering.

Best regards,
Cezary

On Wed, Mar 9, 2011 at 9:07 AM, stephanos2k
<st...@googlemail.com>wrote:

> I think Tapestry should be able to remove the HTML comments from the
> rendered
> result
>  - IF the user explicitly enables this. I saw that this was discussed
> before, but apparently no actions were taken (right?).
>
> The only reasons I can think of NOT to do it are:
>
> a) slower rendering because of additional computing overhead
> -> the overhead is probably quite small, if it isn't, I bet the stripped
> version could easily be cached
> b) problems with browser specific 'comments' ([if lt IE 6])
> -> the  section could simply be ignored (or Javascript can be used for
> those
> conditional commands)
>
> In the end the benefits would be:
> -> smaller output
> -> comments are kept private - they are for internal purposes only anyway
>
> What do you think?
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/remove-HTML-comments-from-output-tp3415110p3415110.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>