나는 .scss 코드를 컴파일하기위한 루비 코드를 가지고있다. DB에서 파일을로드하는 사용자 지정 가져 오기 도구를 만들려고합니다.Sass 커스텀 임포터
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
그리고 마지막으로 내하는 SCS 파일 :
이@import "dummy.scss";
p {
color: red;
span { text-transform: uppercase; }
}
사용자 정의 수입 그냥 정적 CSS를 반환 여기
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)
내 수입입니다 : 여기
내 루비 코드 코드
p { color :blue; }
은 가져온 문자열과 관계 없습니다.
File to import not found or unreadable: dummy.scss. (Sass::SyntaxError)
오류가 발생합니다. 이 오류의 원인은 무엇입니까?