sassc4-rails 2.1.2

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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +37 -0
  4. data/CODE_OF_CONDUCT.md +10 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +124 -0
  8. data/Rakefile +33 -0
  9. data/gemfiles/rails_4_2.gemfile +6 -0
  10. data/gemfiles/rails_5_2.gemfile +6 -0
  11. data/gemfiles/rails_6_0.gemfile +6 -0
  12. data/gemfiles/sprockets-rails_2_3.gemfile +6 -0
  13. data/gemfiles/sprockets-rails_3_0.gemfile +6 -0
  14. data/gemfiles/sprockets_3_0.gemfile +6 -0
  15. data/gemfiles/sprockets_4_0.gemfile +6 -0
  16. data/lib/rails/generators/sass/assets/assets_generator.rb +13 -0
  17. data/lib/rails/generators/sass/assets/templates/stylesheet.sass +3 -0
  18. data/lib/rails/generators/sass/scaffold/scaffold_generator.rb +9 -0
  19. data/lib/rails/generators/sass_scaffold.rb +15 -0
  20. data/lib/rails/generators/scss/assets/assets_generator.rb +13 -0
  21. data/lib/rails/generators/scss/assets/templates/stylesheet.scss +3 -0
  22. data/lib/rails/generators/scss/scaffold/scaffold_generator.rb +10 -0
  23. data/lib/sassc/rails/compressor.rb +34 -0
  24. data/lib/sassc/rails/functions.rb +13 -0
  25. data/lib/sassc/rails/importer.rb +181 -0
  26. data/lib/sassc/rails/railtie.rb +81 -0
  27. data/lib/sassc/rails/template.rb +113 -0
  28. data/lib/sassc/rails/version.rb +7 -0
  29. data/lib/sassc/rails.rb +10 -0
  30. data/lib/sassc-rails.rb +4 -0
  31. data/sassc-rails.gemspec +32 -0
  32. data/test/dummy/app/assets/config/manifest.js +3 -0
  33. data/test/dummy/app/assets/fonts/fake-font.ttf +0 -0
  34. data/test/dummy/app/assets/images/.keep +0 -0
  35. data/test/dummy/app/assets/images/1x1.png +0 -0
  36. data/test/dummy/app/assets/images/rails.png +0 -0
  37. data/test/dummy/app/assets/stylesheets/_top_level_partial.scss +3 -0
  38. data/test/dummy/app/assets/stylesheets/application.scss +5 -0
  39. data/test/dummy/app/assets/stylesheets/css_application.css +11 -0
  40. data/test/dummy/app/assets/stylesheets/css_erb_handler.css.erb +3 -0
  41. data/test/dummy/app/assets/stylesheets/css_sass_erb_handler.sass.erb +2 -0
  42. data/test/dummy/app/assets/stylesheets/css_sass_handler.css.sass +2 -0
  43. data/test/dummy/app/assets/stylesheets/css_scss_erb_handler.scss.erb +3 -0
  44. data/test/dummy/app/assets/stylesheets/css_scss_handler.css.scss +3 -0
  45. data/test/dummy/app/assets/stylesheets/erb_render_with_context.css.erb +1804 -0
  46. data/test/dummy/app/assets/stylesheets/glob_multiple_extensions_test.scss +1 -0
  47. data/test/dummy/app/assets/stylesheets/glob_test.scss +1 -0
  48. data/test/dummy/app/assets/stylesheets/globbed/globbed.scss +3 -0
  49. data/test/dummy/app/assets/stylesheets/globbed/nested/nested_glob.scss +3 -0
  50. data/test/dummy/app/assets/stylesheets/globbed_multiple_extensions/glob.scss.erb +3 -0
  51. data/test/dummy/app/assets/stylesheets/helpers_test.scss +18 -0
  52. data/test/dummy/app/assets/stylesheets/imports_test.scss +23 -0
  53. data/test/dummy/app/assets/stylesheets/in_load_paths/partial_in_load_paths.scss +3 -0
  54. data/test/dummy/app/assets/stylesheets/partials/_css_sass_import.sass +5 -0
  55. data/test/dummy/app/assets/stylesheets/partials/_explicit_extension_import.foo +3 -0
  56. data/test/dummy/app/assets/stylesheets/partials/_sass_import.sass +2 -0
  57. data/test/dummy/app/assets/stylesheets/partials/_scss_import.scss +9 -0
  58. data/test/dummy/app/assets/stylesheets/partials/_without_css_ext.scss +3 -0
  59. data/test/dummy/app/assets/stylesheets/partials/subfolder/_relative_sass.sass +2 -0
  60. data/test/dummy/app/assets/stylesheets/partials/subfolder/_relative_scss.scss +3 -0
  61. data/test/dummy/app/assets/stylesheets/partials/subfolder/relative_not_a_partial.scss +3 -0
  62. data/test/dummy/app/assets/stylesheets/sass_erb_handler.sass.erb +2 -0
  63. data/test/dummy/app/assets/stylesheets/scss_erb_handler.scss.erb +3 -0
  64. data/test/dummy/app/assets/stylesheets/special_characters.scss +5 -0
  65. data/test/dummy/app/assets/stylesheets/subfolder/_defaults.scss +3 -0
  66. data/test/dummy/app/assets/stylesheets/subfolder/another_plain.css +3 -0
  67. data/test/dummy/app/assets/stylesheets/subfolder/plain.css +3 -0
  68. data/test/dummy/app/assets/stylesheets/subfolder/second_level.scss +2 -0
  69. data/test/dummy/app/assets/stylesheets/syntax_error.scss +3 -0
  70. data/test/sassc_rails_test.rb +334 -0
  71. data/test/test_helper.rb +17 -0
  72. metadata +281 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1771885cbf045c698354196442579b9f125b5bb8009d20335df9e1681006a91e
4
+ data.tar.gz: 235c0a490ec30b20e4fd351abbeda80b6fa39c9f064e187e87312b78dd6054a0
5
+ SHA512:
6
+ metadata.gz: bcd2ba5b9378a8278677158202ae4bbfe465230496771db8759f8f7088572a962de1c4f5cf761b4d2c9ebeede58c2656d3925728792c7b8da1cb4d24c8dab691
7
+ data.tar.gz: 46b5d8782fd009344c8be8bcbbc114ac7b086e1639193a173e966f4a7cf02133fc0dd5796fbdfd077dfa7a8f4568163fd597a17b418a97616b9b13824c8de48c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /gemfiles/*.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ vendor
17
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,37 @@
1
+ language: ruby
2
+
3
+ bundler_args: "--binstubs --standalone --without documentation --path ../bundle"
4
+
5
+ script: "bundle exec rake test"
6
+
7
+ before_install:
8
+ - rvm @global do gem uninstall bundler -x
9
+ - gem install bundler --version '< 2'
10
+
11
+ gemfile:
12
+ - gemfiles/sprockets-rails_3_0.gemfile
13
+ - gemfiles/sprockets-rails_2_3.gemfile
14
+ - gemfiles/sprockets_3_0.gemfile
15
+ - gemfiles/sprockets_4_0.gemfile
16
+ - gemfiles/rails_4_2.gemfile
17
+ - gemfiles/rails_5_2.gemfile
18
+ - gemfiles/rails_6_0.gemfile
19
+
20
+ rvm:
21
+ - 2.4.6
22
+ - 2.5.5
23
+ - 2.6.3
24
+ - jruby
25
+
26
+ matrix:
27
+ allow_failures:
28
+ - gemfile: gemfiles/rails_4_2.gemfile
29
+ rvm: jruby
30
+ - gemfile: gemfiles/rails_6_0.gemfile
31
+ rvm: jruby
32
+ exclude:
33
+ - gemfile: gemfiles/rails_6_0.gemfile
34
+ rvm: 2.4.6
35
+
36
+ notifications:
37
+ email: false
@@ -0,0 +1,10 @@
1
+ Sass is more than a technology; Sass is driven by the community of individuals
2
+ that power its development and use every day. As a community, we want to embrace
3
+ the very differences that have made our collaboration so powerful, and work
4
+ together to provide the best environment for learning, growing, and sharing of
5
+ ideas. It is imperative that we keep Sass a fun, welcoming, challenging, and
6
+ fair place to play.
7
+
8
+ [The full community guidelines can be found on the Sass website.][link]
9
+
10
+ [link]: https://sass-lang.com/community-guidelines
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # for working locally
4
+ # gem "sassc4", :path => "../sassc4"
5
+
6
+ # Specify your gem's dependencies in sassc-rails.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ryan Boland
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.
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # SassC::Rails [![Build Status](https://travis-ci.org/sass/sassc-rails.svg)](https://travis-ci.org/sass/sassc-rails) [![Gem Version](https://badge.fury.io/rb/sassc-rails.svg)](http://badge.fury.io/rb/sassc-rails)
2
+
3
+ We all love working with Sass, but compilation can take quite a long time for larger
4
+ codebases. This gem integrates the C implementation of Sass,
5
+ [LibSass](https://github.com/sass/libsass), into the asset pipeline.
6
+
7
+ In one larger project, this made compilation 4x faster:
8
+
9
+ ```
10
+ # Using sassc-rails
11
+
12
+ [1] pry(main)> Benchmark.bm { |bm| bm.report { Rails.application.assets["application.css"] } }
13
+ user system total real
14
+ 1.720000 0.170000 1.890000 ( 1.936867)
15
+
16
+ # Using sass-rails
17
+
18
+ [1] pry(main)> Benchmark.bm { |bm| bm.report { Rails.application.assets["application.css"] } }
19
+ user system total real
20
+ 7.820000 0.250000 8.070000 ( 8.106347)
21
+ ```
22
+
23
+ This should essentially be a drop in alternative to [sass-rails](https://github.com/rails/sass-rails).
24
+
25
+ ## Inline Source Maps
26
+
27
+ With SassC-Rails, it's also extremely easy to turn on inline source maps. Simply
28
+ add the following configuration to your development.rb file:
29
+
30
+ ```ruby
31
+ # config/environments/development.rb
32
+ config.sass.inline_source_maps = true
33
+ ```
34
+
35
+ After adding this config line, you may need to clear your assets cache
36
+ (`rm -r tmp/cache/assets`), stop spring, and restart your rails server. You may
37
+ also wish to disable line comments (`config.sass.line_comments = false`).
38
+
39
+ Note, as indicated, these source maps are *inline*. They will not generate additional
40
+ files or anything like that. Instead, they will be appended to the compiled
41
+ application.css file.
42
+
43
+ ## LibSass Compatibility With Ruby Sass
44
+
45
+ For a look at the compatibility between Ruby Sass and LibSass, check this
46
+ [compatibility chart](http://sass-compatibility.github.io/) out.
47
+
48
+
49
+ ## Installation
50
+
51
+ Add this line to your application's Gemfile:
52
+
53
+ ```ruby
54
+ gem 'sassc-rails'
55
+ ```
56
+
57
+ And then execute:
58
+
59
+ $ bundle
60
+
61
+ ## Common Issues
62
+
63
+ ### Deployment to Heroku
64
+
65
+ Due to LibSass compilation requirements, you must upgrade to the
66
+ [Heroku Cedar-14 Stack](https://devcenter.heroku.com/articles/cedar-14-migration)
67
+ in order to successfully install this gem.
68
+
69
+ Upgrading to Cedar-14 is usually a painless process.
70
+
71
+
72
+ ### Installing alongside a gem that depends on Sass-Rails
73
+
74
+ Libraries explicitly depending on Sass-Rails, such as ActiveAdmin, can cause
75
+ conflicts with installation of SassC-Rails. While we have no built-in solution
76
+ for this, please check out [this issue](https://github.com/sass/sassc-rails/issues/6)
77
+ for a workaround.
78
+
79
+
80
+ ## Credits
81
+
82
+ This gem is based on [sass-rails](https://github.com/rails/sass-rails), and
83
+ is maintained by [Ryan Boland](https://ryanboland.com) and [awesome contributors](https://github.com/sass/sassc-rails/graphs/contributors).
84
+
85
+
86
+ ## Changelog
87
+
88
+ - **2.1.2**
89
+ - [Correct reference to SassC::Script::Value::String](https://github.com/sass/sassc-rails/pull/129)
90
+ - **2.1.1**
91
+ - [Fix Scaffolding](https://github.com/sass/sassc-rails/pull/119)
92
+ - **2.1.0**
93
+ - [JRuby support](https://github.com/sass/sassc-rails/pull/113)
94
+ - [SCSS / SASS scaffolding](https://github.com/sass/sassc-rails/pull/112)
95
+ - **2.0.0**
96
+ - [Drop support for Sprockets 2](https://github.com/sass/sassc-rails/pull/109)
97
+ - [Remove dependency on Ruby Sass](https://github.com/sass/sassc-rails/pull/109)
98
+ - **1.3.0**
99
+ - [Silence Sprockets deprecation warnings](https://github.com/sass/sassc-rails/pull/76)
100
+ - [Sprockets 4 compatibility](https://github.com/sass/sassc-rails/pull/65)
101
+ - **1.2.1**
102
+ - Bump SassC (and thus LibSass) version
103
+ - **1.2.0**
104
+ - [Support sprockets-rails 3](https://github.com/sass/sassc-rails/pull/41)
105
+ - [Only depend on Railties instead of full Rails](https://github.com/sass/sassc-rails/pull/52)
106
+ - **1.1.0**
107
+ - Moved under the official sass organization!
108
+ - [Source line comments](https://github.com/sass/sassc-rails/pull/24) (`app.config.sass.line_comments`)
109
+ - [Prevent sass-rails railtie from running](https://github.com/sass/sassc-rails/pull/34)
110
+ - [CSS compression may be disabled in test mode](https://github.com/sass/sassc-rails/issues/33). Special thanks to [this Sass-Rails PR](https://github.com/rails/sass-rails/pull/338) for inspiration.
111
+ - **1.0.0**
112
+ - Initial Release
113
+ - Add support for inline source maps
114
+ - Support compression in the way that Sass-Rails handles it
115
+
116
+
117
+ ## Contributing
118
+
119
+ 1. Fork it ( https://github.com/sass/sassc-rails/fork )
120
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
121
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
122
+ 1. Add Tests
123
+ 1. Push to the branch (`git push origin my-new-feature`)
124
+ 1. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ $LOAD_PATH.unshift('lib', 'test')
5
+ Dir.glob('./test/**/*_test.rb') { |f| require f }
6
+ end
7
+ task :default => [:test]
8
+
9
+ namespace :tests do
10
+ gemfiles = %w[
11
+ sprockets-rails_3_0
12
+ sprockets-rails_2_3
13
+ sprockets_3_0
14
+ sprockets_4_0
15
+ rails_4_2
16
+ rails_5_2
17
+ ]
18
+
19
+ gemfiles.each do |gemfile|
20
+ desc "Run tests against #{gemfile}"
21
+ task gemfile do
22
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install"
23
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake test"
24
+ end
25
+ end
26
+
27
+ desc "Run tests against all common asset pipeline setups"
28
+ task :all do
29
+ gemfiles.each do |gemfile|
30
+ Rake::Task["tests:#{gemfile}"].invoke
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 4.2.0"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 5.2.1"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 6.0.a"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "sprockets-rails", "~> 2.3.3"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "sprockets-rails", "~> 3.2"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "sprockets", "~> 3.7"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "sprockets", "~> 4.0.x"
4
+
5
+ # Specify your gem's dependencies in sassc-rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Sass
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_sass
9
+ template "stylesheet.sass", File.join('app/assets/stylesheets', class_path, "#{file_name}.sass")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the <%= name %> controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass here: https://sass-lang.com/
@@ -0,0 +1,9 @@
1
+ require "rails/generators/sass_scaffold"
2
+
3
+ module Sass
4
+ module Generators
5
+ class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
6
+ def syntax() :sass end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require "sassc/engine"
2
+ require "rails/generators/named_base"
3
+
4
+ module Sass
5
+ module Generators
6
+ class ScaffoldBase < ::Rails::Generators::NamedBase
7
+ def copy_stylesheet
8
+ dir = ::Rails::Generators::ScaffoldGenerator.source_root
9
+ file = File.join(dir, "scaffold.css")
10
+ converted_contents = ::SassC::Engine.new(File.read(file)).render
11
+ create_file "app/assets/stylesheets/scaffolds.#{syntax}", converted_contents
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Scss
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_scss
9
+ template "stylesheet.scss", File.join('app/assets/stylesheets', class_path, "#{file_name}.scss")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the <%= name %> controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: https://sass-lang.com/
@@ -0,0 +1,10 @@
1
+ require "rails/generators/sass_scaffold"
2
+
3
+ module Scss
4
+ module Generators
5
+ class ScaffoldGenerator < ::Sass::Generators::ScaffoldBase
6
+ def syntax() :scss end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sprockets/sass_compressor'
4
+ require 'securerandom'
5
+
6
+ class Sprockets::SassCompressor
7
+ def initialize(options = {})
8
+ @options = {
9
+ syntax: :scss,
10
+ cache: false,
11
+ read_cache: false,
12
+ style: :compressed
13
+ }.merge(options).freeze
14
+ @cache_key = SecureRandom.uuid
15
+ end
16
+
17
+ def call(*args)
18
+ input = if defined?(data)
19
+ data # sprockets 2.x
20
+ else
21
+ args[0][:data] #sprockets 3.x
22
+ end
23
+
24
+ SassC::Engine.new(
25
+ input,
26
+ {
27
+ style: :compressed
28
+ }
29
+ ).render
30
+ end
31
+
32
+ # sprockets 2.x
33
+ alias :evaluate :call
34
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sprockets/sass_functions'
4
+
5
+ module Sprockets
6
+ module SassFunctions
7
+ def asset_data_url(path)
8
+ ::SassC::Script::Value::String.new("url(" + sprockets_context.asset_data_uri(path.value) + ")")
9
+ end
10
+ end
11
+ end
12
+
13
+ ::SassC::Script::Functions.send :include, Sprockets::SassFunctions
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tilt'
4
+
5
+ module SassC
6
+ module Rails
7
+ class Importer < SassC::Importer
8
+ class Extension
9
+ attr_reader :postfix
10
+
11
+ def initialize(postfix=nil)
12
+ @postfix = postfix
13
+ end
14
+
15
+ def import_for(full_path, parent_dir, options)
16
+ SassC::Importer::Import.new(full_path)
17
+ end
18
+ end
19
+
20
+ class CSSExtension
21
+ def postfix
22
+ ".css"
23
+ end
24
+
25
+ def import_for(full_path, parent_dir, options)
26
+ import_path = full_path.gsub(/\.css$/,"")
27
+ SassC::Importer::Import.new(import_path)
28
+ end
29
+ end
30
+
31
+ class CssScssExtension < Extension
32
+ def postfix
33
+ ".css.scss"
34
+ end
35
+
36
+ def import_for(full_path, parent_dir, options)
37
+ source = File.open(full_path, 'rb') { |f| f.read }
38
+ SassC::Importer::Import.new(full_path, source: source)
39
+ end
40
+ end
41
+
42
+ class CssSassExtension < Extension
43
+ def postfix
44
+ ".css.sass"
45
+ end
46
+
47
+ def import_for(full_path, parent_dir, options)
48
+ sass = File.open(full_path, 'rb') { |f| f.read }
49
+ parsed_scss = SassC::Sass2Scss.convert(sass)
50
+ SassC::Importer::Import.new(full_path, source: parsed_scss)
51
+ end
52
+ end
53
+
54
+ class SassERBExtension < Extension
55
+ def postfix
56
+ ".sass.erb"
57
+ end
58
+
59
+ def import_for(full_path, parent_dir, options)
60
+ template = Tilt::ERBTemplate.new(full_path)
61
+ parsed_erb = template.render(options[:sprockets][:context], {})
62
+ parsed_scss = SassC::Sass2Scss.convert(parsed_erb)
63
+ SassC::Importer::Import.new(full_path, source: parsed_scss)
64
+ end
65
+ end
66
+
67
+ class ERBExtension < Extension
68
+ def import_for(full_path, parent_dir, options)
69
+ template = Tilt::ERBTemplate.new(full_path)
70
+ parsed_erb = template.render(options[:sprockets][:context], {})
71
+ SassC::Importer::Import.new(full_path, source: parsed_erb)
72
+ end
73
+ end
74
+
75
+ EXTENSIONS = [
76
+ CssScssExtension.new,
77
+ CssSassExtension.new,
78
+ SassERBExtension.new,
79
+ ERBExtension.new(".scss.erb"),
80
+ ERBExtension.new(".css.erb"),
81
+ Extension.new(".scss"),
82
+ Extension.new(".sass"),
83
+ CSSExtension.new
84
+ ].freeze
85
+
86
+ PREFIXS = [ "", "_" ]
87
+ GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
88
+
89
+ def imports(path, parent_path)
90
+ parent_dir, _ = File.split(parent_path)
91
+ specified_dir, specified_file = File.split(path)
92
+
93
+ if m = path.match(GLOB)
94
+ path = path.sub(m[0], "")
95
+ base = File.expand_path(path, File.dirname(parent_path))
96
+ return glob_imports(base, m[2], parent_path)
97
+ end
98
+
99
+ search_paths = ([parent_dir] + load_paths).uniq
100
+
101
+ if specified_dir != "."
102
+ search_paths.map! do |path|
103
+ File.join(path, specified_dir)
104
+ end
105
+ search_paths.select! do |path|
106
+ File.directory?(path)
107
+ end
108
+ end
109
+
110
+ search_paths.each do |search_path|
111
+ PREFIXS.each do |prefix|
112
+ file_name = prefix + specified_file
113
+
114
+ EXTENSIONS.each do |extension|
115
+ try_path = File.join(search_path, file_name + extension.postfix)
116
+ if File.exist?(try_path)
117
+ record_import_as_dependency try_path
118
+ return extension.import_for(try_path, parent_dir, options)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ SassC::Importer::Import.new(path)
125
+ end
126
+
127
+ private
128
+
129
+ def extension_for_file(file)
130
+ EXTENSIONS.detect do |extension|
131
+ file.include? extension.postfix
132
+ end
133
+ end
134
+
135
+ def record_import_as_dependency(path)
136
+ context.depend_on path
137
+ end
138
+
139
+ def context
140
+ options[:sprockets][:context]
141
+ end
142
+
143
+ def load_paths
144
+ options[:load_paths]
145
+ end
146
+
147
+ def glob_imports(base, glob, current_file)
148
+ files = globbed_files(base, glob)
149
+ files = files.reject { |f| f == current_file }
150
+
151
+ files.map do |filename|
152
+ record_import_as_dependency(filename)
153
+ extension = extension_for_file(filename)
154
+ extension.import_for(filename, base, options)
155
+ end
156
+ end
157
+
158
+ def globbed_files(base, glob)
159
+ # TODO: Raise an error from SassC here
160
+ raise ArgumentError unless glob == "*" || glob == "**/*"
161
+
162
+ extensions = EXTENSIONS.map(&:postfix)
163
+ exts = extensions.map { |ext| Regexp.escape("#{ext}") }.join("|")
164
+ sass_re = Regexp.compile("(#{exts})$")
165
+
166
+ record_import_as_dependency(base)
167
+
168
+ files = Dir["#{base}/#{glob}"].sort.map do |path|
169
+ if File.directory?(path)
170
+ record_import_as_dependency(path)
171
+ nil
172
+ elsif sass_re =~ path
173
+ path
174
+ end
175
+ end
176
+
177
+ files.compact
178
+ end
179
+ end
180
+ end
181
+ end