├── .gitignore ├── CHANGELOG.markdown ├── Gemfile ├── LICENSE.txt ├── README.markdown ├── Rakefile ├── lib ├── sass-css-importer.rb └── sass │ ├── css_importer.rb │ └── css_importer │ ├── importer.rb │ ├── monkey_patches.rb │ └── version.rb ├── sass-css-importer.gemspec └── test ├── fixtures ├── imports_css.scss └── some_css_files │ ├── _partial.css │ └── foo.css └── sass_css_importer_test.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | -------------------------------------------------------------------------------- /CHANGELOG.markdown: -------------------------------------------------------------------------------- 1 | # 1.0.0 2 | 3 | Initial release. 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | gemspec 4 | 5 | gem 'rake' 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Chris Eppstein 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Sass CSS Importer Plugin 2 | 3 | The Sass CSS Importer allows you to import a CSS file into Sass. 4 | 5 | ## Stylesheet Syntax 6 | 7 | The `.css` extension triggers special behavior in Sass so you cannot 8 | import a file with a CSS extension. To work around this, you must use a 9 | special prefix on the import string and omit the extension. 10 | 11 | @import "CSS:some_folder/some_css_file" 12 | 13 | ## Installation 14 | 15 | $ gem install --pre sass-css-importer 16 | 17 | ## Use with the Sass command line 18 | 19 | $ sass -r sass-css-importer --watch sass_dir:css_dir 20 | 21 | Note: several -r options can be given to the sass command line if you 22 | need to require several libraries. 23 | 24 | ## Use with compass 25 | 26 | Add the following to your compass configuration: 27 | 28 | require 'sass-css-importer' 29 | 30 | ## More complex scenarios 31 | 32 | This plugin assumes you want to import CSS files relative to a Sass 33 | file. More complex scenarios are acheivable by adding a CSS Importer to 34 | the Sass load path option explicitly. 35 | 36 | For example, in compass you can do the following in your `config.rb` 37 | file: 38 | 39 | ```ruby 40 | require 'sass-css-importer' 41 | add_import_path Sass::CssImporter::Importer.new("/path/to/the/css/files") 42 | ``` 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | 4 | require 'rake/testtask' 5 | 6 | Rake::TestTask.new(:test) do |t| 7 | t.libs << 'lib' 8 | t.libs << 'test' 9 | t.pattern = 'test/**/*_test.rb' 10 | t.verbose = false 11 | end 12 | -------------------------------------------------------------------------------- /lib/sass-css-importer.rb: -------------------------------------------------------------------------------- 1 | require 'sass/css_importer' 2 | -------------------------------------------------------------------------------- /lib/sass/css_importer.rb: -------------------------------------------------------------------------------- 1 | module Sass 2 | module CssImporter 3 | end 4 | end 5 | 6 | require 'sass/css_importer/importer'; 7 | require 'sass/css_importer/monkey_patches'; 8 | -------------------------------------------------------------------------------- /lib/sass/css_importer/importer.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | require 'singleton' 3 | 4 | class Sass::CssImporter::Importer < Sass::Importers::Filesystem 5 | 6 | def initialize(root) 7 | super(root) 8 | end 9 | 10 | # Enable watching of css files in Sass 3.3+ 11 | def watched_directories 12 | [root] 13 | end 14 | 15 | # Enable watching of css files in Sass 3.3+ 16 | def watched_file?(file) 17 | file.start_with?(root+File::SEPARATOR) && File.extname(file) == ".css" 18 | end 19 | 20 | def extensions 21 | {'css' => :scss} 22 | end 23 | 24 | def find_relative(name, base, options) 25 | super(strip_prefix(name), base, options) 26 | end 27 | 28 | 29 | def find(name, options) 30 | super(strip_prefix(name), options) 31 | end 32 | 33 | 34 | def mtime(name, options) 35 | super(strip_prefix(name), options) 36 | end 37 | 38 | def key(name, options) 39 | super(strip_prefix(name), options) 40 | end 41 | 42 | def to_s 43 | "Sass::CssImporter::Importer(#{root})" 44 | end 45 | 46 | def eql?(other) 47 | other.class == self.class && other.root == self.root 48 | end 49 | 50 | protected 51 | 52 | def strip_prefix(name) 53 | name.start_with?("CSS:") ? name[4..-1] : name 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /lib/sass/css_importer/monkey_patches.rb: -------------------------------------------------------------------------------- 1 | require 'sass' 2 | 3 | class Sass::Engine 4 | alias initialize_without_css_importer initialize 5 | 6 | def initialize(template, options={}) 7 | initialize_without_css_importer(template, options) 8 | 9 | css_importer = self.options[:load_paths].find {|lp| lp.is_a?(Sass::CssImporter::Importer) } 10 | 11 | unless css_importer 12 | root = File.dirname(options[:filename] || ".") 13 | self.options[:load_paths] << Sass::CssImporter::Importer.new(root) 14 | end 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /lib/sass/css_importer/version.rb: -------------------------------------------------------------------------------- 1 | module Sass 2 | module CssImporter 3 | VERSION = "1.0.0.beta.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /sass-css-importer.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "sass/css_importer/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "sass-css-importer" 7 | s.version = Sass::CssImporter::VERSION 8 | s.platform = Gem::Platform::RUBY 9 | s.authors = ["Chris Eppstein"] 10 | s.email = ["chris@eppsteins.net"] 11 | s.homepage = "http://chriseppstein.github.com/" 12 | s.summary = %q{Allows importing of css files using Sass @import directives.} 13 | s.description = %q{Allows importing of css files using Sass @import directives.} 14 | 15 | s.files = `git ls-files`.split("\n") 16 | s.test_files = `git ls-files -- test/*`.split("\n") 17 | s.require_paths = ["lib"] 18 | 19 | s.add_runtime_dependency 'sass', '>= 3.1' 20 | 21 | end 22 | -------------------------------------------------------------------------------- /test/fixtures/imports_css.scss: -------------------------------------------------------------------------------- 1 | @import "CSS:some_css_files/partial"; 2 | @import "CSS:some_css_files/foo"; 3 | -------------------------------------------------------------------------------- /test/fixtures/some_css_files/_partial.css: -------------------------------------------------------------------------------- 1 | .css-partial { 2 | color: black; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/some_css_files/foo.css: -------------------------------------------------------------------------------- 1 | .css-file { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/sass_css_importer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'sass' 3 | require 'sass/css_importer' 4 | 5 | class SassCssImporterTest < Test::Unit::TestCase 6 | 7 | def test_can_import_css_files_files 8 | css = render_file("imports_css.scss") 9 | assert_match(/\.css-partial/, css) 10 | assert_match(/\.css-file/, css) 11 | end 12 | 13 | private 14 | def render_file(filename) 15 | fixtures_dir = File.expand_path("fixtures", File.dirname(__FILE__)) 16 | full_filename = File.expand_path(filename, fixtures_dir) 17 | syntax = File.extname(full_filename)[1..-1].to_sym 18 | engine = Sass::Engine.new(File.read(full_filename), 19 | :syntax => syntax, 20 | :filename => full_filename, 21 | :cache => false, 22 | :read_cache => false, 23 | :load_paths => [fixtures_dir]) 24 | engine.render 25 | end 26 | end 27 | --------------------------------------------------------------------------------