Sprockets append_path不会添加到SASS load_path

时间:2012-05-03 09:12:39

标签: windows-7 sass compass-sass sprockets

我在Windows 7中使用Sprockets通过Rack服务器提供Compass驱动的SASS文件(仅限开发环境)。当我将路径附加到Sprockets时,它似乎不会将这些添加到SASS加载路径。

据我所知,sprockets-sass append_path中的文档应该自动添加SASS load_path的路径。

我在项目特定组件目录(下面列出)中有base/sass/base.scss,在此文件中,我尝试包含 common 组件中的所有scss文件。如果我使用../common/sass/*中的相对路径(@include)它可以工作,但是当我让SASS在load_path中查找它时,我得到以下错误:

Sass::SyntaxError: File to import not found or unreadable: common/sass/*
Load paths:
  Sass::Globbing::Importer
  C:/Program Files (x86)/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/compass-0.12.1/frameworks/blueprint/stylesheets
  C:/Program Files (x86)/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/compass-0.12.1/frameworks/compass/stylesheets
  C:/Program Files (x86)/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/compass-magick-0.1.4/lib/stylesheets
  Compass::SpriteImporter
  (in C:/repos/test/project/components/base/sass/base.scss)

如您所见,加载路径中仅列出了罗盘和指南针magick添加的路径,我希望它也可以查看C:/repos/test/project/components

我的机架服务器设置如下所示:

#!/bin/env ruby
require 'bundler'
Bundler.require

COMPONENT_DIR = "../../components" # -> C:/repos/test/project/components
GENERATED_CSS_DIR = "public/generated-css"

Compass.configuration do |compass|
  compass.output_style = :compressed
end

compiler = Rack::Builder.new do
  map "/#{GENERATED_CSS_DIR}" do
    environment = Sprockets::Environment.new
    environment.append_path File.expand_path(COMPONENT_DIR)
    environment.cache = Sass::CacheStores::Memory.new
    run environment
  end
end.to_app

@server = Rack::Server.new({:app => compiler, :Port => 9292})

Thread.new do
  loop do
    if $stdin.gets.nil?
      @server.server.shutdown
      Process.exit
    end
  end
end

@server.start

该软件包安装以下gem:

  • rack(1.4.1)
  • sass(3.1.15)
  • sass-globbing(1.0.0.rc.2)
  • 指南针(0.12.1)
  • compass-magick(0.1.4)
  • 链轮(2.3.1)
  • sprockets-helpers(0.4.0)
  • sprockets-sass(0.7.0)

对于我如何解决这个问题的任何见解或指示,我都会非常感激。

1 个答案:

答案 0 :(得分:2)

看起来你需要类似的东西;

compass.add_import_path File.expand_path(File.join(COMPONENT_DIR, "components"))

Compass.configuration do |compass|区块内?