如何在Windows下的Symfony2中使用SCSS过滤器?

时间:2012-03-08 18:38:43

标签: windows symfony sass

实际上,这是两个问题:

  1. 在Windows的Symfony项目中使用SCSS过滤器的正确方法是什么(在Twig模板中)? 我的意思是,我如何在Windows中使用scss二进制文件?

  2. 另外,我是否一定需要使用指南针?如果安装了指南针,我会用“指南针”吗?

  3. 扩展程序:以下是我所做的一些配置:

    app / config / config.yml

    assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        scss:
            bin: "%kernel.root_dir%/Resources/libs/scss"
        compass:
            bin: "%kernel.root_dir%/Resources/libs/compass" 
    

    在我的twig文件中:

    {% stylesheets 
          '@PlaylyfeBaseBundle/Resources/public/css/base.scss'
          '@PlaylyfeBaseBundle/Resources/public/css/another.scss'
       filter='scss'
       output='css/compiled/total.css'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
    

    但是,当我加载页面时,我收到以下错误(在css文件中)

    [exception] 500 | Internal Server Error | RuntimeException
    [message] The filename, directory name, or volume label syntax is incorrect.
    
    [1] RuntimeException: The filename, directory name, or volume label syntax is incorrect.
    at n/a
    in C:\wamp\www\Symfony\vendor\assetic\src\Assetic\Filter\Sass\SassFilter.php line 162
    
    at Assetic\Filter\Sass\SassFilter-&gt;filterLoad(object(Assetic\Asset\FileAsset))
    in C:\wamp\www\Symfony\vendor\assetic\src\Assetic\Filter\FilterCollection.php line 62
    
    at Assetic\Filter\FilterCollection-&gt;filterLoad(object(Assetic\Asset\FileAsset))
    in C:\wamp\www\Symfony\vendor\assetic\src\Assetic\Asset\BaseAsset.php line 83
    
    at Assetic\Asset\BaseAsset-&gt;doLoad(&#039
    

3 个答案:

答案 0 :(得分:4)

我只能说Compass,因为我使用的是同样的问题/问题也很可能与SASS / SCSS过滤器有关。

Windows系统上Compass有许多已知的文件路径问题:

...还修复了Assetic处理它们的问题:

我发现做以下事情对于一起工作是必要的......

<强>#1。确保%ruby%\bin位于您的环境PATH变量中

实施例: PATH = "...;C:\Ruby\1.9.2\bin"

<强>#2。修改%ruby%\bin\compass.bat以使用绝对路径:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"C:\Ruby\1.9.2\bin\ruby.exe" "C:/Ruby/1.9.2/bin/compass" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"C:\Ruby\1.9.2\bin\ruby.exe" "%~dpn0" %*

<强>#3。在compiler.rb @ line~10:

中手动还原539f206
  

注意:最新的Ruby / Compass版本可能不需要此步骤。 (Reference

路径:%ruby%\lib\ruby\gems\1.9.1\gems\compass-*\lib\compass\compiler.rb

#      self.from, self.to = from.gsub('./', ''), to
      self.from, self.to = File.expand_path(from), to

<强>#4。确保正确配置了Assetic:

示例(config.yml):

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        compass:
            bin: %compass.bin%
        yui_js:
            jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
        yui_css:
            jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

我在参数文件中使用%compass.bin%,以便我可以简化Windows和* nix系统之间代码库的转换,因此我的parameters.yml看起来像这样:

# Assetic
compass.bin: C:\Ruby\1.9.2\bin\compass.bat

<强>#5。 (可选)升级Assetic和AsseticBundle:

我将Assetic和AsseticBundle标记为在我的deps文件中与Symfony 2.0.x一起使用的最后一次提交:

[assetic]
    git=http://github.com/kriswallsmith/assetic.git
    version=ac71449e46bed22c276da26bf54ab2f733b3801d

[AsseticBundle]
    git=http://github.com/symfony/AsseticBundle.git
    target=bundles/Symfony/Bundle/AsseticBundle
    version=da4a46ce37557dcf3068b8493b12bdbbe47455e2

请务必将上述所有路径中的%ruby%替换为ruby.exe的实际路径,我的C:\Ruby\1.9.2

步骤#2和#4可能需要也可能不需要,但是在我解决这个问题的过程中,这是我最终的结果,我的设置正常工作(这就是我所关心的!)。

祝你好运!


附带问题:您通往%kernel.root_dir%/Resources/libs的SCSS / Compass二进制文件的路径是什么?

答案 1 :(得分:1)

  1. 不幸的是,twig scss扩展在Windows上被破坏了。这是一个众所周知的问题。我花了一些时间试图想出一个工作但没有可用。我发现最好只使用带有--watch参数的scss可执行文件来创建css文件并将它们存储在Resource / public目录中。这也可以简化一些部署问题,因为您不必担心服务器上有scss。

  2. scss不需要使用指南针。可以把它想象成一个有用的css库。例如,如果你想要做css圆形边缘,Compass mixin将生成所有供应商特定的自定义标签。有关使用它的详细信息,请参阅文档。

答案 2 :(得分:-1)

在我的案例中经过数小时的搜索并尝试了许多解决方案,这对我有用:

在'app / config / config.yml'中添加:

parameters:
# Assetic
assetic.filter.compass.bin: D:/Ruby193/bin/compass

D:/ Ruby193 / bin / compass将取决于您的Ruby路径。

查看截图: http://s23.postimg.org/3n2oc5wh7/MY_SOLUTION_THAT_I_FOUND.jpg

我的系统: Windows 7旗舰版, Ruby 1.9.3, Symfony 2.4.3

相关问题