On Fri, Jul 10, 2009 at 12:14, Jonathan Lundell<jlund...@pobox.com> wrote: > > 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 can test setting HTTP header Pragma to 'no-cache' as W3C says[1] or if you are suspecting that web2py is setting headers in a way you don't want you could view headers (using Firefox addon Live HTTP Headers, wget etc.) to make sure it's ok. An example: <code> alv...@estavel:~$ wget --server-response http://localhost:8000 --2009-07-10 12:40:16-- http://localhost:8000/ Resolving localhost... 127.0.0.1 Connecting to localhost|127.0.0.1|:8000... connected. HTTP request sent, awaiting response... HTTP/1.1 303 SEE OTHER Content-Type: text/html; charset=UTF-8 Location: /welcome/default/index Date: Fri, 10 Jul 2009 15:40:16 GMT Server: CherryPy/3.1.0beta3 WSGI Server Location: /welcome/default/index [following] --2009-07-10 12:40:16-- http://localhost:8000/welcome/default/index Connecting to localhost|127.0.0.1|:8000... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Set-Cookie: session_id_welcome=127-0-0-1-def969db-1334-4a49-80cc-5125fa524cf3; Path=/ Expires: Fri, 10 Jul 2009 15:40:16 GMT Content-Type: text/html; charset=UTF-8 Pragma: no-cache Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Date: Fri, 10 Jul 2009 15:40:16 GMT Server: CherryPy/3.1.0beta3 WSGI Server Length: unspecified [text/html] Saving to: `index' [ <=> ] 5,236 --.-K/s in 0s 2009-07-10 12:40:16 (150 MB/s) - `index' saved [5236] alv...@estavel:~$ </code> When I want to avoid browser's features that I can't control or don't know how works I simply get page with wget: it is simple and do eactly what I want. :-) [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32 -- Álvaro Justen Peta5 - Telecomunicações e Software Livre 21 3021-6001 / 9898-0141 http://www.peta5.com.br/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---