├── .gitignore ├── .travis.yml ├── Appraisals ├── CHANGELOG.md ├── Gemfile ├── Guardfile ├── LICENSE ├── README.md ├── Rakefile ├── compass-rails.gemspec ├── gemfiles ├── rails52.gemfile ├── rails60.gemfile └── rails_edge.gemfile ├── lib ├── compass-rails.rb └── compass-rails │ ├── configuration.rb │ ├── patches.rb │ ├── patches │ ├── 3_1.rb │ ├── 4_0.rb │ ├── compass.rb │ ├── importer.rb │ ├── sass_importer.rb │ ├── sprite_importer.rb │ └── static_compiler.rb │ ├── railties.rb │ ├── railties │ ├── 3_1.rb │ └── 4_0.rb │ └── version.rb ├── sache.json └── test ├── compass_rails_spec.rb ├── fixtures ├── .gitkeep └── assets │ ├── images │ ├── letters │ │ ├── a.png │ │ └── b.png │ └── numbers │ │ ├── sprite-1.png │ │ └── sprite-2.png │ └── stylesheets │ ├── application.css.scss │ └── partials │ ├── _partial_1.scss │ └── _partial_2.scss ├── helpers ├── command_helper.rb ├── debug_helper.rb ├── file_helper.rb ├── rails_helper.rb └── rails_project.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .idea 5 | .config 6 | .yardoc 7 | gemfiles/*.gemfile.lock 8 | Gemfile.lock 9 | InstalledFiles 10 | _yardoc 11 | coverage 12 | doc/ 13 | lib/bundler/man 14 | pkg 15 | rdoc 16 | spec/reports 17 | test/tmp 18 | test/version_tmp 19 | tmp 20 | rails-temp/* 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | sudo: false 3 | rvm: 4 | - 2.4.9 5 | - 2.5.7 6 | - 2.6.5 7 | - 2.7.0 8 | - ruby-head 9 | - jruby-head 10 | gemfile: 11 | - gemfiles/rails52.gemfile 12 | - gemfiles/rails60.gemfile 13 | - gemfiles/rails_edge.gemfile 14 | matrix: 15 | exclude: 16 | - rvm: 2.4.9 17 | gemfile: gemfiles/rails60.gemfile 18 | - rvm: 2.4.9 19 | gemfile: gemfiles/rails_edge.gemfile 20 | fast_finish: true 21 | allow_failures: 22 | - rvm: ruby-head 23 | - rvm: jruby-head 24 | - gemfile: gemfiles/rails_edge.gemfile 25 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | appraise "rails52" do 2 | gem "rails", "~> 5.2.0" 3 | gem "sprockets", "< 4.0" 4 | gem "sass-rails", "~> 5.0" 5 | gem "bootsnap", require: false 6 | end 7 | 8 | appraise "rails60" do 9 | gem "rails", "~> 6.0.0" 10 | gem "sprockets", "< 4.0" 11 | gem "sass-rails", "~> 5.0" 12 | gem "webpacker", "~> 4.0" 13 | gem "bootsnap", ">= 1.4.2", require: false 14 | end 15 | 16 | appraise "rails_edge" do 17 | gem "rails", github: "rails/rails" 18 | 19 | gem "sprockets", "< 4.0" 20 | gem "sass-rails", "~> 5.0" 21 | gem "webpacker", "~> 4.0" 22 | gem "bootsnap", ">= 1.4.2", require: false 23 | end 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | ## 3.0.1 - 2016-2 4 | ### Fixed 5 | - Fix running rake assts:precompile to be run in production mode. Issue #257. 6 | 7 | ## 3.0.0 - 2016-01-23 8 | ### Added 9 | - Added Sprockets 3 support. Issue #232, #236, #244. 10 | 11 | ### Fixed 12 | - Sprockets cache files are no longer saved to /tmp and now use the app-level tmp folder instead. 13 | 14 | ## 2.0.2 - 2015-01-03 15 | ### Fixed 16 | - Fixed test suite to test against Rails 3.1, 3.2, 4.0, 4.2 on Ruby 1.9.3, 2.0.0, 2.1.0, 2.2.0 and jruby-head. Issue #206 17 | - Support up to sass-rails 5.0.1. Issue #198 18 | - Fix sass_importer patches having incorrect method signatures. Issue #195 19 | - Fixed incorrect path generation for sprites in Rails 4. Issue #190 20 | 21 | ## 2.0.0 - 2014-07-10 22 | ### Added 23 | - Support for Rails 4.2 24 | - Allow newer sass-rails with Sass 3.3 support (see #160). 25 | 26 | ### Removed 27 | - Rails 3.0 support. 28 | 29 | ### Fixed 30 | - Properly bust the cache on image sprites within a sub-directory that 31 | are imported with a wildcard (see #166). 32 | 33 | ## 1.1.7 - 2014-03-18 34 | ### Fixed 35 | - Locked Sprockets version to 2.11.0 (see #146). 36 | 37 | ## 1.1.6 - 2014-03-11 38 | ### Fixed 39 | - Leave bundle selection to rails environment. 40 | 41 | ## 1.1.5 - 2014-03-11 42 | ### Added 43 | - Support for Ruby 2.1.0. 44 | 45 | ### Fixed 46 | - Fixed `rails_loaded?` for when Rails is defined but no application is actually loaded. 47 | 48 | ## 1.1.4 - 2014-03-18 49 | ### Changed 50 | - Simplified README. 51 | 52 | ## 1.1.3 - 2013-12-27 53 | ### Fixed 54 | - No longer assuming asset pipeline is running when generating sprites. 55 | 56 | ## 1.1.2 - 2013-12-06 57 | ### Fixed 58 | - Reverted fix for `generated_image_url` introduced in 1.1.0. 59 | 60 | ## 1.1.1 - 2013-12-05 61 | ### Added 62 | - Support for Compass versions greater than 0.12.2. 63 | 64 | ## 1.1.0 - 2013-12-05 65 | ### Added 66 | - Rails 4 support. 67 | - Ruby 2.0 support. 68 | 69 | ### Fixed 70 | - Allow compass-rails without asset pipeline on Rails 3.2. 71 | - Fix `generated_image_url` when `generated_images_dir` is set. 72 | 73 | ### Removed 74 | - Support for Ruby 1.8.7 and 1.9.2. 75 | - Support for Rails 2.3. 76 | 77 | ## 1.0.3 - 2012-06-26 78 | ### Added 79 | - Bumped Compass version to 0.12.2. 80 | 81 | ### Fixed 82 | - `FixedStaticCompiler` hack so sprite source files dont show up in manifest. 83 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | # Specify your gem's dependencies in compass-rails.gemspec 5 | gemspec 6 | 7 | group :test do 8 | gem 'mocha' 9 | gem 'appraisal' 10 | gem 'minitest' 11 | end 12 | 13 | unless ENV["CI"] 14 | gem 'rb-fsevent', :require => false 15 | gem 'ruby_gntp', :require => false 16 | gem 'guard' 17 | gem 'guard-test' 18 | end 19 | 20 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard :test, :cli => '-v v' do 5 | watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } 6 | watch(%r{^test/.+_test\.rb$}) 7 | watch('test/test_helper.rb') { "test" } 8 | 9 | end 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Scott Davis 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # END OF LIFE - compass-rails 2 | 3 | **Don't use compass, it is no longer supported, see the [compass statement](https://github.com/Compass/compass/pull/2094)** 4 | 5 | [![Build Status](https://travis-ci.org/Compass/compass-rails.svg?branch=master)](https://travis-ci.org/Compass/compass-rails) 6 | [![Code Climate](https://codeclimate.com/github/Compass/compass-rails.svg)](https://codeclimate.com/github/Compass/compass-rails) 7 | [![Gem Version](https://badge.fury.io/rb/compass-rails.svg)](http://badge.fury.io/rb/compass-rails) 8 | [![Coverage Status](https://coveralls.io/repos/Compass/compass-rails/badge.svg)](https://coveralls.io/r/Compass/compass-rails) 9 | 10 | Compass rails is an adapter for the [Compass Stylesheet Authoring 11 | Framework](http://compass-style.org) for [Ruby on Rails](http://rubyonrails.org/). 12 | 13 | Since Compass v0.12.0, this is the only way to use compass with your rails application. 14 | 15 | Supports Rails 5.2 and 6.x releases. 16 | 17 | ## Installation 18 | 19 | Add the `compass-rails` gem line to your application's Gemfile 20 | 21 | ```ruby 22 | gem 'sass-rails' 23 | gem 'compass-rails' 24 | ``` 25 | 26 | If you are using any Compass extensions, add them to this group in your 27 | Gemfile. 28 | 29 | And then execute: 30 | 31 | $ bundle 32 | 33 | ## Usage 34 | 35 | Change your `application.css` to `application.css.scss` or `application.css.sass` and then `@import compass` and your own stylesheets to your hearts content. E.g.: 36 | 37 | ```scss 38 | @import "compass"; 39 | 40 | @import "your_project/mixins"; 41 | @import "your_project/base"; 42 | ``` 43 | 44 | *or* 45 | 46 | Use `application.css` to require files that use compass features. Ex: 47 | ```css 48 | /* 49 | *= require styleguide_full_of_compass_stuff 50 | */ 51 | ``` 52 | 53 | *Don't* use `*= require something` within your SCSS or SASS files. You're gonna have a bad time. 54 | 55 | ### Configuration 56 | 57 | Compass-rails is configured out of the box to work with Rails. 58 | 59 | Advanced users can choose to add a `config/compass.rb` and take advantage of the [Compass configuration 60 | reference](http://compass-style.org/help/documentation/configuration-reference/) 61 | as is. 62 | 63 | ### Installing Compass extensions 64 | 65 | Step 1: Add it to your Gemfile and run the `bundle` command to install it. 66 | 67 | Step 2: Install the extension's assets: `bundle exec compass install 68 | ` 69 | 70 | For example, if you want to use susy. 71 | 72 | ```ruby 73 | # Gemfile 74 | gem 'compass-rails' 75 | gem 'susy' 76 | ``` 77 | 78 | then run: 79 | 80 | $ bundle 81 | $ bundle exec compass install susy 82 | 83 | if you are using the rails configuration files you should add: 84 | 85 | ```ruby 86 | config.compass.require "susy" 87 | ``` 88 | 89 | to your application.rb configuration file. 90 | 91 | ## Contributing 92 | 93 | 1. This project is EOL. No more changes will be accepted. 94 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require 'bundler/gem_tasks' 3 | require 'rake/testtask' 4 | 5 | Rake::TestTask.new :test do |t| 6 | require 'fileutils' 7 | t.libs << 'lib' 8 | t.libs << 'test' 9 | test_files = FileList['test/**/*_{test,spec}.rb'] 10 | test_files.exclude('test/rails/*', 'test/haml/*') 11 | t.test_files = test_files 12 | t.verbose = true 13 | end 14 | 15 | task :default => [:test] 16 | -------------------------------------------------------------------------------- /compass-rails.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/compass-rails/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Scott Davis", "Chris Eppstein", "Craig McNamara"] 6 | gem.email = ["jetviper21@gmail.com", "chris@eppsteins.net", "craig.mcnamara@gmail.com"] 7 | gem.description = %q{Integrate Compass into Rails 3.0 and up.} 8 | gem.summary = %q{Integrate Compass into Rails 3.0 and up.} 9 | gem.homepage = "https://github.com/Compass/compass-rails" 10 | 11 | gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 12 | gem.files = `git ls-files`.split("\n") 13 | gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 14 | gem.name = "compass-rails" 15 | gem.require_paths = ["lib"] 16 | gem.version = CompassRails::VERSION 17 | gem.license = "MIT" 18 | 19 | gem.add_dependency 'compass', '~> 1.0.0' 20 | gem.add_dependency 'sprockets', '< 4.0' 21 | gem.add_dependency 'sass-rails', '< 5.1' 22 | end 23 | -------------------------------------------------------------------------------- /gemfiles/rails52.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rb-fsevent", require: false 6 | gem "ruby_gntp", require: false 7 | gem "guard" 8 | gem "guard-test" 9 | gem "rails", "~> 5.2.0" 10 | gem "sprockets", "< 4.0" 11 | gem "sass-rails", "~> 5.0" 12 | gem "bootsnap", require: false 13 | 14 | group :test do 15 | gem "mocha" 16 | gem "appraisal" 17 | gem "minitest" 18 | end 19 | 20 | gemspec path: "../" 21 | -------------------------------------------------------------------------------- /gemfiles/rails60.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rb-fsevent", require: false 6 | gem "ruby_gntp", require: false 7 | gem "guard" 8 | gem "guard-test" 9 | gem "rails", "~> 6.0.0" 10 | gem "sprockets", "< 4.0" 11 | gem "sass-rails", "~> 5.0" 12 | gem "webpacker", "~> 4.0" 13 | gem "bootsnap", ">= 1.4.2", require: false 14 | 15 | group :test do 16 | gem "mocha" 17 | gem "appraisal" 18 | gem "minitest" 19 | end 20 | 21 | gemspec path: "../" 22 | -------------------------------------------------------------------------------- /gemfiles/rails_edge.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rb-fsevent", require: false 6 | gem "ruby_gntp", require: false 7 | gem "guard" 8 | gem "guard-test" 9 | gem "rails", git: "https://github.com/rails/rails.git" 10 | gem "sprockets", "< 4.0" 11 | gem "sass-rails", "~> 5.0" 12 | gem "webpacker", "~> 4.0" 13 | gem "bootsnap", ">= 1.4.2", require: false 14 | 15 | group :test do 16 | gem "mocha" 17 | gem "appraisal" 18 | gem "minitest" 19 | end 20 | 21 | gemspec path: "../" 22 | -------------------------------------------------------------------------------- /lib/compass-rails.rb: -------------------------------------------------------------------------------- 1 | require 'compass' 2 | require "compass-rails/version" 3 | require "compass-rails/configuration" 4 | 5 | module CompassRails 6 | 7 | RAILS_32 = %r{^3.2} 8 | RAILS_31 = %r{^3.1} 9 | 10 | extend self 11 | 12 | def setup_fake_rails_env_paths(sprockets_env) 13 | return unless rails_loaded? 14 | 15 | if sprockets_env.respond_to?(:trail, true) 16 | sprockets_trail = sprockets_env.send(:trail) 17 | else 18 | sprockets_trail = sprockets_env.index 19 | end 20 | 21 | keys = ['app/assets', 'lib/assets', 'vendor/assets'] 22 | local = keys.map {|path| ::Rails.root.join(path) }.map { |path| [File.join(path, 'images'), File.join(path, 'stylesheets')] }.flatten! 23 | sprockets_trail.paths.unshift(*local) 24 | paths = [] 25 | ::Rails::Engine.subclasses.each do |subclass| 26 | paths = subclass.paths 27 | keys.each do |key| 28 | sprockets_trail.paths.unshift(*paths[key].existent_directories) 29 | end 30 | end 31 | end 32 | 33 | def sass_config 34 | ::Rails.application.config.sass 35 | end 36 | 37 | def sprockets 38 | @sprockets ||= Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application) 39 | end 40 | 41 | def context 42 | @context ||= begin 43 | sprockets.version = ::Rails.env + "-#{sprockets.version}" 44 | setup_fake_rails_env_paths(sprockets) 45 | context = ::CompassRails.sprockets.context_class 46 | context.extend(::Sprockets::Helpers::IsolatedHelper) 47 | context.extend(::Sprockets::Helpers::RailsHelper) 48 | context.extend(::Sass::Rails::Railtie::SassContext) 49 | context.sass_config = sass_config 50 | 51 | context 52 | end 53 | end 54 | 55 | def rails_loaded? 56 | defined?(::Rails) 57 | end 58 | 59 | def rails_version 60 | rails_spec = (Gem.loaded_specs["railties"] || Gem.loaded_specs["rails"]) 61 | raise "You have to require Rails before compass" unless rails_spec 62 | rails_spec.version.to_s 63 | end 64 | 65 | def rails31? 66 | return false unless defined?(::Rails) 67 | version_match RAILS_31 68 | end 69 | 70 | def rails32? 71 | return false unless defined?(::Rails) 72 | version_match RAILS_32 73 | end 74 | 75 | def version_match(version) 76 | !(rails_version =~ version).nil? 77 | end 78 | 79 | def configuration 80 | config = Compass::Configuration::Data.new('rails') 81 | config.extend(CompassRails::Configuration) 82 | config 83 | end 84 | 85 | def prefix 86 | ::Rails.application.config.assets.prefix 87 | end 88 | 89 | def configure_rails!(app) 90 | return unless app.config.respond_to?(:sass) 91 | sass_config = app.config.sass 92 | compass_config = app.config.compass 93 | 94 | sass_config.load_paths.concat(compass_config.sass_load_paths) 95 | 96 | { :output_style => :style, 97 | :line_comments => :line_comments, 98 | :cache => :cache, 99 | :disable_warnings => :quiet, 100 | :preferred_syntax => :preferred_syntax 101 | }.each do |compass_option, sass_option| 102 | set_maybe sass_config, compass_config, sass_option, compass_option 103 | end 104 | if compass_config.sass_options 105 | compass_config.sass_options.each do |config, value| 106 | sass_config.send("#{config}=", value) 107 | end 108 | end 109 | end 110 | 111 | private 112 | 113 | # sets the sass config value only if the corresponding compass-based setting 114 | # has been explicitly set by the user. 115 | def set_maybe(sass_config, compass_config, sass_option, compass_option) 116 | if compass_value = compass_config.send(:"#{compass_option}_without_default") 117 | sass_config.send(:"#{sass_option}=", compass_value) 118 | end 119 | end 120 | 121 | end 122 | 123 | if defined?(::Rails) 124 | Compass::AppIntegration.register(:rails, "::CompassRails") 125 | require "compass-rails/patches" 126 | require "compass-rails/railties" 127 | end 128 | -------------------------------------------------------------------------------- /lib/compass-rails/configuration.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | module Configuration 3 | def default_images_dir 4 | File.join("app", "assets", "images") 5 | end 6 | 7 | def default_fonts_dir 8 | File.join("app", "assets", "fonts") 9 | end 10 | 11 | def default_javascripts_dir 12 | File.join("app", "assets", "javascripts") 13 | end 14 | 15 | def default_css_dir 16 | File.join('public', CompassRails.prefix) 17 | end 18 | 19 | def default_http_path 20 | File.join(CompassRails.prefix) 21 | end 22 | 23 | def default_http_images_path 24 | "#{top_level.http_path}" 25 | end 26 | 27 | def default_http_javascripts_path 28 | "#{top_level.http_path}" 29 | end 30 | 31 | def default_http_fonts_path 32 | "#{top_level.http_path}" 33 | end 34 | 35 | def default_http_stylesheets_path 36 | "#{top_level.http_path}" 37 | end 38 | 39 | def default_preferred_syntax 40 | ::Rails.application.config.sass.preferred_syntax rescue nil 41 | end 42 | 43 | def default_sprite_load_path 44 | CompassRails.sprockets.paths 45 | end 46 | 47 | def project_type_without_default 48 | :rails 49 | end 50 | 51 | def default_sass_dir 52 | File.join("app", "assets", "stylesheets") 53 | end 54 | 55 | def default_http_generated_images_path 56 | # Relies on the fact that this will be loaded after the "normal" 57 | # defaults, so that method_missing finds http_root_relative 58 | http_root_relative "images" 59 | end 60 | 61 | def default_extensions_dir 62 | File.join("vendor", "plugins", "compass_extensions") 63 | end 64 | 65 | def default_cache_dir 66 | File.join("tmp", "sass-cache") 67 | end 68 | 69 | def default_project_path 70 | Rails.root 71 | end 72 | 73 | def default_environment 74 | Rails.env 75 | end 76 | end 77 | end -------------------------------------------------------------------------------- /lib/compass-rails/patches.rb: -------------------------------------------------------------------------------- 1 | if CompassRails.rails31? || CompassRails.rails32? 2 | require 'compass-rails/patches/importer' 3 | end 4 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/3_1.rb: -------------------------------------------------------------------------------- 1 | require 'compass-rails/patches/compass' 2 | require 'compass-rails/patches/static_compiler' 3 | 4 | Compass::Core::SassExtensions::Functions::Urls::GeneratedImageUrl.module_eval do 5 | def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false)) 6 | asset_url(path, Sass::Script::String.new('image')) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/4_0.rb: -------------------------------------------------------------------------------- 1 | require 'compass-rails/patches/compass' 2 | require 'compass-rails/patches/sass_importer' 3 | require 'compass-rails/patches/sprite_importer' 4 | 5 | Compass::Core::SassExtensions::Functions::Urls::GeneratedImageUrl.module_eval do 6 | def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false)) 7 | cachebust_generated_images(path) 8 | asset_url(path) 9 | end 10 | 11 | def cachebust_generated_images(path) 12 | generated_images_dir = Compass.configuration.generated_images_dir 13 | generated_images_dir = Rails.root.join(generated_images_dir) 14 | 15 | sprockets_env = options[:sprockets][:environment] 16 | 17 | if sprockets_env.respond_to?(:trail, true) 18 | sprockets_trail = sprockets_env.send(:trail) 19 | else 20 | sprockets_trail = sprockets_env.index 21 | end 22 | 23 | sprockets_entries = sprockets_trail.instance_variable_get(:@entries) || {} 24 | sprockets_stats = sprockets_trail.instance_variable_get(:@stats) || {} 25 | 26 | if sprockets_entries.key?(generated_images_dir.to_s) 27 | path = path.value 28 | dir = File.dirname(path) 29 | 30 | # Delete the entries (directories) which cache the files/dirs in a directory 31 | entry = generated_images_dir.join(dir).to_s 32 | sprockets_entries.delete(entry) 33 | 34 | # Delete the stats (file/dir info) which cache the what kind of file/dir each image is 35 | stat = generated_images_dir.join(path).to_s 36 | sprockets_stats.delete(stat) 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/compass.rb: -------------------------------------------------------------------------------- 1 | Compass::Core::SassExtensions::Functions::ImageSize.class_eval do 2 | private 3 | 4 | def image_path_for_size(image_file) 5 | begin 6 | file = ::CompassRails.sprockets.find_asset(image_file) 7 | return (file.respond_to?(:pathname) ? file.pathname.to_s : file) 8 | rescue ::Sprockets::FileOutsidePaths 9 | return super(image_file) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/importer.rb: -------------------------------------------------------------------------------- 1 | require 'compass/compiler' 2 | module Compass 3 | class Compiler 4 | attr_accessor :sass_options 5 | STYLESHEET = /stylesheet/ 6 | def sass_options 7 | @sass_options[:custom] ||= {} 8 | @sass_options[:custom] = {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)} 9 | @sass_options[:load_paths] ||= [] 10 | unless @sass_options[:load_paths].any? {|k| k.is_a?(::Sass::Rails::Importer) } 11 | ::CompassRails.sprockets.paths.each do |path| 12 | next unless path.to_s =~ STYLESHEET 13 | Dir["#{path}/**/*"].each do |pathname| 14 | # args are: sprockets environment, the logical_path ex. 'stylesheets', and the full path name for the render 15 | context = ::CompassRails.context.new(::CompassRails.sprockets, File.basename(path), Pathname.new(pathname)) 16 | @sass_options[:load_paths] << ::Sass::Rails::Importer.new(context) 17 | end 18 | end 19 | end 20 | @sass_options 21 | end 22 | 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/sass_importer.rb: -------------------------------------------------------------------------------- 1 | klass = if defined?(Sass::Rails::SassTemplate) 2 | Sass::Rails::SassTemplate 3 | else 4 | Sprockets::SassTemplate 5 | end 6 | 7 | klass.class_eval do 8 | def evaluate(context, locals, &block) 9 | # Use custom importer that knows about Sprockets Caching 10 | cache_store = 11 | if defined?(Sprockets::SassProcessor::CacheStore) 12 | Sprockets::SassProcessor::CacheStore.new(sprockets_cache_store, context.environment) 13 | else 14 | Sprockets::SassCacheStore.new(context.environment) 15 | end 16 | 17 | paths = context.environment.paths.map { |path| CompassRails::SpriteImporter.new(path) } 18 | paths += context.environment.paths.map { |path| sass_importer(context, path) } 19 | paths += ::Rails.application.config.sass.load_paths 20 | 21 | options = CompassRails.sass_config.merge( { 22 | :filename => eval_file, 23 | :line => line, 24 | :syntax => syntax, 25 | :cache_store => cache_store, 26 | :importer => sass_importer(context, context.pathname), 27 | :load_paths => paths, 28 | :sprockets => { 29 | :context => context, 30 | :environment => context.environment 31 | } 32 | }) 33 | 34 | engine = ::Sass::Engine.new(data, options) 35 | 36 | engine.dependencies.map do |dependency| 37 | filename = dependency.options[:filename] 38 | if filename.include?('*') # Handle sprite globs 39 | image_path = Rails.root.join(Compass.configuration.images_dir).to_s 40 | Dir[File.join(image_path, filename)].each do |f| 41 | context.depend_on(f) 42 | end 43 | else 44 | context.depend_on(filename) if File.exist?(filename) 45 | end 46 | end 47 | 48 | engine.render 49 | rescue ::Sass::SyntaxError => e 50 | # Annotates exception message with parse line number 51 | context.__LINE__ = e.sass_backtrace.first[:line] 52 | raise e 53 | end 54 | 55 | private 56 | 57 | def sass_importer_artiy 58 | @sass_importer_artiy ||= sass_importer_class.instance_method(:initialize).arity 59 | end 60 | 61 | def sass_importer(context, path) 62 | case sass_importer_artiy.abs 63 | when 1 64 | sass_importer_class.new(path) 65 | else 66 | sass_importer_class.new(context, path) 67 | end 68 | end 69 | 70 | # if using haml-rails, self.class.parent = Haml::Filters (which doesn't have an implementation) 71 | def sass_importer_class 72 | @sass_importer_class ||= if defined?(self.class.parent::SassImporter) 73 | self.class.parent::SassImporter 74 | elsif defined?(Sass::Rails::SassTemplate) 75 | Sass::Rails::SassImporter 76 | else 77 | Sprockets::SassImporter 78 | end 79 | end 80 | 81 | def sprockets_cache_store 82 | cache = 83 | case Rails.application.config.assets.cache_store 84 | when :null_store 85 | Sprockets::Cache::NullStore.new 86 | when :memory_store, :mem_cache_store 87 | Sprockets::Cache::MemoryStore.new 88 | else 89 | path = "#{Rails.application.config.root}/tmp/cache/assets/#{Rails.env}" 90 | 91 | Sprockets::Cache::FileStore.new(path) 92 | end 93 | 94 | Sprockets::Cache.new(cache, Rails.logger) 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/sprite_importer.rb: -------------------------------------------------------------------------------- 1 | require 'sprockets' 2 | require 'compass/sprite_importer' 3 | 4 | module CompassRails 5 | class SpriteImporter < Compass::SpriteImporter 6 | attr_reader :root 7 | 8 | def initialize(root) 9 | @root = root 10 | end 11 | 12 | def find(uri, options) 13 | if old = super(uri, options) 14 | context = options[:sprockets][:context] 15 | self.class.files(uri).each do |file| 16 | relative_path = Pathname.new(file).relative_path_from(Pathname.new(root)) 17 | begin 18 | pathname = context.resolve(relative_path.to_s) 19 | context.depend_on_asset(pathname) 20 | rescue Sprockets::FileNotFound 21 | 22 | end 23 | end 24 | end 25 | 26 | old 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/compass-rails/patches/static_compiler.rb: -------------------------------------------------------------------------------- 1 | require 'sprockets/static_compiler' 2 | module Sprockets 3 | class StaticCompiler 4 | cattr_accessor :generated_sprites 5 | self.generated_sprites = {} 6 | def write_manifest_with_sprites(manifest) 7 | write_manifest_without_sprites(manifest.merge(self.class.generated_sprites)) 8 | end 9 | alias_method_chain :write_manifest, :sprites 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /lib/compass-rails/railties.rb: -------------------------------------------------------------------------------- 1 | if defined?(::Rails) 2 | if CompassRails.rails31? || CompassRails.rails32? 3 | require "compass-rails/railties/3_1" 4 | else 5 | require "compass-rails/railties/4_0" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/compass-rails/railties/3_1.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | class Railtie < Rails::Railtie 3 | 4 | initializer "compass.initialize_rails", :group => :all do |app| 5 | require 'compass' 6 | require 'compass-rails/patches/3_1' 7 | Compass.discover_extensions! 8 | CompassRails.configure_rails!(app) 9 | end 10 | 11 | config.compass = begin 12 | @compass ||= begin 13 | data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file)) 14 | config_data 15 | else 16 | Compass::Configuration::Data.new("rails_config") 17 | end 18 | data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded. 19 | Compass.add_configuration(:rails) 20 | Compass.add_configuration(data) 21 | Compass.configuration.on_sprite_saved do |filename| 22 | if Rails.application.config.assets.digest && # if digesting is enabled 23 | caller.grep(/static_compiler/).any? && #OMG HAX - check if we're being precompiled 24 | Compass.configuration.generated_images_path[Compass.configuration.images_path] # if the generated images path is not in the assets images directory, we don't have to do these backflips 25 | 26 | # Clear entries in Hike::Index for this sprite's directory. 27 | # This makes sure the asset can be found by find_assets 28 | CompassRails.sprockets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename)) 29 | 30 | pathname = Pathname.new(filename) 31 | logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path)) 32 | asset = CompassRails.sprockets.find_asset(logical_path) 33 | target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path) 34 | 35 | # Adds the asset to the manifest file. 36 | Sprockets::StaticCompiler.generated_sprites[logical_path.to_s] = asset.digest_path 37 | 38 | # Adds the fingerprinted asset to the public directory 39 | FileUtils.mkdir_p File.dirname(target) 40 | asset.write_to target 41 | 42 | end 43 | end 44 | data 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/compass-rails/railties/4_0.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | class Railtie < Rails::Railtie 3 | 4 | initializer "compass.initialize_rails", :group => :all do |app| 5 | require 'compass' 6 | require 'compass-rails/patches/4_0' 7 | Compass.discover_extensions! 8 | CompassRails.configure_rails!(app) 9 | end 10 | 11 | config.compass = begin 12 | @compass ||= begin 13 | data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file)) 14 | config_data 15 | else 16 | Compass::Configuration::Data.new("rails_config") 17 | end 18 | data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded. 19 | Compass.add_configuration(:rails) 20 | Compass.add_configuration(data) 21 | Compass.configuration.on_sprite_saved do |filename| 22 | if Rails.application.config.assets.digest && # if digesting is enabled 23 | caller.grep(%r{/sprockets/rails/task.rb}).any? && #OMG HAX - check if we're being precompiled 24 | Compass.configuration.generated_images_path[Compass.configuration.images_path.to_s] # if the generated images path is not in the assets images directory, we don't have to do these backflips 25 | 26 | # Clear entries in Hike::Index for this sprite's directory. 27 | # This makes sure the asset can be found by find_assets 28 | if CompassRails.sprockets.respond_to?(:trail, true) 29 | index = CompassRails.sprockets.send(:trail).index 30 | else 31 | index = CompassRails.sprockets.index 32 | end 33 | 34 | index.instance_variable_get(:@entries).delete(File.dirname(filename)) 35 | index.instance_variable_get(:@stats).delete(filename) 36 | 37 | pathname = Pathname.new(filename) 38 | logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path)).to_s 39 | asset = CompassRails.sprockets.find_asset(logical_path) 40 | target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path) 41 | 42 | # Adds the asset to the manifest file. 43 | 44 | manifest = ActionView::Base.assets_manifest 45 | manifest.assets[logical_path] = asset.digest_path 46 | 47 | 48 | # Adds the fingerprinted asset to the public directory 49 | FileUtils.mkdir_p File.dirname(target) 50 | asset.write_to target 51 | 52 | end 53 | end 54 | data 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/compass-rails/version.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | VERSION = '4.0.0' unless defined?(::CompassRails::VERSION) 3 | end 4 | -------------------------------------------------------------------------------- /sache.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "compass-rails", 3 | "description": "compass rails integration", 4 | "tags": ["ruby", "rails", "compass"] 5 | } 6 | -------------------------------------------------------------------------------- /test/compass_rails_spec.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | describe CompassRails do 4 | include CompassRails::Test::RailsHelpers 5 | 6 | it "compiles a basic compass stylesheet" do 7 | within_rails_app('test_railtie') do |project| 8 | project.setup_asset_fixtures! 9 | 10 | assert project.boots? 11 | 12 | project.precompile! 13 | 14 | project.compiled_stylesheet 'public/assets/application*.css' do |css| 15 | refute css.empty? 16 | assert_match 'body container', css 17 | assert_match "-webkit-linear-gradient", css 18 | assert_match "-moz-border-radius", css 19 | assert_match '.numbers-sprite-1', css 20 | assert_match '.numbers-sprite-2', css 21 | assert_match '.letters-a', css 22 | assert_match '.letters-a', css 23 | end 24 | end 25 | end 26 | 27 | it "supports rails config arguments" do 28 | within_rails_app('test_railtie') do |project| 29 | assert_equal "scss", project.rails_property("sass.preferred_syntax") 30 | assert_equal "public/assets", project.rails_property("compass.css_dir") 31 | 32 | project.set_rails('sass.preferred_syntax', :sass) 33 | project.set_rails('compass.css_dir', "public/stylesheets") 34 | 35 | assert_equal "sass", project.rails_property("sass.preferred_syntax") 36 | assert_equal "public/stylesheets", project.rails_property("compass.css_dir") 37 | end 38 | end unless ENV['DEBUG_COMPILE'] 39 | 40 | it "compiles when in production mode" do 41 | within_rails_app('test_railtie') do |project| 42 | project.setup_asset_fixtures! 43 | 44 | # Mimic Rails production mode 45 | project.set_rails('assets.compile', false) 46 | 47 | assert project.boots? 48 | 49 | project.precompile! 50 | 51 | project.compiled_stylesheet 'public/assets/application*.css' do |css| 52 | refute css.empty? 53 | assert_match 'body container', css 54 | assert_match '.numbers-sprite-1', css 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /test/fixtures/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Compass/compass-rails/f6391d0d30fa63bb9bf6cd94e0e5608012584e6e/test/fixtures/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/assets/images/letters/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Compass/compass-rails/f6391d0d30fa63bb9bf6cd94e0e5608012584e6e/test/fixtures/assets/images/letters/a.png -------------------------------------------------------------------------------- /test/fixtures/assets/images/letters/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Compass/compass-rails/f6391d0d30fa63bb9bf6cd94e0e5608012584e6e/test/fixtures/assets/images/letters/b.png -------------------------------------------------------------------------------- /test/fixtures/assets/images/numbers/sprite-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Compass/compass-rails/f6391d0d30fa63bb9bf6cd94e0e5608012584e6e/test/fixtures/assets/images/numbers/sprite-1.png -------------------------------------------------------------------------------- /test/fixtures/assets/images/numbers/sprite-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Compass/compass-rails/f6391d0d30fa63bb9bf6cd94e0e5608012584e6e/test/fixtures/assets/images/numbers/sprite-2.png -------------------------------------------------------------------------------- /test/fixtures/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | // Import Compass 2 | @import "compass"; 3 | 4 | // Glob import SCSS partials 5 | @import "partials/*"; 6 | 7 | // Import Sprites 8 | @import "letters/*.png"; 9 | @include all-letters-sprites; 10 | 11 | // Inline Sprites 12 | $numbers-inline: true; 13 | @import "numbers/sprite-*.png"; 14 | @include all-numbers-sprites; 15 | 16 | // Try out some compass stuff 17 | body{ 18 | @include background-image(linear-gradient(white, #aaaaaa)); 19 | 20 | container{ 21 | @include border-radius(4px, 4px); 22 | } 23 | } -------------------------------------------------------------------------------- /test/fixtures/assets/stylesheets/partials/_partial_1.scss: -------------------------------------------------------------------------------- 1 | .partial1 { 2 | display: none; 3 | } -------------------------------------------------------------------------------- /test/fixtures/assets/stylesheets/partials/_partial_2.scss: -------------------------------------------------------------------------------- 1 | .partial2{ 2 | display: block; 3 | } -------------------------------------------------------------------------------- /test/helpers/command_helper.rb: -------------------------------------------------------------------------------- 1 | require 'appraisal' 2 | require 'appraisal/command' 3 | module Kernal 4 | module Captures 5 | def capture_output 6 | buffer = [] 7 | real_stdout, $stdout = $stdout, StringIO.new 8 | buffer << yield 9 | buffer << $stdout.string 10 | return buffer.join 11 | ensure 12 | $stdout = real_stdout 13 | end 14 | 15 | def capture_all_output 16 | capture_output do 17 | capture_warning do 18 | yield 19 | end 20 | end 21 | end 22 | 23 | 24 | def capture_warning 25 | buffer = [] 26 | real_stderr, $stderr = $stderr, StringIO.new 27 | buffer << yield 28 | buffer << $stderr.string 29 | return buffer.join 30 | ensure 31 | $stderr = real_stderr 32 | end 33 | end 34 | end 35 | 36 | include Kernal::Captures 37 | 38 | module CompassRails 39 | module Test 40 | module CommandHelper 41 | include DebugHelper 42 | GEMFILES_DIR = Pathname.new(ROOT_PATH).join('gemfiles') 43 | BUNDLER_COMMAND = 'bundle' 44 | 45 | def run_command(command, gemfile=nil) 46 | debug "Running: #{command} with gemfile: #{gemfile}" 47 | capture_all_output { CompassRails::Test::CommandRunner.new(command, gemfile).run } 48 | end 49 | 50 | def bundle(gemfile=nil) 51 | run_command(BUNDLER_COMMAND, gemfile) 52 | end 53 | 54 | end 55 | end 56 | end 57 | 58 | # Executes commands with a clean environment 59 | class CompassRails::Test::CommandRunner 60 | BUNDLER_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze 61 | 62 | def self.from_args(gemfile) 63 | command = ([$0] + ARGV.slice(1, ARGV.size)).join(' ') 64 | new(command, gemfile) 65 | end 66 | 67 | def initialize(command, gemfile = nil) 68 | @original_env = {} 69 | @gemfile = gemfile 70 | if command =~ /^bundle/ 71 | @command = command 72 | else 73 | @command = "bundle exec #{command}" 74 | end 75 | end 76 | 77 | def run 78 | with_clean_env { %x{#{@command}} } 79 | end 80 | 81 | def exec 82 | with_clean_env { Kernel.exec(@command) } 83 | end 84 | 85 | private 86 | 87 | def with_clean_env 88 | unset_bundler_env_vars 89 | ENV['BUNDLE_GEMFILE'] = @gemfile 90 | yield 91 | ensure 92 | restore_env 93 | end 94 | 95 | def unset_bundler_env_vars 96 | BUNDLER_ENV_VARS.each do |key| 97 | @original_env[key] = ENV[key] 98 | ENV[key] = nil 99 | end 100 | end 101 | 102 | def restore_env 103 | @original_env.each { |key, value| ENV[key] = value } 104 | end 105 | end 106 | -------------------------------------------------------------------------------- /test/helpers/debug_helper.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | module Test 3 | module DebugHelper 4 | 5 | def debug(message) 6 | puts "#{message}\n" if ENV['DEBUG'] 7 | $stdout.flush 8 | end 9 | 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /test/helpers/file_helper.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | module Test 3 | module FileHelper 4 | include DebugHelper 5 | 6 | delegate :mkdir_p, :rm, :rm_rf, :cp_r, :touch, to: ::FileUtils 7 | 8 | def cd(path, &block) 9 | debug "Entering: #{path}" 10 | Dir.chdir(path, &block) 11 | end 12 | 13 | def inject_at_bottom(file_name, string) 14 | content = File.read(file_name) 15 | content = "#{content}#{string}" 16 | File.open(file_name, 'w') { |file| file << content } 17 | end 18 | 19 | def inject_into_file(file_name, replacement, position, anchor) 20 | case position 21 | when :after 22 | replace(file_name, Regexp.escape(anchor), "#{anchor}#{replacement}") 23 | when :before 24 | replace(file_name, Regexp.escape(anchor), "#{replacement}#{anchor}") 25 | else 26 | raise Compass::FilesystemConflict.new("You need to specify :before or :after") 27 | end 28 | end 29 | 30 | def replace(destination, regexp, string) 31 | content = File.read(destination) 32 | content.gsub!(Regexp.new(regexp), string) 33 | File.open(destination, 'wb') { |file| file.write(content) } 34 | end 35 | 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /test/helpers/rails_helper.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | module Test 3 | module RailsHelpers 4 | include FileHelper 5 | include DebugHelper 6 | include CommandHelper 7 | RAILS_6_1 = "6.1" 8 | RAILS_6_0 = "6.0" 9 | RAILS_5_2 = "5.2" 10 | 11 | WORKING_DIR = File.join(ROOT_PATH, 'rails-temp') 12 | 13 | VERSION_LOOKUP = { 14 | RAILS_6_1 => %r{^6\.1\.}, 15 | RAILS_6_0 => %r{^6\.0\.}, 16 | RAILS_5_2 => %r{^5\.2\.}, 17 | } 18 | 19 | GEMFILES = { 20 | RAILS_6_1 => GEMFILES_DIR.join("rails_edge.gemfile").to_s, 21 | RAILS_6_0 => GEMFILES_DIR.join("rails60.gemfile").to_s, 22 | RAILS_5_2 => GEMFILES_DIR.join("rails52.gemfile").to_s, 23 | } 24 | 25 | GENERATOR_OPTIONS = ['-q', '-G', '-O', '--skip-bundle'] 26 | 27 | def rails_command(options) 28 | debug cmd = "rails #{options.join(' ')}" 29 | run_command(cmd, GEMFILES[rails_version]) 30 | end 31 | 32 | def rails_version 33 | @rails_version ||= VERSION_LOOKUP.detect { |version, regex| CompassRails.version_match(regex) }.first 34 | end 35 | 36 | # Generate a rails application without polluting our current set of requires 37 | # with the rails libraries. This will allow testing against multiple versions of rails 38 | # by manipulating the load path. 39 | def generate_rails_app(name, options = []) 40 | options += GENERATOR_OPTIONS 41 | rails_command(['new', name, *options]) 42 | end 43 | 44 | def within_rails_app(named, &block) 45 | dir = "#{named}-#{rails_version}" 46 | rm_rf File.join(WORKING_DIR, dir) 47 | mkdir_p WORKING_DIR 48 | cd(WORKING_DIR) do 49 | generate_rails_app(dir, []) 50 | cd(dir) do 51 | yield RailsProject.new(File.join(WORKING_DIR, dir), rails_version) 52 | end 53 | end 54 | rm_rf File.join(WORKING_DIR, dir) unless ENV['DEBUG_COMPILE'] 55 | end 56 | 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /test/helpers/rails_project.rb: -------------------------------------------------------------------------------- 1 | module CompassRails 2 | module Test 3 | class RailsProject 4 | include FileHelper 5 | include DebugHelper 6 | include CommandHelper 7 | include RailsHelpers 8 | include Kernal::Captures 9 | 10 | APPLICATION_FILE = 'config/application.rb' 11 | 12 | attr_reader :directory, :version 13 | 14 | def initialize(directory, version) 15 | @directory = Pathname.new(directory) 16 | @version = version 17 | disable_cookies! if version == '3.1' 18 | end 19 | 20 | ## FILE METHODS 21 | 22 | def to_s 23 | directory_name 24 | end 25 | 26 | def directory_name 27 | File.basename(directory) 28 | end 29 | 30 | def file(path) 31 | directory.join(path) 32 | end 33 | 34 | # RAILS METHODS 35 | 36 | def boots? 37 | rails_property("compass.project_type") == "rails" 38 | end 39 | 40 | def precompile! 41 | run_command("rake assets:precompile", GEMFILES[version]) 42 | end 43 | 44 | def setup_asset_fixtures! 45 | rm_rf file("app/assets") 46 | cp_r CompassRails::Test.root.join('test', 'fixtures', 'assets'), file("app") 47 | end 48 | 49 | def precompiled?(path) 50 | !Dir[asset_path(path)].empty? 51 | end 52 | 53 | def compiled_stylesheet(path, &block) 54 | File.open(asset_path(path)).read.tap do |css| 55 | debug(css) 56 | yield css if block_given? 57 | end 58 | end 59 | 60 | def asset_path(path_pattern) 61 | Dir[file(path_pattern)].first.tap do |asset| 62 | raise 'Asset not found' if asset.nil? 63 | end 64 | end 65 | 66 | def rails_property(key) 67 | rails_command(['runner', "'puts Rails.application.config.#{key}'"]).chomp 68 | end 69 | 70 | def set_rails(property, value) 71 | value = "\n config.#{property} = #{value.inspect}\n" 72 | inject_into_file(directory.join(APPLICATION_FILE), value, :after, 'class Application < Rails::Application') 73 | end 74 | 75 | def disable_cookies! 76 | value = "\n config.middleware.delete 'ActionDispatch::Session::CookieStore'\n" 77 | inject_into_file(directory.join(APPLICATION_FILE), value, :after, 'class Application < Rails::Application') 78 | end 79 | 80 | end 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | require 'compass-rails' 3 | require 'active_support/all' 4 | 5 | module CompassRails 6 | module Test 7 | ROOT_PATH = File.expand_path('../../', __FILE__) 8 | 9 | def self.root 10 | Pathname.new(ROOT_PATH) 11 | end 12 | end 13 | end 14 | 15 | %w(debug file command rails).each do |helper| 16 | require File.join(File.expand_path('../', __FILE__), 'helpers', "#{helper}_helper") 17 | end 18 | 19 | require File.join(File.expand_path('../', __FILE__), 'helpers', "rails_project") 20 | 21 | --------------------------------------------------------------------------------