I'v been using Pyramid for a week now, and i love it. I started using
pylons before i noticed the pyramid project. I think pyramid seems
simpler.
So i thought i would share a scss renderer that i just made, and maybe
get feedback. If im doing it the right way, i mean. And if someone
else thinks its
usefull maybe it could get added. PyScss is quite fast, so the
performance penalty is minimal.

The config will need a line like:

scss.path = myapp:templates

The renderer:

from pyramid.asset import abspath_from_asset_spec
from pyscss.scss import Scss
import os

def scss_renderer_factory(info):
    template =
os.path.join(abspath_from_asset_spec(info.settings.get('scss.path',
False)),info.name)
    f = open(template)
    s = f.read()
    f.close()
    def _render(value, system):
        request = system.get('request')
        if request is not None:
            if not hasattr(request, 'response_content_type'):
                request.response_content_type = 'text/css'
        css = Scss()
        return css.compile(s)
    return _render

In __init__.py:

config.add_renderer('.scss', scss_renderer_factory)
config.add_route('style', '/style')

Then it can be used in the views:

@view_config(route_name="style", renderer="style.scss")
def get_settings(request):
    return {'foo':'bar'}


And the template/style.scss:
@option compress: no;

@mixin rounded($side, $radius: 10px) {
    border-#{$side}-radius: $radius;
    -moz-border-radius-#{$side}: $radius;
    -webkit-border-#{$side}-radius: $radius;
}

#navbar li { @include rounded(top); }
#footer { @include rounded(top, 5px); }
#sidebar { @include rounded(left, 8px); }

Please comment if things should be done differently.
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.

Reply via email to