Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

symfony - How to use SCSS filter in Symfony2 under Windows?

Actually, this is two questions:

  1. What is the correct way to use the SCSS filter in my Symfony project in Windows (in Twig templates) ? I mean, how do i use the scss binary in windows?

  2. Also, Do I necessarily need to use Compass? and "HOW" do i use compass if I have installed it?

Extension : Here is some configuration I have done:

In 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" 

In my twig file:

{% 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 %}

But, when i load the page, I get the following error (inside the css file)

[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:wampwwwSymfonyvendorasseticsrcAsseticFilterSassSassFilter.php line 162

at AsseticFilterSassSassFilter-&gt;filterLoad(object(AsseticAssetFileAsset))
in C:wampwwwSymfonyvendorasseticsrcAsseticFilterFilterCollection.php line 62

at AsseticFilterFilterCollection-&gt;filterLoad(object(AsseticAssetFileAsset))
in C:wampwwwSymfonyvendorasseticsrcAsseticAssetBaseAsset.php line 83

at AsseticAssetBaseAsset-&gt;doLoad(&#039
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I can only speak for Compass since is what I use but the same issues/problems most likely relate to the SASS/SCSS filters as well.

There are many known file path issues with Compass on Windows systems:

... and also fixes proposed to Assetic to deal with them:

I've found that doing the following was necessary for everything to work together...

#1. Make sure %ruby%in is in your environment PATH variable:

Example: PATH = "...;C:Ruby1.9.2in"

#2. Edit %ruby%incompass.bat to use absolute paths:

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

#3. Revert 539f206 manually in compiler.rb @ line ~10:

Note: This step may not be required on the latest Ruby/Compass versions. (Reference)

Path: %ruby%lib ubygems1.9.1gemscompass-*libcompasscompiler.rb

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

#4. Make sure Assetic is configured properly:

Example (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

I use %compass.bin% in my parameters file so that I can ease the transition of the codebase between Windows and *nix systems, so my parameters.yml looks like this:

# Assetic
compass.bin: C:Ruby1.9.2incompass.bat

#5. (Optional) Upgrade Assetic and AsseticBundle:

I have Assetic and AsseticBundle tagged to the very last possible commit that works with Symfony 2.0.x in my deps file:

[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

Make sure to replace %ruby% in all of the paths above with your actual path to ruby.exe, mine being C:Ruby1.9.2.

Steps #2 and #4 may or may not be required, but over the course of my time fighting with this issue, it is where I've ended up and my setup works (which is all I care about!).

Good luck!


Side question: Is your path to the SCSS/Compass binaries really in %kernel.root_dir%/Resources/libs?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...