fusionbox / django-pyscss

Makes it easier to use PyScss in Django
https://pypi.python.org/pypi/django-pyscss
BSD 2-Clause "Simplified" License
19 stars 13 forks source link

@import doesn't work #2

Closed thayashi closed 10 years ago

thayashi commented 10 years ago

Hi, this is really great project, first of all, I'd like to say thank you for your effort for this project. I tried this module for my Django project, basically it works, but only @import function doesn't work. Do you have any idea for this issue?

rockymeza commented 10 years ago

Hi @thayashi,

Thank you so much for your interest in this project! I have to say let you know that this project is really young (less than one week) and I'm still working out the bugs. I actually have yet to even implement it in the project that I was writing it for, so you will have to bear with me as we get the kinks ironed out.

Regarding the issue that you are having, can you show me what your @import call looks like and also, could you please tell me the structure of your static directories? It would help to know where your CSS files live and which CSS file is trying to import which other CSS file.

Thanks!

thayashi commented 10 years ago

Thanks for the comment! Actually, I'd like to use this for OpenStack horizon. Horizon is using less for bootstap css compile now, but since bootstap just supported sass, I'd like to use sass for Horizon. This is directory structure: https://github.com/thayashi/horizon/tree/bootstrap-sass/openstack_dashboard/static/dashboard/sass https://github.com/thayashi/horizon/blob/bootstrap-sass/openstack_dashboard/static/dashboard/sass/bootstrap.scss This is css template https://github.com/thayashi/horizon/blob/bootstrap-sass/openstack_dashboard/templates/_stylesheets.html#L12 @import call returns nothing, it looks no error. https://dl.dropboxusercontent.com/u/7098/stuff/css.png

I hope this helps for something.

Regards,

rockymeza commented 10 years ago

Hi @thayashi,

Just based on looking through the code, I'm going to guess that you are going to need to change this line in the settings file https://github.com/thayashi/horizon/blob/bootstrap-sass/openstack_dashboard/settings.py#L136.

Please see the documentation for django-pyscss regarding integration with django-compressor.

django-pyscss doesn't support the underscore imports that backbone is using, so I will have to add support for that in a second.

With regard to not getting any errors, I think you weren't getting any errors because django-pyscss wasn't ever being called, but I will add some documentation on how to get logging working with django.

I'm going to go ahead and close this for now. Let me know if you have any other problems.

thayashi commented 10 years ago

HI, Thanks for the comment! Actually, I've already added the ('text/x-scss', 'django_pyscss.compressor.DjangoScssFilter'), just the commit was wrong.

django-pyscss doesn't support the underscore imports that backbone is using, so I will have to add > support for that in a second.

I got it. I changed to like this, then It worked. https://github.com/thayashi/horizon/blob/bootstrap-sass/openstack_dashboard/static/dashboard/sass/bootstrap/bootstrap.scss Also I found that imports didn't work for the file which is under the other directory like "bootstrap/xxxxxx.scss", if it is same directory, it worked.

BTW, https://dl.dropboxusercontent.com/u/7098/stuff/sass.jpg Can I avoid indent like above for scss compile?

rockymeza commented 10 years ago

huh.. I've never seen anything like that. That's pretty funny looking. django-pyscss doesn't really have anything to do with the rendering. I want to say that this might be something to do with pyScss, but I don't know. If you want to, you can look at the style options that pyScss has. I don't know if they are documented, but if you wanted to use them you could do one of two things:

Edit the global settings:

from scss import config
config.STYLE = 'compressed'

OR you can write your own filter that passes in more options to the Scss class:

from django_pyscss.scss import DjangoScss
from django_pyscss.compressor import DjangoScssFilter

class MyDjangoScssFilter(DjangoScssFilter):
    compiler = DjangoScss(scss_opts={
        'style': 'compressed',
    })

and then you would have to change your PRECOMPILERS config.

There are a couple of different style options:

Available values are 'nested', 'expanded', 'compact', 'compressed' and 'legacy' (defaults to 'nested'):

rockymeza commented 10 years ago

Regarding the bootstrap import stuff, here's how the import system works:

If the import path starts with a / the import will be treated as absolute and the file will be searched for at the root /static/ directory. Otherwise it will be treated as relative and will be searched for in the current directory for this file.

In this case:

# /static/css/foo.scss
@import 'bootstrap/xxx.scss';

The importer will search in /static/css/boostrap/ for the xxx.scss file.

In this case:

# /static/css/foo.scss
@import '/bootstrap/xxx.scss';

The importer will search in the /static/bootstrap/ directory for xxx.scss.

This is styled off of how browsers resolve relative URLs.

I hope this helps.

thayashi commented 10 years ago

Thanks! The global settings work. I got the how it works the import system as well. Let me ask one more question (sorry for the many times), the import system also requires file extension '. scss', right? As Sass grammar, it doesn't require the extension, is it a restriction of django-pyscss?

rockymeza commented 10 years ago

django-pyscss does not require a file extension.

@import 'foo';

If you don't have a file extension, django-pyscss will look for the following files:

thayashi commented 10 years ago

OK, It seems I got the wrong idea, thank you very much for the help. I'm looking forward to next update.

rockymeza commented 10 years ago

@thayashi,

I added support for underscore imports. https://github.com/fusionbox/django-pyscss/commit/2c194759c43c7bc9ba2580954dfb64e740a03e1e

thayashi commented 10 years ago

I just confirmed, it works well. Thank you very much! BTW, why don't you add this package to PyPI?

rockymeza commented 10 years ago

Done

https://pypi.python.org/pypi/django-pyscss/1.0.0

thayashi commented 10 years ago

Thanks a lot!