2015-06-13 52 views
2

我有擴建的環境瓶資產 - 薩斯不解決@import SCSS指令相對路徑

./bin/pip show flask | grep Version 
Version: 0.10.1 
./bin/pip show flask-assets | grep Version 
Version: 0.10 

SRC文件夾 的src/setup.py瓶的應用有如下字符串

setup(
    name = 'spf', 
    install_requires = [ 
     'flask', 
     'flask-assets', 
    ], 
    entry_points = { 
     'console_scripts': [ 
      'spf_dev = spf.manage:dev', /* see manage.py dev function */ 
     ], 
    }, 
} 

用於產生倉/ spf_dev我有 SRC/SPF/manage.py用下面的代碼

from flask.ext import assets 
from . import env 

def init (app): 
    manager = script.Manager(app) 

    manager.add_command(
     'assets', 
     assets.ManageAssets(app.assets), 
    ) 
    return manager 

def dev(): 
    init(env.dev.app).run() 

的燒瓶環境初始化我使用 的src/SPF/ENV/dev.py

from spf import init 
app = init({ 
    'ASSETS_DIR': 'src/spf/static/assets', 
    'ASSETS_URL': '/assets/', 

    'SASS_STYLE': 'compressed', 

    'UGLIFYJS_EXTRA_ARGS': (
     '-c', 
     '--screw-ie8', 
    ), 

}) 

,我實現 的src/SPF/初始化的.py

退貨WSGI應用程序初始化函數
import flask 
from . import assets 

def init (env_config=None): 
    app = flask.Flask(
     'spf', 
     static_url_path='', 
    ) 

    app.config.update(evn_config) 
    app.assets = assets.Assets(app) 
    return app 

資產模塊與捆綁登記 SRC/SPF/assets.py

from flask.ext.assets import (
    Environment, 
    Bundle, 
) 

class Assets (Environment): 
    def __init__ (self, app): 
     super(Assets, self).__init__(app) 

     if 'ASSETS_DIR' in app.config: 
      self.directory = app.config['ASSETS_DIR'] 

     if 'ASSETS_URL' in app.config: 
      self.url = app.config['ASSETS_URL'] 

     if 'SASS_STYLE' in app.config: 
      self.config['sass_style'] = app.config['SASS_STYLE'] 

     if 'UGLIFYJS_EXTRA_ARGS' in app.config: 
      self.config['UGLIFYJS_EXTRA_ARGS'] = \ 
       app.config['UGLIFYJS_EXTRA_ARGS'] 

     self.register('theme.css', Bundle(
      'scss/theme.scss', 
      filters='scss', 
      output='theme.css', 
     )) 

     self.append_path('src/assets') 

的src /資產/ SCSS/theme.scss

@import 'btn-o'; 

的src /資產/ SCSS/_btn-o.scss存在,不是空的,並有0777訪問權

但是當我運行

buildout -c src/buildout.cfg 
./bin/spf_dev assets -v build 

我有錯誤

Building bundle: theme.css 
Failed, error was: sass: subprocess had error: stderr=Error: File to import not found or unreadable: ./btn-o. on line 1 of standard input 
    Use --trace for backtrace. , stdout=, returncode=65 

我已閱讀https://github.com/miracle2k/webassets/blob/master/src/webassets/filter/sass.py#L36

,但我不明白;-( 爲什麼青菜不@import指令中使用的src /資產爲解決相對路徑從標準輸入我用self.append_path(「SRC /資產」)後?

+0

但是'btn-o'是什麼? – sobolevn

+0

btn-o它只是scss文件與按鈕的一些CSS代碼 – Slach

+0

我發現在紅寶石(不是python)代碼在sass 中的truble見https://github.com/sass/sass/issues/1745 – Slach

回答

3

您需要的負載路徑添加到您的青菜過濾器爲它與3.4.14

sass = get_filter('scss') 
sass.load_paths = [os.path.join(app.static_folder, 'scss')] 
工作

然後,當您註冊您的包時:

self.register('theme.css', Bundle(
    'scss/theme.scss', 
    filters=(sass,), 
    output='theme.css', 
)) 
2

問題是SASS 3.4.14

的解決方法是

sudo gem uninstall sass 
sudo gem install sass -v 3.4.13