Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using the Less filter, there's no way to combine CSS and Less in a bundle #120

Closed
bradwright opened this issue Mar 16, 2012 · 6 comments
Milestone

Comments

@bradwright
Copy link
Contributor

Given this Bundle code:

less_css = Bundle(
    'css/base.less',
    filters='less')

css = Bundle(
    'css/reset.css',
    less_css,
    output='css/main.%(version)s.css')

environment.register('css_main', css)

and this template:

{% assets "css_main" %}
    <link rel="stylesheet" type="text/css" href="{{ ASSET_URL }}">
{% endassets %}

I can't combine my Less file and my CSS file in a final file as it won't work in development (due to not having rel="stylesheet/less" in the file).

@sciyoshi
Copy link

See the CSS compiler documentation page - your first bundle should include debug=False and an output file for it to work in debug mode as well.

@bradwright
Copy link
Contributor Author

If it has an output file I can't really debug errors - the files should be separate to debug them correctly.

Anyway I did this as a temporary workaround:

{% assets "css_main" %}
    <link rel="stylesheet{% if ASSET_URL.endswith('.less') %}/less{% endif %}" type="text/css" href="{{ ASSET_URL }}">
{% endassets %}

@miracle2k
Copy link
Owner

I see, so in development mode, you would like the use the ability to compile less browser-side, but for production, you want to precompile it on the server.

Your workaround seem very much correct, because as far as I can see, any "proper" solution to this would essentially be for the assets tag to provide some sort of {{REL}} variable that can be used at this point. And the code behind the REL variable could at most do what you are doing: looking at the file extension.

I'm not convinced that some kind of big architecture, with hooks for filters and the like, is warranted here. What I would suggest is supporting arbitrary values that can be passed along, something I've wanted to add for a while:

less_css = Bundle(
    'css/base.less',
    filters='less', 
    opts={'rel': 'stylesheet/less'})

which let's you write your template like this:

 <link rel="{{ rel or "stylesheet/less" }}" type="text/css" href="{{ ASSET_URL }}">

And could be used for things like media='print':

Bundle('css/print.css', opts={'media': 'print'})

@bradwright
Copy link
Contributor Author

That looks like a good solution. My other idea was to subclass Bundle, so like:

CssBundle(Bundle):
LessBundle(Bundle):

etc, which has its own render thing. Then you'd just do:

{{ ASSET_RENDER }}

or similar.

@miracle2k
Copy link
Owner

Type-aware Bundles are planned, in #12. It's a bigger untertaking though.

@miracle2k
Copy link
Owner

This is actually related to #60 as well, which would configure filters like less to always run. Clearly, at least for less, there are cases where you might not want the compilation to happen.

miracle2k added a commit that referenced this issue May 13, 2012
Filters can now declare that they need to run in 'merge' mode (cssrewrite),
or that they need to run always (compiler-type filters).

In the latter case, if such a filter is used, the bundle will automatically be
merged. This is a more limited change than it sounds - still, see the section
on backwards-incompatibilities in the docs for more info.

Closes #60, and solves the requests in #73, #102 and possibly others.
Some relation to #120.
miracle2k added a commit that referenced this issue May 14, 2012
Add a LESS_RUN_IN_DEBUG option to make this easier. Final commit for #120.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants