On Oct 6, 2009, at 2:54 PM, Eric Vicenti wrote: > > Thanks, mdi and Jonathan. I will borrow your __cssheaders() function, > if you don't mind. > > Is there any way to have some code in the css.py controller which will > automatically define functions for all my css files in /views/css/ ? > All it would need to do is run the __cssheaders() function and return > dict(), but it feels unnecessary to maintain a list of functions when > there are files.
That would be useful. I'd like to see built-in support for dynamic CSS generation, but for me to do it, it'd take a bit of a research project on the views subsystem that I don't have time for. It's a different problem from other dynamic files (html, rss, etc) where most of the content is dynamic. In the case of CSS, each file has very different static content, and the dynamic content is a relatively small part of it. > -Eric > > On Oct 6, 2:29 pm, Jonathan Lundell <[email protected]> wrote: >> On Oct 6, 2009, at 1:35 PM, mdipierro wrote: >> >>> It is good practice to put in the CSS only relative urls to other >>> static files. That is not a problem with web2py. >> >>> If you need to include in the CSS urls generated by {{=URL(....)}} >>> then you should promote the css from a static file to a dynamic >>> page: >>> 1) make a controller for it >>> 2) make a view ending in .css >>> 3) call the action from the layout ending in .css >>> 4) in the .css view use absolute paths to include images >> >> When I tried serving dynamic CSS (I wanted to dynamically control >> colors, fonts, etc), I had to do some work to get the result served >> as >> text/css (which is necessary). I ended up hacking that (and some >> other >> header stuff, like caching) in the controller, but I suppose it could >> happen in the view. >> >> I notice that there's no generic.css. >> >> I have a controller, css.py, that looks like this: >> >> import time >> from gluon.storage import Storage >> >> def __cssheaders(): >> ''' >> edit default response headers for CSS >> serve text/css with limited caching >> ''' >> response.cookies = Storage() >> response.headers['Content-Type']='text/css' >> response.headers['Cache-Control'] = 'max-age=3600, must- >> revalidate' >> if 'Last-Modified' in response.headers: del response.headers >> ['Last-Modified'] >> if 'Expires' in response.headers: del response.headers >> ['Expires'] >> if 'Pragma' in response.headers: del response.headers['Pragma'] >> >> def xxx(): >> ''' >> app/css/xxx.css >> set fonts and colors to be substituted via xxx.css view >> ''' >> __cssheaders() >> font_serif = 'cambria, georgia, "times new roman", serif' >> font_sans = 'corbel, "Helvetica Neue", Helvetica, Arial, sans- >> serif' >> return dict(dark_color="#8e1650", second_color="#635e54", >> light_color="#e9e7de", >> accent_color="#edab05", flash_color="white", >> flash_background="#8e1650", >> body_background_color="#e8e8e8", >> content_background_color="white", >> font_body=font_serif, >> font_logo=font_sans, >> font_head=font_sans,) > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" 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 -~----------~----~----~----~------~----~------~--~---

