sprockets-sass 1.3.1 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.reek +12 -0
  3. data/.rubocop.yml +77 -0
  4. data/.travis.yml +16 -0
  5. data/Appraisals +32 -15
  6. data/Gemfile +5 -0
  7. data/README.md +41 -4
  8. data/Rakefile +15 -3
  9. data/gemfiles/compass_0.11.gemfile +1 -1
  10. data/gemfiles/sass_3.1.gemfile +1 -1
  11. data/gemfiles/sass_3.3.gemfile +8 -0
  12. data/gemfiles/sass_3.4.gemfile +8 -0
  13. data/gemfiles/sprockets_2.10.gemfile +1 -1
  14. data/gemfiles/sprockets_2.11.gemfile +1 -1
  15. data/gemfiles/sprockets_2.2.gemfile +1 -1
  16. data/gemfiles/sprockets_2.3.gemfile +1 -1
  17. data/gemfiles/sprockets_2.4.gemfile +1 -1
  18. data/gemfiles/sprockets_2.5.gemfile +1 -1
  19. data/gemfiles/sprockets_2.6.gemfile +1 -1
  20. data/gemfiles/sprockets_2.7.gemfile +1 -1
  21. data/gemfiles/sprockets_2.8.gemfile +1 -1
  22. data/gemfiles/sprockets_2.9.gemfile +1 -1
  23. data/gemfiles/sprockets_3.7.gemfile +9 -0
  24. data/gemfiles/sprockets_4.0.gemfile +10 -0
  25. data/gemfiles/sprockets_4.0_beta2.gemfile +9 -0
  26. data/lib/sprockets-sass.rb +1 -0
  27. data/lib/sprockets/sass.rb +37 -12
  28. data/lib/sprockets/sass/functions.rb +24 -159
  29. data/lib/sprockets/sass/registration.rb +126 -0
  30. data/lib/sprockets/sass/utils.rb +115 -0
  31. data/lib/sprockets/sass/v2/cache_store.rb +26 -0
  32. data/lib/sprockets/sass/v2/compressor.rb +31 -0
  33. data/lib/sprockets/sass/v2/functions.rb +142 -0
  34. data/lib/sprockets/sass/v2/importer.rb +209 -0
  35. data/lib/sprockets/sass/v2/sass_template.rb +221 -0
  36. data/lib/sprockets/sass/v2/scss_template.rb +14 -0
  37. data/lib/sprockets/sass/v3/cache_store.rb +28 -0
  38. data/lib/sprockets/sass/v3/compressor.rb +97 -0
  39. data/lib/sprockets/sass/v3/functions.rb +12 -0
  40. data/lib/sprockets/sass/v3/importer.rb +212 -0
  41. data/lib/sprockets/sass/v3/sass_template.rb +37 -0
  42. data/lib/sprockets/sass/v3/scss_template.rb +15 -0
  43. data/lib/sprockets/sass/v4/cache_store.rb +11 -0
  44. data/lib/sprockets/sass/v4/compressor.rb +11 -0
  45. data/lib/sprockets/sass/v4/functions.rb +12 -0
  46. data/lib/sprockets/sass/v4/importer.rb +105 -0
  47. data/lib/sprockets/sass/v4/sass_template.rb +27 -0
  48. data/lib/sprockets/sass/v4/scss_template.rb +16 -0
  49. data/lib/sprockets/sass/version.rb +2 -1
  50. data/spec/custom_importer_spec.rb +4 -6
  51. data/spec/spec_helper.rb +30 -3
  52. data/spec/sprockets-sass_spec.rb +101 -61
  53. data/spec/support/be_fresh_matcher.rb +10 -6
  54. data/spec/support/dummy_importer.rb +1 -1
  55. data/spec/support/fail_postprocessor.rb +23 -0
  56. data/spec/support/sass_template.rb +11 -0
  57. data/sprockets-sass.gemspec +27 -8
  58. metadata +92 -95
  59. data/gemfiles/compass_0.12.gemfile +0 -7
  60. data/gemfiles/sass_3.2.gemfile +0 -7
  61. data/gemfiles/sprockets_2.0.gemfile +0 -7
  62. data/gemfiles/sprockets_2.1.gemfile +0 -9
  63. data/lib/sprockets/sass/cache_store.rb +0 -27
  64. data/lib/sprockets/sass/compressor.rb +0 -22
  65. data/lib/sprockets/sass/importer.rb +0 -142
  66. data/lib/sprockets/sass/sass_template.rb +0 -115
  67. data/lib/sprockets/sass/scss_template.rb +0 -12
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "compass", "~> 0.12.0"
6
-
7
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "sass", "~> 3.2.0"
6
-
7
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "sprockets", "~> 2.0.0"
6
-
7
- gemspec :path=>"../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "sprockets", "~> 2.1.0"
6
- gem "sass", "~> 3.2.0"
7
- gem "compass", "~> 0.12.0"
8
-
9
- gemspec :path=>"../"
@@ -1,27 +0,0 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- module Sass
5
- class CacheStore < ::Sass::CacheStores::Base
6
- attr_reader :environment
7
-
8
- def initialize(environment)
9
- @environment = environment
10
- end
11
-
12
- def _store(key, version, sha, contents)
13
- environment.send :cache_set, "sass/#{key}", { :version => version, :sha => sha, :contents => contents }
14
- end
15
-
16
- def _retrieve(key, version, sha)
17
- if obj = environment.send(:cache_get, "sass/#{key}")
18
- return unless obj[:version] == version
19
- return unless obj[:sha] == sha
20
- obj[:obj]
21
- else
22
- nil
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- module Sass
5
- class Compressor
6
- # Compresses the given CSS using Sass::Engine's
7
- # :compressed output style.
8
- def compress(css)
9
- if css.count("\n") > 2
10
- ::Sass::Engine.new(css,
11
- :syntax => :scss,
12
- :cache => false,
13
- :read_cache => false,
14
- :style => :compressed
15
- ).render
16
- else
17
- css
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,142 +0,0 @@
1
- require 'sass/importers/base'
2
- require 'pathname'
3
-
4
- module Sprockets
5
- module Sass
6
- class Importer < ::Sass::Importers::Base
7
- GLOB = /\*|\[.+\]/
8
-
9
- # @see Sass::Importers::Base#find_relative
10
- def find_relative(path, base_path, options)
11
- if path =~ GLOB
12
- engine_from_glob(path, base_path, options)
13
- else
14
- engine_from_path(path, base_path, options)
15
- end
16
- end
17
-
18
- # @see Sass::Importers::Base#find
19
- def find(path, options)
20
- engine_from_path(path, nil, options)
21
- end
22
-
23
- # @see Sass::Importers::Base#mtime
24
- def mtime(path, options)
25
- if pathname = resolve(path)
26
- pathname.mtime
27
- end
28
- rescue Errno::ENOENT
29
- nil
30
- end
31
-
32
- # @see Sass::Importers::Base#key
33
- def key(path, options)
34
- path = Pathname.new(path)
35
- ["#{self.class.name}:#{path.dirname.expand_path}", path.basename]
36
- end
37
-
38
- # @see Sass::Importers::Base#to_s
39
- def to_s
40
- "#{self.class.name}:#{context.pathname}"
41
- end
42
-
43
- protected
44
-
45
- # Create a Sass::Engine from the given path.
46
- def engine_from_path(path, base_path, options)
47
- context = options[:custom][:sprockets_context]
48
- pathname = resolve(context, path, base_path) or return nil
49
- context.depend_on pathname
50
- ::Sass::Engine.new evaluate(context, pathname), options.merge(
51
- :filename => pathname.to_s,
52
- :syntax => syntax(pathname),
53
- :importer => self
54
- )
55
- end
56
-
57
- # Create a Sass::Engine that will handle importing
58
- # a glob of files.
59
- def engine_from_glob(glob, base_path, options)
60
- context = options[:custom][:sprockets_context]
61
- imports = resolve_glob(context, glob, base_path).inject('') do |imports, path|
62
- context.depend_on path
63
- relative_path = path.relative_path_from Pathname.new(base_path).dirname
64
- imports << %(@import "#{relative_path}";\n)
65
- end
66
- return nil if imports.empty?
67
- ::Sass::Engine.new imports, options.merge(
68
- :filename => base_path.to_s,
69
- :syntax => :scss,
70
- :importer => self
71
- )
72
- end
73
-
74
- # Finds an asset from the given path. This is where
75
- # we make Sprockets behave like Sass, and import partial
76
- # style paths.
77
- def resolve(context, path, base_path)
78
- possible_files(context, path, base_path).each do |file|
79
- context.resolve(file) { |found| return found if context.asset_requirable?(found) }
80
- end
81
-
82
- nil
83
- end
84
-
85
- # Finds all of the assets using the given glob.
86
- def resolve_glob(context, glob, base_path)
87
- base_path = Pathname.new(base_path)
88
- path_with_glob = base_path.dirname.join(glob).to_s
89
-
90
- Pathname.glob(path_with_glob).sort.select do |path|
91
- path != context.pathname && context.asset_requirable?(path)
92
- end
93
- end
94
-
95
- # Returns all of the possible paths (including partial variations)
96
- # to attempt to resolve with the given path.
97
- def possible_files(context, path, base_path)
98
- path = Pathname.new(path)
99
- base_path = Pathname.new(base_path).dirname
100
- paths = [ path, partialize_path(path) ]
101
-
102
- # Find base_path's root
103
- env_root_paths = context.environment.paths.map {|p| Pathname.new(p) }
104
- root_path = env_root_paths.detect do |env_root_path|
105
- base_path.to_s.start_with?(env_root_path.to_s)
106
- end
107
- root_path ||= Pathname.new(context.root_path)
108
-
109
- # Add the relative path from the root, if necessary
110
- if path.relative? && base_path != root_path
111
- relative_path = base_path.relative_path_from(root_path).join path
112
- paths.unshift(relative_path, partialize_path(relative_path))
113
- end
114
-
115
- paths.compact
116
- end
117
-
118
- # Returns the partialized version of the given path.
119
- # Returns nil if the path is already to a partial.
120
- def partialize_path(path)
121
- if path.basename.to_s !~ /\A_/
122
- Pathname.new path.to_s.sub(/([^\/]+)\Z/, '_\1')
123
- end
124
- end
125
-
126
- # Returns the Sass syntax of the given path.
127
- def syntax(path)
128
- path.to_s.include?('.sass') ? :sass : :scss
129
- end
130
-
131
- # Returns the string to be passed to the Sass engine. We use
132
- # Sprockets to process the file, but we remove any Sass processors
133
- # because we need to let the Sass::Engine handle that.
134
- def evaluate(context, path)
135
- attributes = context.environment.attributes_for(path)
136
- processors = context.environment.preprocessors(attributes.content_type) + attributes.engines.reverse
137
- processors.delete_if { |processor| processor < Tilt::SassTemplate }
138
- context.evaluate(path, :processors => processors)
139
- end
140
- end
141
- end
142
- end
@@ -1,115 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- module Sass
5
- class SassTemplate < Tilt::SassTemplate
6
- self.default_mime_type = 'text/css'
7
-
8
- # A reference to the current Sprockets context
9
- attr_reader :context
10
-
11
- # Determines if the Sass functions have been initialized.
12
- # They can be 'initialized' without actually being added.
13
- @sass_functions_initialized = false
14
- class << self
15
- attr_accessor :sass_functions_initialized
16
- alias :sass_functions_initialized? :sass_functions_initialized
17
-
18
- # Templates are initialized once the functions are added.
19
- def engine_initialized?
20
- super && sass_functions_initialized?
21
- end
22
- end
23
-
24
- # Add the Sass functions if they haven't already been added.
25
- def initialize_engine
26
- super unless self.class.superclass.engine_initialized?
27
-
28
- if Sass.add_sass_functions != false
29
- begin
30
- require 'sprockets/helpers'
31
- require 'sprockets/sass/functions'
32
- rescue LoadError; end
33
- end
34
-
35
- self.class.sass_functions_initialized = true
36
- end
37
-
38
- # Define the expected syntax for the template
39
- def syntax
40
- :sass
41
- end
42
-
43
- # See `Tilt::Template#prepare`.
44
- def prepare
45
- @context = nil
46
- @output = nil
47
- end
48
-
49
- # See `Tilt::Template#evaluate`.
50
- def evaluate(context, locals, &block)
51
- @output ||= begin
52
- @context = context
53
- ::Sass::Engine.new(data, sass_options).render
54
- rescue ::Sass::SyntaxError => e
55
- # Annotates exception message with parse line number
56
- context.__LINE__ = e.sass_backtrace.first[:line]
57
- raise e
58
- end
59
- end
60
-
61
- protected
62
-
63
- # Returns a Sprockets-aware cache store for Sass::Engine.
64
- def cache_store
65
- return nil if context.environment.cache.nil?
66
-
67
- if defined?(Sprockets::SassCacheStore)
68
- Sprockets::SassCacheStore.new context.environment
69
- else
70
- CacheStore.new context.environment
71
- end
72
- end
73
-
74
- # Assemble the options for the `Sass::Engine`
75
- def sass_options
76
- # Allow the use of custom SASS importers, making sure the
77
- # custom importer is a `Sprockets::Sass::Importer`
78
- if default_sass_options.has_key?(:importer) &&
79
- default_sass_options[:importer].is_a?(Importer)
80
- importer = default_sass_options[:importer]
81
- else
82
- importer = Importer.new
83
- end
84
-
85
- merge_sass_options(default_sass_options, options).merge(
86
- :filename => eval_file,
87
- :line => line,
88
- :syntax => syntax,
89
- :cache_store => cache_store,
90
- :importer => importer,
91
- :custom => { :sprockets_context => context }
92
- )
93
- end
94
-
95
- # Get the default, global Sass options. Start with Compass's
96
- # options, if it's available.
97
- def default_sass_options
98
- if defined?(Compass)
99
- merge_sass_options Compass.sass_engine_options.dup, Sprockets::Sass.options
100
- else
101
- Sprockets::Sass.options.dup
102
- end
103
- end
104
-
105
- # Merges two sets of `Sass::Engine` options, prepending
106
- # the `:load_paths` instead of clobbering them.
107
- def merge_sass_options(options, other_options)
108
- if (load_paths = options[:load_paths]) && (other_paths = other_options[:load_paths])
109
- other_options[:load_paths] = other_paths + load_paths
110
- end
111
- options.merge other_options
112
- end
113
- end
114
- end
115
- end
@@ -1,12 +0,0 @@
1
- module Sprockets
2
- module Sass
3
- class ScssTemplate < SassTemplate
4
- self.default_mime_type = 'text/css'
5
-
6
- # Define the expected syntax for the template
7
- def syntax
8
- :scss
9
- end
10
- end
11
- end
12
- end