[英]Foundation 6 Installed with bower-rails Sass::SyntaxError
[英]Django-Bower + Foundation 5 + SASS, How to configure?
我正在使用Django-Bower測試基礎5的SASS實現。 我對Bower的想法不熟悉,並且對於如何使這個設置正常工作有點困惑。
我安裝了django-bower並配置為正常運行。 在我為bower apps config添加基礎並運行manage.py bower_install
我可以看到基礎文件確實已經正確安裝。 我也可以使用靜態標記將JS加載到模板中而沒有問題,所以我覺得我差不多就在那里。
我的問題是如何實際使用我自定義SASS文件安裝的基礎文件,以及將這些SASS文件編譯成CSS的最佳方法。 我知道我應該能夠通過@include "foundation"
將基礎包含到我的SASS中但是我迷失了如何讓SASS文件“看到”組件/ bower_components / foundation / sass中的基礎文件以及如何設置編譯以將css放入正確的靜態文件中。
更新:PyCharm有一個選項來觀看sass文件並編譯它們,所以我現在有一個編譯文件的選項,但是當我嘗試導入基礎時我得到error blog3.sass (Line 1: File to import not found or unreadable: foundation.
作為參考,這是我的文件結構:
├── blog3
│ └── __pycache__
├── components
│ └── bower_components
│ ├── foundation
│ │ ├── css
│ │ ├── js
│ │ │ ├── foundation
│ │ │ └── vendor
│ │ └── scss
│ │ └── foundation
│ │ └── components
│ ├── jquery
│ └── modernizr
│ ├── feature-detects
│ ├── media
│ └── test
│ ├── caniuse_files
│ ├── js
│ │ └── lib
│ └── qunit
└── interface
├── migrations
│ └── __pycache__
├── __pycache__
├── sass
└── templates
└── interface
這是我的settings.py
"""
Django settings for blog3 project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '...'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'annoying',
'django_extensions',
'djangobower',
'interface',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'blog3.urls'
WSGI_APPLICATION = 'blog3.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'djangobower.finders.BowerFinder',
)
BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, "components")
BOWER_INSTALLED_APPS = (
'jquery',
'foundation',
)
這是使用django-compressor的“如何編譯scss文件”的示例:
APPNAME /靜態/ SCSS / app.scss:
@import "../../../components/bower_components/foundation/scss/foundation";
@import "compass";
/* other stuff*/
settings.py:
STATICFILES_FINDERS = (
.....
'compressor.finders.CompressorFinder',
)
COMPRESS_PRECOMPILERS = (
('text/x-sass', 'sass --compass "{infile}" "{outfile}"'),
('text/x-scss', 'sass --scss --compass "{infile}" "{outfile}"'),
)
COMPRESS_URL = '/static/'
template.html:
{% load static %}
{% load compress %}
<head>
{% compress css %}
<link href="{% static 'scss/app.scss' %}" media="screen, projection" rel="stylesheet" type="text/x-scss" />
{% endcompress %}
</head>
希望這對你有所幫助。
編輯
也許這是一個更好的配置,使用沒有親戚路徑的@import。 -I
arg:
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
BOWER_COMPONENTS_ROOT = os.path.join(PROJECT_PATH, "../components/")
COMPRESS_PRECOMPILERS = (
('text/x-sass', 'sass --compass "{infile}" "{outfile}"'),
('text/x-scss', 'sass --scss --compass -I "%s/bower_components/foundation/scss" "{infile}" "{outfile}"' % BOWER_COMPONENTS_ROOT),
)
現在app.scss:
@import "foundation";
@import "compass";
最近我很欣賞pycharm觀察者
在觀察者的編輯中,進入'參數'字段我設置:
--compass -I“/ $ ProjectFileDir $ / components / bower_components / foundation / scss”--no-cache --update $ FileName $:$ FileNameWithoutExtension $ .css
所以,在scss文件中:
@import "foundation";
@import "compass";
包:
如何用django-pipeline編譯:
application.scss:
@import "../../../components/bower_components/foundation/scss/foundation";
settings.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pipeline',
'djangobower',
)
BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, 'components')
STATICFILES_FINDERS = (
.....
'djangobower.finders.BowerFinder', # just for bower components
)
PIPELINE_CSS = {
'application': {
'source_filenames': (
'css/application.scss',
),
'output_filename': 'css/application.css',
'extra_context': {
'media': 'screen,projection',
},
},
}
PIPELINE_COMPILERS = (
'pipeline.compilers.sass.SASSCompiler',
)
然后在模板中:
{% load compressed %}
{% compressed_css 'application' %}
這將在developpemnt上編譯,而collectstatic將編譯和壓縮
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.