On Jul 10, 2009, at 7:03 AM, JohnMc wrote:

> Before you get too far into it, you might want to take a look at
> CleverCSS. (http://sandbox.pocoo.org/clevercss/). Might be able to
> incorporate it to save some time.

Nice, but I'm not sure it's compelling. And you'd still need to serve  
up a dynamic CSS file.

My needs aren't all that complex, basically a macro facility for  
controlling colors and fonts without having to do a big search &  
replace. The native CSS way to do this is (for example):

h1,h2,h3,h4,.headerclass { font-family: some header fonts; }

h1 { the rest of h1 }

h2 { the rest of h2 }

etc

But in a big file this gets to be very confusing, with definitions  
fragmented all over the place. So if I define the font family either  
as {{variables}} at the front of the file or in the controller, I can  
use:

h1 {
        {{header_font_family}}
}

or the like. The nice thing about the web2py setup is that the whole  
mechanism is already available and well-known--nothing new to learn.

For the record, here's what I ended up with. I made a controller  
called 'css' containing code like this, one method per css file  
(nothing in the dict yet, but that might be a good way to communicate  
my css parameters):

def base():
     response.headers['Content-Type']='text/css'  <<< this was the  
necessary trick
     return dict()

There's a corresponding view called css/base.css (no embedded code  
yet; other than that, it's just a stock CSS file):

body { font-family: Verdana, sans-serif; }
div.beautify td { padding-top: 0; }

Then in layout.html, instead of:

<link rel="stylesheet" media="screen,projection" type="text/css"  
href="{{=URL(request.application,'static','base.css')}}" />

we have:

<link rel="stylesheet" media="screen,projection" type="text/css"  
href="{{=URL(request.application,'css','base.css')}}" />

That's all there is to it, with one exception that I haven't worked  
out yet: the dynamic file is marked as uncached, and that's pretty  
inefficient for CSS if your CSS isn't really dynamic page-to-page,  
which mine is not. I'm assuming that I can edit the response headers  
to specify a ttl. But that's an optimization, and not needed for  
functionality.

I could imagine that web2py might want to do this automatically, and  
adjust the default response headers based on the .css extension of the  
view.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to