Re: AMP pages with Tapestry

2016-11-30 Thread Carlos Montero Canabal
Thank you for the response.

AMP validation is very restrictive, so I need write  only, not  or .

So, I go for other fast solution which I use in other project to generate 
emails.

I will show the extended solution in my  tapestry5.dev-util.com 
 webapp, but as a short summary:

AmpPage.java

@Inject
private Block head, body;

...

AmpPage.tml

!doctype html>
http://tapestry.apache.org/schema/tapestry_5_3.xsd";
xmlns:p="tapestry:parameter">



 ...





 ...
 








So AmpPage is the “real" page but it has invalid AMP attributes. So I created a 
AmpExporterPage:

public class AmpExporterPage {

@Inject
private PartialTemplateRenderer partialTemplateRenderer;

@Inject
private ComponentSource componentSource;

@Inject
private Request request;

@Inject
private Environment environment;

public Object onActivate(final EventContext ec) {

return new StreamResponse() {

@Override
public void prepareResponse(final Response response) {

}

@Override
public InputStream getStream() throws IOException {

final AmpPage ampPage = (AmpPage) 
componentSource.getPage(AmpPage.class);
ampPage.onActivate(ec);
ampPage.setupRender();
final Block head = ampPage.getHead();
final Block body = ampPage.getBody();

environment.push(Heartbeat.class, new 
HeartbeatImpl());

String markupHead = 
partialTemplateRenderer.render(head);
String markupBody = 
partialTemplateRenderer.render(body);

markupHead = markupHead.replace(" 
xmlns=\"http://www.w3.org/1999/xhtml\"";, "");
markupHead = 
markupHead.replaceAll("amp-boilerplate=\"amp-boilerplate\"", "amp-boilerplate");

markupBody = markupBody.replace(" 
xmlns=\"http://www.w3.org/1999/xhtml\"";, "");

final StringBuilder sb = new StringBuilder();
sb.append("").append(markupHead).append(markupBody).append("");
final InputStream is = new 
ByteArrayInputStream(sb.toString().getBytes("UTF-8"));

return is;
}

@Override
public String getContentType() {
return "text/html";
}
};
}

}

I do a speed test and it takes around 40 milliseconds in generate de response, 
so it’s ok for me.

Regards

Carlos Montero


> El 30/11/2016, a las 14:06, Thiago H. de Paula Figueiredo 
>  escribió:
> 
> On Tue, Nov 29, 2016 at 6:36 PM, Carlos Montero Canabal <
> carlosmonterocana...@gmail.com> wrote:
> 
>> Hello Tapestry users,
>> 
> 
> Hi!
> 
> 
>> 
>> I would like to create an amp version of my pages into a tapestry5.4
>> webapp. According to https://www.ampproject.org/
>> docs/reference/spec#required-markup > docs/reference/spec#required-markup> the root html only would be:
>> 
>> 
>> 
>> Tapestry5 make a xhtml compilation for the .tml, so I ask you if there is
>> any method to:
>> 
> 
> That's not correct. Tapestry 5 uses an XML parser for template files, and
> attributes without values aren't valid XML. You can try .
> 
> 
>> 1. Exclude de xhtml compilation for this pages
>> 2. Intercept the result and modify it to eliminate additional tags added
>> by Tapestry.
>> 3. Create a MarkupModel for AMPHtml?
>> 
> 
> Number 3 above is probably the best idea. You'll need to override the
> MarkupWriterFactory so you can use your AmpMarkupModel.
> 
> --
> Thiago



Re: AMP pages with Tapestry

2016-11-30 Thread Michael Gentry
Hi Carlos,

I've never used AMP, but see if the following markup will work with it:



mrg


On Tue, Nov 29, 2016 at 3:36 PM, Carlos Montero Canabal <
carlosmonterocana...@gmail.com> wrote:

> Hello Tapestry users,
>
> I would like to create an amp version of my pages into a tapestry5.4
> webapp. According to https://www.ampproject.org/
> docs/reference/spec#required-markup  docs/reference/spec#required-markup> the root html only would be:
>
> 
>
> Tapestry5 make a xhtml compilation for the .tml, so I ask you if there is
> any method to:
>
> 1. Exclude de xhtml compilation for this pages
> 2. Intercept the result and modify it to eliminate additional tags added
> by Tapestry.
> 3. Create a MarkupModel for AMPHtml?
>
> What would be the best solution?
>
> Best regards
>
> Carlos Montero


Re: AMP pages with Tapestry

2016-11-30 Thread Thiago H. de Paula Figueiredo
On Tue, Nov 29, 2016 at 6:36 PM, Carlos Montero Canabal <
carlosmonterocana...@gmail.com> wrote:

> Hello Tapestry users,
>

Hi!


>
> I would like to create an amp version of my pages into a tapestry5.4
> webapp. According to https://www.ampproject.org/
> docs/reference/spec#required-markup  docs/reference/spec#required-markup> the root html only would be:
>
> 
>
> Tapestry5 make a xhtml compilation for the .tml, so I ask you if there is
> any method to:
>

That's not correct. Tapestry 5 uses an XML parser for template files, and
attributes without values aren't valid XML. You can try .


> 1. Exclude de xhtml compilation for this pages
> 2. Intercept the result and modify it to eliminate additional tags added
> by Tapestry.
> 3. Create a MarkupModel for AMPHtml?
>

Number 3 above is probably the best idea. You'll need to override the
MarkupWriterFactory so you can use your AmpMarkupModel.

--
Thiago


AMP pages with Tapestry

2016-11-29 Thread Carlos Montero Canabal
Hello Tapestry users,

I would like to create an amp version of my pages into a tapestry5.4 webapp. 
According to https://www.ampproject.org/docs/reference/spec#required-markup 
 the root html 
only would be:



Tapestry5 make a xhtml compilation for the .tml, so I ask you if there is any 
method to:

1. Exclude de xhtml compilation for this pages
2. Intercept the result and modify it to eliminate additional tags added by 
Tapestry.
3. Create a MarkupModel for AMPHtml?

What would be the best solution?

Best regards

Carlos Montero