Giter Site home page Giter Site logo

dziegler / django-css Goto Github PK

View Code? Open in Web Editor NEW
217.0 217.0 28.0 265 KB

django-css is a fork of django_compressor that makes it easy to use CSS compilers with your Django projects. CSS compilers extend CSS syntax to include more powerful features such as variables and nested blocks, and pretty much rock all around.

Home Page: http://blog.davidziegler.net

License: Other

JavaScript 0.01% Python 99.99%

django-css's People

Contributors

aramgutang avatar dziegler avatar mintchaos avatar oesmith avatar tymofij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-css's Issues

Compressor does not play nice with {{ MEDIA_URL }}

I'm trying to deploy a site that worked fine with django-css in devel mode, even with compress switched on.

I have a compress stanza in my base.html that looks like this:

 {% compress css xhtml %}
<link rel="stylesheet" href="{{ MEDIA_URL }}css/reset.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="{{ MEDIA_URL }}css/960.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="{{ MEDIA_URL }}css/text.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="{{ MEDIA_URL }}css/layout.ccss" type="text/css" charset="utf-8" />
{% block extra_css %}{% endblock %}
{% endcompress %}

When I open the site, I get a traceback in my server log, ending with:

[Thu Aug 06 10:09:35 2009] [error] [client 90.184.195.240] UncompressableFileError: "css/reset.css" is not in COMPRESS_URL ("http://m.revealit.dk/revealit.dk/site_media/") and can not be compressed

It seems that django-css is somehow eating the output of {{ MEDIA_URL }}, because if I remove the {% compress %} tag, the URLs get rendered correctly (although the CleverCSS file obviously don't work without processing).

Breaks on utf-8 input

I get a UnicodeDecodeError, when one of the css files to be compressed contains non ascii chars.

As a work around I move the reference to the one unicode css file outside of my compress block.

Limitations of django-css

I want to know what are limitations of the template tag content, I mean, what can I put inside it ? any other template tag ? Any html element (comments)?

COMPRESS_URL is not used

compressor/__init__.py , line 66:

    def get_filename(self, url):
        if not url.startswith(settings.MEDIA_URL):
            raise UncompressableFileError('"%s" is not in COMPRESS_URL ("%s") and can not be compressed' % (url, settings.MEDIA_URL))
        basename = url[len(settings.MEDIA_URL):]
        filename = os.path.join(settings.MEDIA_ROOT, basename)
        return filename

Despire README telling about the COMPRESS_URL and COMPRESS_ROOT, they are not used in actual file reading.

TemplateSyntaxError: global name 'ALLOWED_ARGS' is not defined

Getting a TemplateSyntaxError when using compress. Looks like it's being referenced in an Exception you're trying to raise in compress.py on line 99. Will look in to solving the underlying problem (argument must be js or css), but figured you might like to know.

Production server can't find templates

I have django-css working great on my dev environment (OS X) but when I try to run it on Ubuntu (Slicehost) with wsgi I get a pre-Django 500 server error:

[Wed Dec 30 15:57:12 2009] [error] [client 70.114.139.91] TemplateDoesNotExist: compressor/css.html

Django-css works great if I have COMPRESS = False. It successfully converts my .sass files to .css. The problem only occurs when I set COMPRESS = True.

What am I doing wrong?

django-css causes syncdb failure.

When a project that uses django-css attempts to load, it looks for a site object every time. It is wrapped in a try/except clause, but if the loading is before the django_sites table has been populated, then it creates a transaction error.

This isn't necessarily too bad, but this happens when trying to do an initial syncdb.

Which means the syncdb fails, because a table is missing - that the syncdb needs to create.

The workaround is to disable the compressor app until after the syncdb.

django 1.3 STATIC_URL

Django 1.3 introduces STATIC_URL as a standard approach for app static files.
So from now on there are two paths for not dynamic files:
MEDIA_URL - more like uploaded files
STATIC_URL - statics delivered with app

At this point there are two issues with django-css.

  1. defeulting to context MEDIA_URL
    I guess it should be enough jus to remove templatetags/compress.py lines:
    if 'MEDIA_URL' in context:
    media_url = context['MEDIA_URL']
    else:
  2. During development STATIC_ROOT is often empty as it is being dynamically filled by static app. A standard practice is to have all files collected to STATIC_ROOT only on development

It might be useful to either document this limitation or get real static file path while in development mode (runserver)

Unit tests failing

not sure if this is a problem with compressor or django css. Doesn't look like the repo here or installing from pypi provides a version that does not break unit tests.

FAIL: test_css_split (compressor.tests.CompressorTestCase)

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/compressor/tests.py", line 95, in test_css_split
self.assertEqual(out, split)
AssertionError: [('file', u'/usr/lib/python2.6/site-packages/compressor/../testing/media/css/one.css', ''), ('hunk', u'p { border:5px solid green;}', '<style type="text/css">p { border:5px solid green;}</style>'), ('file', u'/usr/lib/python2.6/site-packages/compressor/../testing/media/css/two.css', ''), ('file', u'/usr/lib/python2.6/site-packages/compressor/../testing/media/css/three.css', ''), ('hunk', 'small {\n font-size: 10px;\n}', "<style type='text/css'>\nsmall {\n font-size: 10px;\n}\n</style>"), ('hunk', 'h1 {\n font-weight: bold;\n}', "<style type='text/css'>\nh1 {\n font-weight: bold;\n}\n</style>")] != [('file', u'/usr/lib/python2.6/site-packages/testing/media/css/one.css', ''), ('hunk', u'p { border:5px solid green;}', '<style type="text/css">p { border:5px solid green;}</style>'), ('file', u'/usr/lib/python2.6/site-packages/testing/media/css/two.css', ''), ('file', u'/usr/lib/python2.6/site-packages/testing/media/css/three.css', ''), ('hunk', 'small {\n font-size: 10px;\n}', "<style type='text/css'>\nsmall {\n font-size: 10px;\n}\n</style>"), ('hunk', 'h1 {\n font-weight: bold;\n}', "<style type='text/css'>\nh1 {\n font-weight: bold;\n}\n</style>")]

FAIL: test_get_filename (compressor.tests.CompressorTestCase)

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/compressor/tests.py", line 70, in test_get_filename
self.assertEqual(filename,os.path.join(settings.MEDIA_ROOT,'something.css'))
AssertionError: '/usr/lib/python2.6/site-packages/testing/media/something.css' != '/usr/lib/python2.6/site-packages/compressor/../testing/media/something.css'

FAIL: test_js_split (compressor.tests.CompressorTestCase)

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/compressor/tests.py", line 149, in test_js_split
self.assertEqual(out, split)
AssertionError: [('file', u'/usr/lib/python2.6/site-packages/compressor/../testing/media/js/one.js', '<script src="/media/js/one.js" type="text/javascript"></script>'), ('hunk', u'obj.value = "value";', '<script type="text/javascript">obj.value = "value";</script>')] != [('file', u'/usr/lib/python2.6/site-packages/testing/media/js/one.js', '<script src="/media/js/one.js" type="text/javascript"></script>'), ('hunk', u'obj.value = "value";', '<script type="text/javascript">obj.value = "value";</script>')]

Base64 background images don't work

Base64 data for background images doesn't work because the CssAbsoluteFilter is messing around with the URL, trying to add the media path. It looks like changing line 29 of css_default.py to the following fixes it:
if url.startswith('http://') or url.startswith('/') or url.startswith('data:'):

Tests fail.

The following output occurs when I try to run tests, because it is looking for a file that is not part of your package. It is looking for the testing package - but that package doesn't exist after I've installed your application. Hence, failure.

~: ./manage.py test --failfast
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.AttributeError'> ignored
Creating test database for alias 'default'...................................................................................................................................................................................................................................................................................................................................................Exception RuntimeError: 'maximum recursion depth exceeded in subclasscheck' in <type 'exceptions.AttributeError'> ignored
.Exception RuntimeError: 'maximum recursion depth exceeded in subclasscheck' in <type 'exceptions.AttributeError'> ignored
.Exception RuntimeError: 'maximum recursion depth exceeded in subclasscheck' in <type 'exceptions.AttributeError'> ignored
.......................................................E
======================================================================
ERROR: test_css_hash (compressor.tests.CompressorTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/tests.py", line 133, in test_css_hash
self.assertEqual(self.css_hash, self.cssNode.hash)
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 138, in hash
return get_hexdigest(self.combined)[:12]
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 129, in combined
output = self.concat()
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 110, in concat
return "\n".join(self.hunks)
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 94, in hunks
for kind, v, elem in self.split_contents():
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 263, in split_contents
self.compile(path,settings.COMPILER_FORMATS[ext])
File "/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/init.py", line 207, in compile
raise Exception(err)
Exception: python: can't open file '/Users/monokrome/Projects/reo/lib/python2.6/site-packages/compressor/../testing/clevercss.py': [Errno 2] No such file or directory

----------------------------------------------------------------------
Ran 394 tests in 6.551s

FAILED (errors=1)
Destroying test database for alias 'default'...

CSSTidy Filter Doesn't Work

Christian borrowed the CSSTidy filter from django-compress, but never edited it to work with django_compressor's edited FilterBase class. Since django_compressor proper seems to be dead for the time being, I'm hoping you could make the necessary changes. :)

Without cache?

Hello,

It's more of a question: most shared hosting doesn't allow memcached. Is it possible to make use of django-css without cache?

Cleverss inserts an extra letter into path on windows

On windows, when I try to start my django project I get the following exception:

Caught Exception while rendering: Traceback (most recent call last): File "C:\Python27\Scripts\clevercss-script.py", line 8, in load_entry_point('CleverCSS==0.1.4', 'console_scripts', 'clevercss')() File "build\bdist.win-amd64\egg\clevercss.py", line 1590, in main IOError: [Errno 2] No such file or directory: 'C:\Users\blahblah\Projects\client\core\media\a\ccss\block.ccss'

NOTE that the actual path is:
C:\Users\blahblah\Projects\client\core\media\ccss\block.ccss'

Note that this path does not have a letter "a" between "media" and "ccss".

Separate stylesheets depending on their media attribute?

Say I had this -

{% compress css %}

link rel="stylesheet" href="{{ MEDIA_URL }}css/screen.css" media="sceen">
link rel="stylesheet" href="{{ MEDIA_URL }}css/menu.css" media="sceen">
link rel="stylesheet" href="{{ MEDIA_URL }}css/iphone.css" media="only screen and (max-device-width: 480px)">

{% endcompress %}

Is there currently a way to output two seperate stylesheets grouped by the media attribute e.g.

link rel="stylesheet" href="CACHE/123.css" type="text/css" media="sceen">
link rel="stylesheet" href="CACHE/456.css" type="text/css" media="only screen and (max-device-width: 480px)">

so that the iphone one does not overwrite any previous rules?

Thanks

Problem with Sass 3 and django-css

I set up a new dev environment and did the standard "gem install haml" command to get the latest version, but it turns out sass is in version 3 now and has made some major syntax changes. I went through and updated my syntax to match only to discover that django-css won't compile using sass 3.

If you try to load a page that requires a .sass file, the browser hangs and never loads the page. Hitting reload results in the page loading, but without the css from your .sass file. Checking the .css that was created reveals that it is empty. Running "sass myfile.sass myfile.css" from the shell does just fine at compiling the sass to css, but django-css can't do it at run-time anymore. I even tried putting some sass code in a {% sass %} block directly in my template and that worked, but working with .sass files fails every time.

To make sure the new version of sass was the culprit, I rolled by my .sass changes, confirmed that everything was still broken, then did this: "gem uninstall haml"..."gem install haml --version 2.2.24" - after uninstalling and reinstalling with the old version of sass everything worked perfectly.

Not sure where the source of the problem is here, but I didn't have time to do any more troubleshooting and will be sticking with Sass 2 for now. My best guess is that there is some compatibility problem between django-css and Sass 3.

Cleverss inserts an extra letter into path on windows

On windows, when I try to start my django project I get the following exception:

Caught Exception while rendering: Traceback (most recent call last): File "C:\Python27\Scripts\clevercss-script.py", line 8, in load_entry_point('CleverCSS==0.1.4', 'console_scripts', 'clevercss')() File "build\bdist.win-amd64\egg\clevercss.py", line 1590, in main IOError: [Errno 2] No such file or directory: 'C:\Users\blahblah\Projects\client\core\media\a\ccss\block.ccss'

NOTE that the actual path is:
C:\Users\blahblah\Projects\client\core\media\ccss\block.ccss'

Note that this path does not have a letter "a" between "media" and "ccss".

Also, it uses double slashes \ on windows - but for some reason git-hub's parser removed them.

Sorry for the double ticket - I closed the other one by accident.

charset attribute on link element is not HTML5 compliant

The element generated by django-css contains a charset="utf-8" attribute. Unfortunately the charset attribute is not allowed in HTML5 any longer. Maybe there should be a setting for HTML5 mode or similiar.

Thanks for the great app! I was tired of having the LESS compiler running in the background all the time. But no longer.

django-css and celery test conflict

I have a project that uses celery (http://ask.github.com/celery/) for some asynchronous background processing. I have some tests that test celery's Task#delay method (http://ask.github.com/celery/reference/celery.task.base.html#celery.task.base.Task.delay). In order to run these tests, per the celery documentation (http://ask.github.com/celery/cookbook/unit-testing.html#testing-with-django), I set CELERY_ALWAYS_EAGER = True in my settings.

The issue comes when I include 'compressor' in my INSTALLED_APPS...when compressor is present, my celery delay tests hang indefinetly. I'm relativly new to python, so I'm not sure of the exact mechanics, but it seems though compressor is invalidating the CELERY_ALWAYS_EAGER setting. I have tried placing 'compressor' above and below 'celery' in my INSTALLED_APPS, to no effect.

I raised the issue here becuase things were working fine before I tried including compressor.

There isn't too much error output to show, but I can send code if that would be helpful to duplicate the problem.

Thanks.

TemplateSyntaxError with misconfiguration

Specifying an invalid value for x in {% compress x %} results in a TemplateSyntaxError:

Caught an exception while rendering: global name 'ALLOWED_ARGS' is not defined

This is due to the fact that ALLOWED_ARGS isn't defined anywhere, and is called in templatetags/compress.py

I've just started working with django-css, and I'm not sure what the allowed args are supposed to be, so I won't suggest a patch. :)

UnicodeDecodeError in compress templatetag

We have one LESS file being included in our base.html template:

{% compress css %}
    <link rel="stylesheet" href="{{ MEDIA_URL }}css/screen.less" type="text/css" media="screen, projection">
{% endcompress %}

It works fine on our local machines, but on the server we get a UnicodeDecodeError (see below). Has anyone else seen this or know how to fix it?

We will investigate further, just thought I'd post an issue in case other people are seeing the same thing.

TemplateSyntaxError: Caught an exception while rendering: Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/templatetags/compress.py", line 42, in render
output = compressor.output()
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 178, in output
url = "%s/%s" % (settings.MEDIA_URL.rstrip('/'), self.new_filepath)
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 148, in new_filepath
filename = "".join([self.hash, self.extension])
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 144, in hash
return get_hexdigest(self.combined)[:12]
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 135, in combined
output = self.concat()
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 118, in concat
return "\n".join(self.hunks)
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 112, in hunks
input = self.filter(input, 'input', filename=v, elem=elem)
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/init.py", line 126, in filter
content = filter(**kwargs)
File "/usr/local/lib/python2.6/dist-packages/django_css-2.2.1-py2.6.egg/compressor/filters/css_default.py", line 20, in input
output = url_pattern.sub(self.url_converter, self.content)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 16: ordinal not in range(128)

Separate YUI binaries for CSS and JS

Having a module-global BINARY in this file makes it hard for subclasses to use custom binaries. All I want is a subclass that uses a different binary, not the one in settings.COMPRESS_YUI_BINARY.

The BINARY variable should be a class attribute instead of a module global, so that subclasses could easily change it.

Force recompile needed when dealing with sass @import files

If you have a file, say main.sass, that pulls in things like _typography.sass and _header.sass like this:

@import typography.sass
@import header.sass

Django-css does not pick up on these changes because it is only checking the timestamp of main.sass and doesn't look at any included files. To get around it, you have to add a blank line, then remove it from main.sass or just manually compile the sass yourself at the command line, neither of which are ideal.

I created a patch to solve the problem by simply adding a COMPRESS_FORCE_RECOMPILE optional setting. It defaults to False, which keeps everything running as it used to, but if you set it to True in your Django settings, it forces the recompile every time. Use case is to set it to True just before making a bunch of Sass changes, then change the setting back when done. Or just leave it on all the time in a dev environment if speed is not a big issue.

Here's the patch: http://gist.github.com/500673

url = os.path.realpath(url) Bug

Compressor seems to break on line 67 of compressor.init.py
which is this:
url = os.path.realpath(url)

If I comment this line out, it works.

I am using python 2.6 with virtualenv + pip. I have some other projects that I am working on that aren't using virtualenv and I don't experience the above issue. Only with virtualenv.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.