There is a Parse::RecDescent CSS parser inside CSS.pm that might be useful to you. I was thinking of writing an adaptor module for CSS.pm that allows it to output a 4.01 compliant scalar of properties/attributes for any given selector. Then instead of including the CSS directly, as you show:
> INCLUDE config/stylesheet > name="body" > code={ > key => "body", > value => > "font-family:Helvetica,Arial,Sans-Serif;color:#000000;background:#ffffff;" > }; > you can do something more like this: [% use CSS %] [% mycss = CSS.new(csspath) %] [% ... name = "body" code = mycss.style("body") %] foreach html tag you want to stylize. CSS.pm should be flexible enough for you to store javascript handlers in the CSS file as well, but the parser might require a bit of tweaking. You would access them something like this: [% js = mycss.style("body").javascript %] -Allen On Sat, 27 Apr 2002, Matthew Gream wrote: > > Someone recently mentioned adding css support - I've started down the road > to a half-baked support using the following mechanism (and in the next > couple of weeks I'm sure that I'll have it refined). Here's an example how I > use the same mechanism for javascript. I am already supporting inline CSS so > that I can entirely use 4.01/Strict. To support embedded CSS I plan to make > "config/stylesheet" sophisticated enough to do moderate optimisation to > aggregating duplicate properties and so on. Half-baked at the moment but > hopefully can illustrate some direction. > > I've only been using TT2 for about 1-2 months now, so this probably > illustrates some of my naviety :-). > > Matthew. > > //-------------------------------------------------------------------------- > ------ > // config/otherlink > //-------------------------------------------------------------------------- > ------ > > [%# ARGS > # link # link URL > # text # link text, defaults to link URL > -%] > [% IF link -%] > <a href="[% link %]" onclick="return window_open('[% link %]');"> > [%- > INCLUDE config/javascript > name="window_open" > code={ > key => "function window_open(url)", > value => > "window.open(url,'Window','width=640,height=480,scrollbars=yes,resizable=yes > '); return false;" > }; > -%] > [%- END -%] > [% text or link %] > [%- "</a>" IF link -%] > > //-------------------------------------------------------------------------- > ------ > // config/javascript > //-------------------------------------------------------------------------- > ------ > [%- > IF name AND code; > j_lookup = 0; > FOREACH j = html.head.script.java; > IF j_lookup == 0 AND j.name == name; > j_lookup = 1; > END; > END; > IF j_lookup == 0; > html.head.script.java.push({ name => name, code => code }); > END; > END; > -%] > > //-------------------------------------------------------------------------- > ------ > // usr/local/tt2/templates/html/head > //-------------------------------------------------------------------------- > ------ > ... > [% FOREACH i = html.head.script.java -%] > [% IF loop.first %] <script type="text/javascript"> > <!-- > [% END -%] > [% i.code.key %] { [% i.code.value %] } > [% IF loop.last %] --> > </script> > [% END -%] > [% END -%] > ... > [% FOREACH i = html.head.style.css -%] > [% IF loop.first %] <style type="text/css"> > <!-- > [% END -%] > [% i.code.key %] { [% i.code.value %] } > [% IF loop.last %] --> > </style> > [% END -%] > [% END -%] > ... > //-------------------------------------------------------------------------- > ------ > // config/defaults > //-------------------------------------------------------------------------- > ------ > INCLUDE config/stylesheet > name="body" > code={ > key => "body", > value => > "font-family:Helvetica,Arial,Sans-Serif;color:#000000;background:#ffffff;" > }; > > > -- > [EMAIL PROTECTED] > > > _______________________________________________ > templates mailing list > [EMAIL PROTECTED] > http://www.template-toolkit.org/mailman/listinfo/templates >