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

Adding option to concatenate files before processing #289

Conversation

jannon
Copy link

@jannon jannon commented Jul 17, 2012

What's in this pull request

  • Let tag arguments after kind (css|js) be specified in any order
  • Use more standard 'as ' syntax to name the code block
  • Add ability to specify options in the tag
  • 'group_first' option to allow files to be concatenated before processing

There are tests and documentation updates as well as the code changes

Tag Argument Order

There's not really any need to enforce a certain arrangement of arguments in the tag so let's just let people specify them however they want after the kind parameter. So now all of these are valid:

{% compress js inline as main %}

{% compress js as main file %}

{% compress css group_first=true as base %}

Using 'as <name>'

Lots of things in python and django use this syntax, so it would be nice to do so as well

Specifying options in the tag

Just like the with tag in django, you can specify an arbitrary number of keyword/value arguments to the tag. These will get put into a dictionary and passed to the Compressor classes. Also, the default compressors, add these to the options that they pass the precompilers and filters. One of the main motivations for this was to prepare for being able to specify that files should be grouped first before, say, lessc precompilation, which leads to...

'group_first' option

Setting the option group_first=true in the compress template tag will cause files of the same type to be concatenated before being handed to precompilers/filters. This will allow people to do standard code decomposition with things like .less files (having a mixins file separate from page-specific files)

For example:

{% compress css group_first=true %}
    <link rel="stylesheet" href="/media/css/mixins.less" type="text/less" />
    <link rel="stylesheet" href="/media/css/home.less" type="text/less" />
    <link rel="stylesheet" href="/media/css/foo.css" type="text/css" />
{% endcompress %}

Will concatenate the .less files so the less precompiler will properly process all the files
This provides a fix for #30

This also adds ability to specify tag options, and use 'as <name>' to name blocks
@travisbot
Copy link

This pull request passes (merged 0404f08 into 2255063).

@travisbot
Copy link

This pull request fails (merged 65b676e into 2255063).

@travisbot
Copy link

This pull request passes (merged 0f04270 into 2255063).

If 'deferred=true' and 'as <name>' are passed in template tag, the output of the compress tag is added to the template context as <name>.   If there is no name specified in the tag, the 'deferred' option is ignored and the tag output is rendered normally.  If the mode is 'file' the url of the file is used, otherwise the full rendered content is used.

This will allow people to use django_compressor in conjunction with asynchronous asset loaders (e.g. yepnope.js, require.js, etc.)
@travisbot
Copy link

This pull request fails (merged 2b3f2cc into 2255063).

@jannon jannon closed this Jul 21, 2012
@travisbot
Copy link

This pull request fails (merged f578b14 into 2255063).

@sicarrots
Copy link

Hi, jannon, thanks for Your great job! It is possible to work on merging this pull request? It would be nice to have this feauture in core django_compressor.

@k-funk
Copy link

k-funk commented May 21, 2016

Why was this never merged? :(

@karyon
Copy link
Contributor

karyon commented Jun 1, 2016

@k-funk this has been continued in #294. updating that PR would be greatly appreciated :)

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

Successfully merging this pull request may close these issues.

None yet

5 participants