Symfony 2中Assetic过滤器异常:指南针

37

我已经在我的Symfony 2项目中安装了Compass。现在我想与Assetic过滤器结合使用Compass。 我正在使用Windows 7。

我认为它几乎可以工作,但我仍然收到这个错误:

[Assetic\Exception\FilterException]
An error occurred while running:
"C:\Ruby21-x64\bin\ruby.EXE" "C:\Ruby21-x64\bin\compass.BAT" "compile" "C:\
Users\tommie\AppData\Local\Temp" "--boring" "--config" "C:\Users\tommie\App
Data\Local\Temp\ass4325.tmp" "--sass-dir" "" "--css-dir" "" "C:/Users/tommi
e/AppData/Local/Temp/ass4326.tmp.scss"
Error Output:
C:/Ruby21-x64/bin/compass.BAT:1: syntax error, unexpected tCONSTANT, expect
ing end-of-input

我的 HTML 代码(Twig):stylesheets.html.twig

{% stylesheets filter="compass" output='css/compiled/*.css'
   "@AcmeSassDemoBundle/Resources/assets/css/base.scss"
%}
<link rel="stylesheet" href="{{ asset_url }}" />

{% endstylesheets %}

base.html.twig:

->

base.html.twig:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{% block title %}Sass Demo!{% endblock %}</title>
    {#{% block stylesheets %}{% endblock %} #}

    {% include "AcmeSassDemoBundle:Demo:stylesheets.html.twig" %}
    <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
    <div id="header">
        {% block header %}
            <h1>Sass Demo</h1>
            <div class="logo">this container is half as big as the sass.gif's dimension</div>
        {% endblock %}
    </div>

    <div id="menu">
        <ul>
            <li class="add"><a href="#">add something</a></li>
            <li class="edit"><a href="#">edit something</a></li>
            <li class="delete"><a href="#">delete something</a></li>
        </ul>
    </div>

    <div id="content">
        {% block body %}hello sass!{% endblock %}
    </div>

    <div id="footer">
        {% block footer %}awesome footer goes here ...{% endblock %}
    </div>
    {% block javascripts %}{% endblock %}</
</body>

index.html.twig:

{% extends 'AcmeSassDemoBundle:Demo:base.html.twig' %}

{% block body %}

<div class="content">
  hello world
    <div class="sub">
       This text should be in green ...
       <div class="sub">
        ... and this one in blue!
    </div>
</div>

我的 config.yml 过滤器资产配置:

# Assetic Configuration
assetic:
    debug: false
    use_controller: true# default: true
    filters:
        sass:    ~
        compass: 
            compass:
                bin: C:\Ruby21-x64\bin\compass.bat

基础样式表(base.scss)

$main-background-color: #FFF;
$main-color: #FFF;
$light-color: #759E1A;
$link-color: #0088CC;

body {
    background-color: #CCC;
}

@mixin rounded($side, $radius: 10px) {
    border-radius: $radius;
    border-#{$side}-radius: $radius;
    -moz-border-radius-#{$side}: $radius;
    -webkit-border-#{$side}-radius: $radius;
}

@import "header.scss";
@import "menu.scss";
@import "content.scss";
@import "footer.scss";

你的配置文件里是打错了还是真的有两个compass?我的只有一个。试着移除其中一个 像这样。另外,能否请你提供你的base.scss文件? - ferdynator
嗨ferdynator,我更新了我的问题并添加了base.scss。我也尝试了你的配置,但仍然不起作用。错误信息如下:"/usr/bin/ruby" "C:\Ruby21-x64\bin\compass.bat" "compile" "C:\Windows\Temp" "--boring" "--config" "C:\Windows\Temp\assB498.tmp" "--sass-dir" "" "--css-dir" "" "C:/Windows/Temp/assB499.tmp.scss" - Thomas Crawford
看看这个指南,也许会有所帮助:https://dev59.com/rXDYa4cB1Zd3GeqPFu78 - Nickolaus
你能展示一下compass.BAT的内容吗?看起来这个文件包含了一个错误。 - kronn
2个回答

1
我不想打击你的积极性,但是在Windows和Ruby上使用这两者的组合是最糟糕的(node也一样,node_module带有长子目录树,在Windows上会有256个字符的限制,并且在安装包时会显示错误)。我的意思是,可以考虑将项目移动到类似于服务器配置的虚拟机中作为替代方案(VirtualBox和Vagrant)。
Linux对Ruby更加友好(它支持Ruby),并且具有符号链接和长路径名;
对于调试: https://symfony.com/doc/2.8/setup/homestead.html 或许这个旧链接也会有所帮助: 如何在Windows下使用Symfony2中的SCSS过滤器?

0

很有可能这是你已经尝试或注意到的事情,但以防万一:

错误似乎更像是 Ruby 解释器崩溃了,而不是在处理你的 scss / twig 时出错。这在某种程度上是有道理的,因为 Ruby 不希望使用 .BAT 脚本。

通常只使用 'compass',而不是 'compass.BAT',后者通常只调用带有 'compass' 的 Ruby。

例如:

"C:\Ruby21-x64\bin\ruby.EXE" "C:\Ruby21-x64\bin\compass.BAT" "compile" "C:\ Users\tommie\AppData\Local\Temp" "--boring" "--config" "C:\Users\tommie\App Data\Local\Temp\ass4325.tmp" "--sass-dir" "" "--css-dir" "" "C:/Users/tommi e/AppData/Local/Temp/ass4326.tmp.scss"

通常应该是

"C:\Ruby21-x64\bin\ruby.EXE" "C:\Ruby21-x64\bin\compass" "compile" "C:\ Users\tommie\AppData\Local\Temp" "--boring" "--config" "C:\Users\tommie\App Data\Local\Temp\ass4325.tmp" "--sass-dir" "" "--css-dir" "" "C:/Users/tommi e/AppData/Local/Temp/ass4326.tmp.scss"
基本上,将compass.bin路径设置为不带.bat,你可能会没问题。这通常在config.yml中的assetic.filters.compass.bin中。
另请参见https://github.com/symfony/AsseticBundle/issues/158 这也揭示了特殊字符不受欢迎,不确定它对dirnames中的空格有多喜欢。如果没有.bat仍然无法正常工作,则这些可能也会导致窒息。

谢谢,我也尝试过了,但不幸的是这不是问题所在。我仍然得到相同的错误。 - Thomas Crawford

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接