我有一段用于编译 .scss 代码的 ruby 代码。我正在尝试构建一个自定义导入器来从数据库加载文件。
这是我的红宝石代码:
require 'rubygems'
require 'sass'
require 'sass/plugin'
require './eptimporter'  # my custom importer( code below )
Sass::Plugin.options[:load_paths] ||= []
Sass::Plugin.options[:load_paths] << Sass::Importers::Eptimporter.new("dummy")
puts Sass::Plugin.options[:load_paths]
puts Sass.compile_file("sass/sass.scss")  # scss file (code below)
这是我的进口商:
module Sass
  module Importers
    class Eptimporter < Base
      attr_accessor :root
      def initialize(root)
        @root = root
      end
      # @see Base#find_relative
      def find_relative(name, base, options)
        nil
      end
      # @see Base#find
      def find(name, options)
        options[:syntax] = ":scss"
        options[:filename] = name
        options[:importer] = self
        Sass::Engine.new("p { color :blue; }", options)
      end
      # @see Base#mtime
      def mtime(name, options)
        Time.now
      end
      # @see Base#key
      def key(name, options)
        [self.class.name , name]
      end
      # @see Base#to_s
      def to_s
        @root
      end
    end
  end
end
最后是我的 scss 文件:
@import "dummy.scss";
p { 
  color: red; 
  span { text-transform: uppercase; }
}
p { color :blue; }无论导入字符串是什么,自定义导入器都只会返回一个静态 CSS 代码。我确实得到了一个File to import not found or unreadable: dummy.scss. (Sass::SyntaxError)错误。什么会导致此错误?