You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by gbrits <gb...@gmail.com> on 2010/11/23 13:36:50 UTC

T5: auto-combining css

Hi ,

like JS I would like to be able to auto-combine css-stylesheets. 

Does anyone have an example of how to correctly do this? 

I quickly tried to do something on my own, overriding DocumentLinkerImpl and
effectively mimicking the combination-code for JS (see below) 

Although the resulting css contains all stylesheets rules, etc. no browser
seems to be able to read the rules. 
I guess some code down the chain does something incompatible to the css-file
(writing wrong mime-type?)  resulting in this behavior. 

Anyone got any working code, or alternatively knows how to make my below
code work? 

Thanks,
Geert-Jan 



//the below code is called from  changed method: 
protected void addStylesheetsToHead(Element root, List<IncludedStylesheet>
stylesheets)

////
 private void addCombinedStylesheetLink(Element container,
LinkedHashSet<String> stylesheets2)
    {
        try
        {
            ClientDataSink dataSink = clientDataEncoder.createSink();

            ObjectOutputStream stream = dataSink.getObjectOutputStream();

            stream.writeInt(stylesheets2.size());

            for (String stylesheetURL : stylesheets2)
            {
                // Each scriptURL will be prefixed with the context path,
which isn't needed to build the combined virtual
                // asset (in fact, it gets in the way).

                stream.writeUTF(stylesheetURL.substring(contextPathLength));
            }

            String virtualURL = fullAssetPrefix +
RequestConstants.VIRTUAL_FOLDER + dataSink.getEncodedClientData() + ".css";
            
            container.element("link",
            		 		  "href", virtualURL,
            				  "rel", "stylesheet",
                              "type", "text/css",
                              "media","screen, print"
                             );
        }
        catch (IOException ex)
        {
            throw new RuntimeException(ex);
        }

-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-auto-combining-css-tp3276708p3276708.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