You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoffrey Wiseman <ge...@gmail.com> on 2009/03/26 17:47:01 UTC
@IncludeStylesheet and non-local CSS
If I were to build component that uses YUI, and I wanted to attach the
stylesheet from Yahoo (rather than copying it to my application), it doesn't
seem as if @IncludeStylesheet will let me do that; am I correct?
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: @IncludeStylesheet and non-local CSS
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Thu, Mar 26, 2009 at 1:25 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> I think you are on to something, but is bundling YUI locally a real
> problem?
>
It's not a huge problem, no -- I'd just rather get it from the source,
given:
- Yahoo's servers are pretty reliable
- the per-host browser limits on downloads/connections
- the odds that it may already be cached
If I had to pull it down, I could live with it, but seems like it'd be good
to have the option to get it remotely as well.
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: @IncludeStylesheet and non-local CSS
Posted by Fernando Padilla <fe...@alum.mit.edu>.
we use YUI. We simply added a "url" asset factory prefix (which tapestry
should really really add by default actually, like 10 lines of code).
If you want it, I can attach my code easily.
And no, you should not bundle yui locally. It already does a tonne of
on-demand loading, dependency resolution, minimization, and grouping (
which tapestry does now, but you know.. it's using yahoo's CDN ).
actually, I was wondering why tapestry doesn't use google's CDN for
prototype and scriptalicious?
http://code.google.com/apis/ajaxlibs/
Howard Lewis Ship wrote:
> I think you are on to something, but is bundling YUI locally a real problem?
>
> On Thu, Mar 26, 2009 at 10:05 AM, Geoffrey Wiseman
> <ge...@gmail.com> wrote:
>> On Thu, Mar 26, 2009 at 12:47 PM, Geoffrey Wiseman <
>> geoffrey.wiseman@gmail.com> wrote:
>>
>>> If I were to build component that uses YUI, and I wanted to attach the
>>> stylesheet from Yahoo (rather than copying it to my application), it doesn't
>>> seem as if @IncludeStylesheet will let me do that; am I correct?
>>>
>> This was raised before for Javascript (
>> http://markmail.org/thread/pcrp6gzkyvsm37i5) -- while rendering the
>> Javascript right in the body of the page seems like not a big deal, it's not
>> really ideal for CSS, and it doesn't buy you the duplicate-detection that
>> @IncludeStylesheet will. If it's possible to use external paths, even if it
>> means I have to do some plumbing, I'd like to know about it.
>>
>> Looks like it /might/ be able to do this with my own asset factory?
>>
>> - Geoffrey
>> --
>> Geoffrey Wiseman
>> http://www.geoffreywiseman.ca/
>>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Howard Lewis Ship <hl...@gmail.com>.
I think you are on to something, but is bundling YUI locally a real problem?
On Thu, Mar 26, 2009 at 10:05 AM, Geoffrey Wiseman
<ge...@gmail.com> wrote:
> On Thu, Mar 26, 2009 at 12:47 PM, Geoffrey Wiseman <
> geoffrey.wiseman@gmail.com> wrote:
>
>> If I were to build component that uses YUI, and I wanted to attach the
>> stylesheet from Yahoo (rather than copying it to my application), it doesn't
>> seem as if @IncludeStylesheet will let me do that; am I correct?
>>
>
> This was raised before for Javascript (
> http://markmail.org/thread/pcrp6gzkyvsm37i5) -- while rendering the
> Javascript right in the body of the page seems like not a big deal, it's not
> really ideal for CSS, and it doesn't buy you the duplicate-detection that
> @IncludeStylesheet will. If it's possible to use external paths, even if it
> means I have to do some plumbing, I'd like to know about it.
>
> Looks like it /might/ be able to do this with my own asset factory?
>
> - Geoffrey
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Howard Lewis Ship <hl...@gmail.com>.
Another reason to host the YUI scripts locally is so that you can take
advantage of JavaScript combination (in Tapestry 5.1). That only works
if all of the individual script files are located on the server (in
the context, or on the classpath).
On Thu, Mar 26, 2009 at 11:48 AM, Geoffrey Wiseman
<ge...@gmail.com> wrote:
> On Thu, Mar 26, 2009 at 1:40 PM, Dave Greggory <da...@yahoo.com>wrote:
>
>>
>> Just use RenderSupport.
>>
>> I just built my own component named asset attacher for this purpose.
>>
>
> And if anyone's curious what the other approach might look like:
>
> package com.tsg.tapestry;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.MalformedURLException;
> import java.net.URI;
> import java.net.URISyntaxException;
> import java.net.URL;
> import java.util.Locale;
>
> import org.apache.tapestry5.Asset;
> import org.apache.tapestry5.ioc.Resource;
> import org.apache.tapestry5.services.AssetFactory;
>
> public class UriAssetFactory implements AssetFactory {
>
> @Override
> public Asset createAsset(Resource resource) {
> return new UriAsset((UriResource) resource);
> }
>
> @Override
> public Resource getRootResource() {
> return new UriResource();
> }
>
> private static class UriResource implements Resource {
>
> private String path;
> private URI uri;
>
> public UriResource() {
> // root uri resource
> this.path = null;
> this.uri = null;
> }
>
> public UriResource(String path) {
> this.path = path;
> try {
> this.uri = new URI(path);
> } catch (URISyntaxException e) {
> uri = null;
> }
> }
>
> private boolean isRoot() {
> return path == null;
> }
>
> @Override
> public boolean exists() {
> if (uri != null) {
> return true;
> } else {
> return false;
> }
> }
>
> @Override
> public Resource forFile(String relativePath) {
> if (isRoot()) {
> return new UriResource(relativePath);
> } else {
> return new UriResource(this.getFolder() + '/' +
> relativePath);
> }
> }
>
> /**
> * URI Resources can't be localized -- at least, not in any easy
> manner.
> */
> @Override
> public Resource forLocale(Locale locale) {
> return this;
> }
>
> @Override
> public String getFile() {
> if (isRoot()) {
> return "";
> } else {
> int index = path.lastIndexOf('/');
> if (index == -1) {
> return path;
> } else {
> return path.substring(index + 1);
> }
> }
> }
>
> @Override
> public String getFolder() {
> if (isRoot()) {
> return "";
> } else {
> int index = path.lastIndexOf('/');
> if (index == -1) {
> return "";
> } else {
> return path.substring(0, index);
> }
> }
> }
>
> @Override
> public String getPath() {
> return path;
> }
>
> @Override
> public InputStream openStream() throws IOException {
> if (isRoot()) {
> throw new IOException("Cannot open stream for root uri.");
> } else if (uri == null) {
> throw new IOException("Cannot open stream for malformed
> uri.");
> } else {
> return uri.toURL().openStream();
> }
> }
>
> @Override
> public URL toURL() {
> if (uri == null) {
> try {
> return uri.toURL();
> } catch (MalformedURLException e) {
> return null;
> }
> } else {
> return null;
> }
> }
>
> @Override
> public Resource withExtension(String extension) {
> if (isRoot()) {
> return this;
> } else {
> int index = path.lastIndexOf('.');
> if (index == -1) {
> return new UriResource(path + '.' + extension);
> } else {
> return new UriResource(path.substring(0, index + 1)
> + extension);
> }
> }
> }
>
> }
>
> private static class UriAsset implements Asset {
>
> private UriResource resource;
>
> public UriAsset(UriResource resource) {
> this.resource = resource;
> }
>
> @Override
> public Resource getResource() {
> return resource;
> }
>
> @Override
> public String toClientURL() {
> return resource.getPath();
> }
>
> }
>
> }
>
>
> package com.tsg.crystal.web.services;
>
> import org.apache.tapestry5.ioc.MappedConfiguration;
> import org.apache.tapestry5.services.AssetFactory;
>
> import com.tsg.tapestry.UriAssetFactory;
>
> public class TapestryModule {
>
> public static void contributeAssetSource(
> MappedConfiguration<String, AssetFactory> configuration) {
> configuration.add("uri", new UriAssetFactory());
> }
> }
>
>
>
> @IncludeStylesheet( {
> "uri:
> http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css
> ",
> "uri:http://yui.yahooapis.com/2.7.0/build/base/base-min.css" })
>
>
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Fernando Padilla <fe...@alum.mit.edu>.
I vote that this is added to tapestry-core. :)
Robert Zeigler wrote:
> The Chenillekit module provides a URIAssetFactory, as well; I've just
> started playing with this library, but I've been pretty pleased so far.
>
> Robert
>
> On Mar 26, 2009, at 3/2610:06 PM , Geoffrey Wiseman wrote:
>
>> On Thu, Mar 26, 2009 at 9:53 PM, Fernando Padilla <fe...@alum.mit.edu>
>> wrote:
>>
>>> that's exactly what we do.. we just named it "url", instead of "uri".
>>> :) :)
>>
>>
>> Well, it's a trivial piece of code, so if a committer wants to run
>> with it -
>> feel free, although you might want to check to make sure I didn't do
>> something inappropriate along the way, as there are pieces (e.g.
>> localization) that I can't easily address in this setup.
>>
>> - Geoffrey
>> --
>> Geoffrey Wiseman
>> http://www.geoffreywiseman.ca/
>
>
> ---------------------------------------------------------------------
> 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: @IncludeStylesheet and non-local CSS
Posted by Robert Zeigler <ro...@scazdl.org>.
The Chenillekit module provides a URIAssetFactory, as well; I've just
started playing with this library, but I've been pretty pleased so far.
Robert
On Mar 26, 2009, at 3/2610:06 PM , Geoffrey Wiseman wrote:
> On Thu, Mar 26, 2009 at 9:53 PM, Fernando Padilla
> <fe...@alum.mit.edu> wrote:
>
>> that's exactly what we do.. we just named it "url", instead of
>> "uri". :) :)
>
>
> Well, it's a trivial piece of code, so if a committer wants to run
> with it -
> feel free, although you might want to check to make sure I didn't do
> something inappropriate along the way, as there are pieces (e.g.
> localization) that I can't easily address in this setup.
>
> - Geoffrey
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Thu, Mar 26, 2009 at 9:53 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:
> that's exactly what we do.. we just named it "url", instead of "uri". :) :)
Well, it's a trivial piece of code, so if a committer wants to run with it -
feel free, although you might want to check to make sure I didn't do
something inappropriate along the way, as there are pieces (e.g.
localization) that I can't easily address in this setup.
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: @IncludeStylesheet and non-local CSS
Posted by Fernando Padilla <fe...@alum.mit.edu>.
that's exactly what we do.. we just named it "url", instead of "uri". :) :)
Geoffrey Wiseman wrote:
> On Thu, Mar 26, 2009 at 1:40 PM, Dave Greggory <da...@yahoo.com>wrote:
>
>> Just use RenderSupport.
>>
>> I just built my own component named asset attacher for this purpose.
>>
>
> And if anyone's curious what the other approach might look like:
>
> package com.tsg.tapestry;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.MalformedURLException;
> import java.net.URI;
> import java.net.URISyntaxException;
> import java.net.URL;
> import java.util.Locale;
>
> import org.apache.tapestry5.Asset;
> import org.apache.tapestry5.ioc.Resource;
> import org.apache.tapestry5.services.AssetFactory;
>
> public class UriAssetFactory implements AssetFactory {
>
> @Override
> public Asset createAsset(Resource resource) {
> return new UriAsset((UriResource) resource);
> }
>
> @Override
> public Resource getRootResource() {
> return new UriResource();
> }
>
> private static class UriResource implements Resource {
>
> private String path;
> private URI uri;
>
> public UriResource() {
> // root uri resource
> this.path = null;
> this.uri = null;
> }
>
> public UriResource(String path) {
> this.path = path;
> try {
> this.uri = new URI(path);
> } catch (URISyntaxException e) {
> uri = null;
> }
> }
>
> private boolean isRoot() {
> return path == null;
> }
>
> @Override
> public boolean exists() {
> if (uri != null) {
> return true;
> } else {
> return false;
> }
> }
>
> @Override
> public Resource forFile(String relativePath) {
> if (isRoot()) {
> return new UriResource(relativePath);
> } else {
> return new UriResource(this.getFolder() + '/' +
> relativePath);
> }
> }
>
> /**
> * URI Resources can't be localized -- at least, not in any easy
> manner.
> */
> @Override
> public Resource forLocale(Locale locale) {
> return this;
> }
>
> @Override
> public String getFile() {
> if (isRoot()) {
> return "";
> } else {
> int index = path.lastIndexOf('/');
> if (index == -1) {
> return path;
> } else {
> return path.substring(index + 1);
> }
> }
> }
>
> @Override
> public String getFolder() {
> if (isRoot()) {
> return "";
> } else {
> int index = path.lastIndexOf('/');
> if (index == -1) {
> return "";
> } else {
> return path.substring(0, index);
> }
> }
> }
>
> @Override
> public String getPath() {
> return path;
> }
>
> @Override
> public InputStream openStream() throws IOException {
> if (isRoot()) {
> throw new IOException("Cannot open stream for root uri.");
> } else if (uri == null) {
> throw new IOException("Cannot open stream for malformed
> uri.");
> } else {
> return uri.toURL().openStream();
> }
> }
>
> @Override
> public URL toURL() {
> if (uri == null) {
> try {
> return uri.toURL();
> } catch (MalformedURLException e) {
> return null;
> }
> } else {
> return null;
> }
> }
>
> @Override
> public Resource withExtension(String extension) {
> if (isRoot()) {
> return this;
> } else {
> int index = path.lastIndexOf('.');
> if (index == -1) {
> return new UriResource(path + '.' + extension);
> } else {
> return new UriResource(path.substring(0, index + 1)
> + extension);
> }
> }
> }
>
> }
>
> private static class UriAsset implements Asset {
>
> private UriResource resource;
>
> public UriAsset(UriResource resource) {
> this.resource = resource;
> }
>
> @Override
> public Resource getResource() {
> return resource;
> }
>
> @Override
> public String toClientURL() {
> return resource.getPath();
> }
>
> }
>
> }
>
>
> package com.tsg.crystal.web.services;
>
> import org.apache.tapestry5.ioc.MappedConfiguration;
> import org.apache.tapestry5.services.AssetFactory;
>
> import com.tsg.tapestry.UriAssetFactory;
>
> public class TapestryModule {
>
> public static void contributeAssetSource(
> MappedConfiguration<String, AssetFactory> configuration) {
> configuration.add("uri", new UriAssetFactory());
> }
> }
>
>
>
> @IncludeStylesheet( {
> "uri:
> http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css
> ",
> "uri:http://yui.yahooapis.com/2.7.0/build/base/base-min.css" })
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Thu, Mar 26, 2009 at 1:40 PM, Dave Greggory <da...@yahoo.com>wrote:
>
> Just use RenderSupport.
>
> I just built my own component named asset attacher for this purpose.
>
And if anyone's curious what the other approach might look like:
package com.tsg.tapestry;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.services.AssetFactory;
public class UriAssetFactory implements AssetFactory {
@Override
public Asset createAsset(Resource resource) {
return new UriAsset((UriResource) resource);
}
@Override
public Resource getRootResource() {
return new UriResource();
}
private static class UriResource implements Resource {
private String path;
private URI uri;
public UriResource() {
// root uri resource
this.path = null;
this.uri = null;
}
public UriResource(String path) {
this.path = path;
try {
this.uri = new URI(path);
} catch (URISyntaxException e) {
uri = null;
}
}
private boolean isRoot() {
return path == null;
}
@Override
public boolean exists() {
if (uri != null) {
return true;
} else {
return false;
}
}
@Override
public Resource forFile(String relativePath) {
if (isRoot()) {
return new UriResource(relativePath);
} else {
return new UriResource(this.getFolder() + '/' +
relativePath);
}
}
/**
* URI Resources can't be localized -- at least, not in any easy
manner.
*/
@Override
public Resource forLocale(Locale locale) {
return this;
}
@Override
public String getFile() {
if (isRoot()) {
return "";
} else {
int index = path.lastIndexOf('/');
if (index == -1) {
return path;
} else {
return path.substring(index + 1);
}
}
}
@Override
public String getFolder() {
if (isRoot()) {
return "";
} else {
int index = path.lastIndexOf('/');
if (index == -1) {
return "";
} else {
return path.substring(0, index);
}
}
}
@Override
public String getPath() {
return path;
}
@Override
public InputStream openStream() throws IOException {
if (isRoot()) {
throw new IOException("Cannot open stream for root uri.");
} else if (uri == null) {
throw new IOException("Cannot open stream for malformed
uri.");
} else {
return uri.toURL().openStream();
}
}
@Override
public URL toURL() {
if (uri == null) {
try {
return uri.toURL();
} catch (MalformedURLException e) {
return null;
}
} else {
return null;
}
}
@Override
public Resource withExtension(String extension) {
if (isRoot()) {
return this;
} else {
int index = path.lastIndexOf('.');
if (index == -1) {
return new UriResource(path + '.' + extension);
} else {
return new UriResource(path.substring(0, index + 1)
+ extension);
}
}
}
}
private static class UriAsset implements Asset {
private UriResource resource;
public UriAsset(UriResource resource) {
this.resource = resource;
}
@Override
public Resource getResource() {
return resource;
}
@Override
public String toClientURL() {
return resource.getPath();
}
}
}
package com.tsg.crystal.web.services;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.services.AssetFactory;
import com.tsg.tapestry.UriAssetFactory;
public class TapestryModule {
public static void contributeAssetSource(
MappedConfiguration<String, AssetFactory> configuration) {
configuration.add("uri", new UriAssetFactory());
}
}
@IncludeStylesheet( {
"uri:
http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css
",
"uri:http://yui.yahooapis.com/2.7.0/build/base/base-min.css" })
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: @IncludeStylesheet and non-local CSS
Posted by Dave Greggory <da...@yahoo.com>.
Just use RenderSupport.
I just built my own component named asset attacher for this purpose.
public class AssetAttacher
{
@Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
private String assetURL;
@Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
private String assetType;
@Inject
private EnvironmentAssetAliasManager assetAliasManager;
@Environmental
private RenderSupport renderSupport;
@SetupRender
public boolean attach()
{
if (assetType.equalsIgnoreCase("javascript"))
{
renderSupport.addScriptLink(assetURL);
}
else
{
renderSupport.addStylesheetLink(assetURL, null);
}
// short circuit to prevent rendering of body (since there's no tml for this component)
return false;
}
}
Then from other components tml, just include the AssetAttacher.
<t:AssetAttacher t:assetURL="http://www.differentsite.com/my.css" t:assetType="stylesheet"/>
or
<t:AssetAttacher t:assetURL="http://www.differentsite.com/my.js" t:assetType="javascript
"/>
----- Original Message ----
From: Geoffrey Wiseman <ge...@gmail.com>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Thursday, March 26, 2009 1:05:52 PM
Subject: Re: @IncludeStylesheet and non-local CSS
On Thu, Mar 26, 2009 at 12:47 PM, Geoffrey Wiseman <
geoffrey.wiseman@gmail.com> wrote:
> If I were to build component that uses YUI, and I wanted to attach the
> stylesheet from Yahoo (rather than copying it to my application), it doesn't
> seem as if @IncludeStylesheet will let me do that; am I correct?
>
This was raised before for Javascript (
http://markmail.org/thread/pcrp6gzkyvsm37i5) -- while rendering the
Javascript right in the body of the page seems like not a big deal, it's not
really ideal for CSS, and it doesn't buy you the duplicate-detection that
@IncludeStylesheet will. If it's possible to use external paths, even if it
means I have to do some plumbing, I'd like to know about it.
Looks like it /might/ be able to do this with my own asset factory?
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @IncludeStylesheet and non-local CSS
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Thu, Mar 26, 2009 at 12:47 PM, Geoffrey Wiseman <
geoffrey.wiseman@gmail.com> wrote:
> If I were to build component that uses YUI, and I wanted to attach the
> stylesheet from Yahoo (rather than copying it to my application), it doesn't
> seem as if @IncludeStylesheet will let me do that; am I correct?
>
This was raised before for Javascript (
http://markmail.org/thread/pcrp6gzkyvsm37i5) -- while rendering the
Javascript right in the body of the page seems like not a big deal, it's not
really ideal for CSS, and it doesn't buy you the duplicate-detection that
@IncludeStylesheet will. If it's possible to use external paths, even if it
means I have to do some plumbing, I'd like to know about it.
Looks like it /might/ be able to do this with my own asset factory?
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/