compass-rails 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +23 -4
  4. data/Appraisals +18 -9
  5. data/CHANGELOG.md +82 -0
  6. data/Gemfile +4 -8
  7. data/README.md +14 -12
  8. data/Rakefile +4 -23
  9. data/compass-rails.gemspec +3 -2
  10. data/gemfiles/rails52.gemfile +20 -0
  11. data/gemfiles/rails60.gemfile +21 -0
  12. data/gemfiles/rails_edge.gemfile +21 -0
  13. data/lib/compass-rails.rb +16 -125
  14. data/lib/compass-rails/patches.rb +0 -3
  15. data/lib/compass-rails/patches/3_1.rb +3 -12
  16. data/lib/compass-rails/patches/4_0.rb +23 -29
  17. data/lib/compass-rails/patches/compass.rb +3 -3
  18. data/lib/compass-rails/patches/importer.rb +10 -12
  19. data/lib/compass-rails/patches/sass_importer.rb +67 -7
  20. data/lib/compass-rails/patches/sprite_importer.rb +4 -4
  21. data/lib/compass-rails/railties.rb +1 -3
  22. data/lib/compass-rails/railties/3_1.rb +5 -12
  23. data/lib/compass-rails/railties/4_0.rb +11 -9
  24. data/lib/compass-rails/version.rb +1 -3
  25. data/test/compass_rails_spec.rb +58 -0
  26. data/test/fixtures/assets/images/letters/a.png +0 -0
  27. data/test/fixtures/assets/images/letters/b.png +0 -0
  28. data/test/fixtures/assets/images/numbers/sprite-1.png +0 -0
  29. data/test/fixtures/assets/images/numbers/sprite-2.png +0 -0
  30. data/test/fixtures/assets/stylesheets/application.css.scss +23 -0
  31. data/test/fixtures/assets/stylesheets/partials/_partial_1.scss +3 -0
  32. data/test/fixtures/assets/stylesheets/partials/_partial_2.scss +3 -0
  33. data/test/helpers/command_helper.rb +2 -15
  34. data/test/helpers/debug_helper.rb +1 -1
  35. data/test/helpers/file_helper.rb +2 -17
  36. data/test/helpers/rails_helper.rb +37 -38
  37. data/test/helpers/rails_project.rb +30 -70
  38. data/test/test_helper.rb +8 -3
  39. metadata +55 -24
  40. data/changelog.markdown +0 -11
  41. data/gemfiles/rails31.gemfile +0 -23
  42. data/gemfiles/rails32.gemfile +0 -23
  43. data/gemfiles/rails40.gemfile +0 -23
  44. data/lib/compass-rails/installer.rb +0 -30
  45. data/test/integrations/.gitkeep +0 -0
  46. data/test/integrations/rails_31_test.rb +0 -46
  47. data/test/integrations/rails_32_test.rb +0 -46
  48. data/test/integrations/rails_40_test.rb +0 -46
  49. data/test/units/.gitkeep +0 -0
@@ -1,6 +1,3 @@
1
1
  if CompassRails.rails31? || CompassRails.rails32?
2
- CompassRails.load_rails
3
2
  require 'compass-rails/patches/importer'
4
- elsif CompassRails.rails4?
5
- CompassRails.load_rails
6
3
  end
@@ -1,17 +1,8 @@
1
1
  require 'compass-rails/patches/compass'
2
2
  require 'compass-rails/patches/static_compiler'
3
3
 
4
- module Sass::Script::Functions
5
- def generated_image_url(path, only_path = nil)
6
- asset_url(path, Sass::Script::String.new("image"))
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
7
  end
8
8
  end
9
-
10
- module Sass::Script::Functions
11
- include Compass::RailsImageFunctionPatch
12
- end
13
-
14
- # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
15
- class Sass::Script::Functions::EvaluationContext
16
- include Sass::Script::Functions
17
- end
@@ -2,44 +2,38 @@ require 'compass-rails/patches/compass'
2
2
  require 'compass-rails/patches/sass_importer'
3
3
  require 'compass-rails/patches/sprite_importer'
4
4
 
5
- module Sass::Script::Functions
6
- def generated_image_url(path, only_path = nil)
7
- pathobject = Pathname.new(path.to_s)
8
- subdirectory = pathobject.dirname.to_s
9
-
10
- cachebust_generated_images(path, subdirectory)
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)
11
8
  asset_url(path)
12
9
  end
13
10
 
14
- def cachebust_generated_images(image_path, subdirectory = nil)
15
- generated_images_path = Rails.root.join(Compass.configuration.generated_images_dir).to_s
16
- if subdirectory.nil?
17
- bust_cache_path = generated_images_path
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)
18
19
  else
19
- bust_cache_path = generated_images_path + "/" + subdirectory
20
+ sprockets_trail = sprockets_env.index
20
21
  end
21
- bust_image_stat_path = generated_images_path + "/" + image_path.to_s
22
22
 
23
- sprockets_entries = options[:sprockets][:environment].send(:trail).instance_variable_get(:@entries)
23
+ sprockets_entries = sprockets_trail.instance_variable_get(:@entries) || {}
24
+ sprockets_stats = sprockets_trail.instance_variable_get(:@stats) || {}
24
25
 
25
- # sprockets_entries.delete(generated_images_path) if sprockets_entries.has_key? generated_images_path
26
- if sprockets_entries.has_key? generated_images_path
27
- # sprockets_entries.delete(generated_images_path)
26
+ if sprockets_entries.key?(generated_images_dir.to_s)
27
+ path = path.value
28
+ dir = File.dirname(path)
28
29
 
29
- # Delete the entries (directories) which cache the files/dirs in a directory
30
- options[:sprockets][:environment].send(:trail).instance_variable_get(:@entries).delete(bust_cache_path)
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)
31
33
 
32
- # Delete the stats (file/dir info) which cache the what kind of file/dir each image is
33
- options[:sprockets][:environment].send(:trail).instance_variable_get(:@stats).delete(bust_image_stat_path)
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)
34
37
  end
35
38
  end
36
39
  end
37
-
38
- module Sass::Script::Functions
39
- include Compass::RailsImageFunctionPatch
40
- end
41
-
42
- # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
43
- class Sass::Script::Functions::EvaluationContext
44
- include Sass::Script::Functions
45
- end
@@ -1,10 +1,10 @@
1
- module Compass::RailsImageFunctionPatch
1
+ Compass::Core::SassExtensions::Functions::ImageSize.class_eval do
2
2
  private
3
3
 
4
4
  def image_path_for_size(image_file)
5
5
  begin
6
- file = ::Rails.application.assets.find_asset(image_file)
7
- return file
6
+ file = ::CompassRails.sprockets.find_asset(image_file)
7
+ return (file.respond_to?(:pathname) ? file.pathname.to_s : file)
8
8
  rescue ::Sprockets::FileOutsidePaths
9
9
  return super(image_file)
10
10
  end
@@ -4,18 +4,16 @@ module Compass
4
4
  attr_accessor :sass_options
5
5
  STYLESHEET = /stylesheet/
6
6
  def sass_options
7
- if CompassRails.asset_pipeline_enabled?
8
- @sass_options[:custom] ||= {}
9
- @sass_options[:custom] = {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)}
10
- @sass_options[:load_paths] ||= []
11
- unless @sass_options[:load_paths].any? {|k| k.is_a?(::Sass::Rails::Importer) }
12
- ::Rails.application.assets.paths.each do |path|
13
- next unless path.to_s =~ STYLESHEET
14
- Dir["#{path}/**/*"].each do |pathname|
15
- # args are: sprockets environment, the logical_path ex. 'stylesheets', and the full path name for the render
16
- context = ::CompassRails.context.new(::Rails.application.assets, File.basename(path), Pathname.new(pathname))
17
- @sass_options[:load_paths] << ::Sass::Rails::Importer.new(context)
18
- end
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)
19
17
  end
20
18
  end
21
19
  end
@@ -7,18 +7,23 @@ end
7
7
  klass.class_eval do
8
8
  def evaluate(context, locals, &block)
9
9
  # Use custom importer that knows about Sprockets Caching
10
- cache_store = Sprockets::SassCacheStore.new(context.environment)
11
- paths = context.environment.paths.map { |path| CompassRails::SpriteImporter.new(context, path) }
12
- paths += context.environment.paths.map { |path| self.class.parent::SassImporter.new(context, path) }
13
- paths += ::Rails.application.config.sass.load_paths
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
14
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
15
20
 
16
21
  options = CompassRails.sass_config.merge( {
17
22
  :filename => eval_file,
18
23
  :line => line,
19
24
  :syntax => syntax,
20
25
  :cache_store => cache_store,
21
- :importer => self.class.parent::SassImporter.new(context, context.pathname),
26
+ :importer => sass_importer(context, context.pathname),
22
27
  :load_paths => paths,
23
28
  :sprockets => {
24
29
  :context => context,
@@ -26,11 +31,66 @@ klass.class_eval do
26
31
  }
27
32
  })
28
33
 
29
- ::Sass::Engine.new(data, options).render
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
30
49
  rescue ::Sass::SyntaxError => e
31
50
  # Annotates exception message with parse line number
32
51
  context.__LINE__ = e.sass_backtrace.first[:line]
33
52
  raise e
34
53
  end
35
- end
36
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
@@ -3,19 +3,19 @@ require 'compass/sprite_importer'
3
3
 
4
4
  module CompassRails
5
5
  class SpriteImporter < Compass::SpriteImporter
6
- attr_reader :context, :root
6
+ attr_reader :root
7
7
 
8
- def initialize(context, root)
9
- @context = context
8
+ def initialize(root)
10
9
  @root = root
11
10
  end
12
11
 
13
12
  def find(uri, options)
14
13
  if old = super(uri, options)
14
+ context = options[:sprockets][:context]
15
15
  self.class.files(uri).each do |file|
16
16
  relative_path = Pathname.new(file).relative_path_from(Pathname.new(root))
17
17
  begin
18
- pathname = context.resolve(relative_path)
18
+ pathname = context.resolve(relative_path.to_s)
19
19
  context.depend_on_asset(pathname)
20
20
  rescue Sprockets::FileNotFound
21
21
 
@@ -1,9 +1,7 @@
1
1
  if defined?(::Rails)
2
2
  if CompassRails.rails31? || CompassRails.rails32?
3
3
  require "compass-rails/railties/3_1"
4
- elsif CompassRails.rails4?
5
- require "compass-rails/railties/4_0"
6
4
  else
7
- $stderr.puts "Unsupported rails environment for compass"
5
+ require "compass-rails/railties/4_0"
8
6
  end
9
7
  end
@@ -3,16 +3,9 @@ module CompassRails
3
3
 
4
4
  initializer "compass.initialize_rails", :group => :all do |app|
5
5
  require 'compass'
6
- if CompassRails.asset_pipeline_enabled?
7
- require 'compass-rails/patches/3_1'
8
- # Configure compass for use within rails, and provide the project configuration
9
- # that came via the rails boot process.
10
- CompassRails.check_for_double_boot!
11
- Compass.discover_extensions!
12
- CompassRails.configure_rails!(app)
13
- else
14
- CompassRails.initialize!(app.config.compass)
15
- end
6
+ require 'compass-rails/patches/3_1'
7
+ Compass.discover_extensions!
8
+ CompassRails.configure_rails!(app)
16
9
  end
17
10
 
18
11
  config.compass = begin
@@ -32,11 +25,11 @@ module CompassRails
32
25
 
33
26
  # Clear entries in Hike::Index for this sprite's directory.
34
27
  # This makes sure the asset can be found by find_assets
35
- Rails.application.assets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename))
28
+ CompassRails.sprockets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename))
36
29
 
37
30
  pathname = Pathname.new(filename)
38
31
  logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path))
39
- asset = Rails.application.assets.find_asset(logical_path)
32
+ asset = CompassRails.sprockets.find_asset(logical_path)
40
33
  target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path)
41
34
 
42
35
  # Adds the asset to the manifest file.
@@ -4,9 +4,6 @@ module CompassRails
4
4
  initializer "compass.initialize_rails", :group => :all do |app|
5
5
  require 'compass'
6
6
  require 'compass-rails/patches/4_0'
7
- # Configure compass for use within rails, and provide the project configuration
8
- # that came via the rails boot process.
9
- CompassRails.check_for_double_boot!
10
7
  Compass.discover_extensions!
11
8
  CompassRails.configure_rails!(app)
12
9
  end
@@ -28,19 +25,24 @@ module CompassRails
28
25
 
29
26
  # Clear entries in Hike::Index for this sprite's directory.
30
27
  # This makes sure the asset can be found by find_assets
31
- trail = Rails.application.assets.send(:trail)
32
- trail.instance_variable_get(:@entries).delete(File.dirname(filename))
33
- trail.instance_variable_get(:@stats).delete(filename)
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)
34
36
 
35
37
  pathname = Pathname.new(filename)
36
- logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path))
37
- asset = Rails.application.assets.find_asset(logical_path)
38
+ logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path)).to_s
39
+ asset = CompassRails.sprockets.find_asset(logical_path)
38
40
  target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path)
39
41
 
40
42
  # Adds the asset to the manifest file.
41
43
 
42
44
  manifest = ActionView::Base.assets_manifest
43
- manifest.assets[logical_path.to_s] = asset.digest_path
45
+ manifest.assets[logical_path] = asset.digest_path
44
46
 
45
47
 
46
48
  # Adds the fingerprinted asset to the public directory
@@ -1,5 +1,3 @@
1
1
  module CompassRails
2
- unless defined?(::CompassRails::VERSION)
3
- VERSION = "2.0.0"
4
- end
2
+ VERSION = '4.0.0' unless defined?(::CompassRails::VERSION)
5
3
  end
@@ -0,0 +1,58 @@
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
@@ -0,0 +1,23 @@
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
+ }