dartsass-sprockets 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +23 -0
- data/README.md +72 -0
- data/lib/dartsass-sprockets.rb +3 -0
- data/lib/rails/generators/sass/assets/assets_generator.rb +13 -0
- data/lib/rails/generators/sass/scaffold/scaffold_generator.rb +9 -0
- data/lib/rails/generators/sass_scaffold.rb +15 -0
- data/lib/rails/generators/scss/assets/assets_generator.rb +13 -0
- data/lib/rails/generators/scss/scaffold/scaffold_generator.rb +10 -0
- data/lib/sassc/rails/compressor.rb +34 -0
- data/lib/sassc/rails/functions.rb +13 -0
- data/lib/sassc/rails/importer.rb +181 -0
- data/lib/sassc/rails/railtie.rb +81 -0
- data/lib/sassc/rails/template.rb +113 -0
- data/lib/sassc/rails/version.rb +7 -0
- data/lib/sassc/rails.rb +10 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27972e22ea4a4d83396a8874b82d96d48b006bbff80a6fd09b566819e1a94cbe
|
4
|
+
data.tar.gz: 8c01d7c429722328d6dcb3f8b7a85ad17a5f88abf7d4ad0044f62c5c26e4fcda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a6e2076e7a2c18806ac6932539026eea2ecf427618824bac7169e17655a991fa5cd2e19a2a6179aa28946ec57170e4fc335b28d1c0a2fb4794da608455a8d17
|
7
|
+
data.tar.gz: 5cf8902d81bcb478120735495b9ed76668e25570975d97e7c559531e10b3b55c4f8f072c3c7ed9b226a4965d98fd6925c08526262e507d8a9e1f46b808fe5b53
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) Ryan Boland & contributors
|
2
|
+
Copyright (c) TableCheck
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Dart Sass for Spockets
|
2
|
+
|
3
|
+
[![build](https://github.com/tablecheck/dartsass-sprockets/actions/workflows/build.yml/badge.svg)](https://github.com/tablecheck/dartsass-sprockets/actions/workflows/build.yml)
|
4
|
+
[![gem](https://badge.fury.io/rb/dartsass-sprockets.svg)](https://rubygems.org/gems/dartsass-sprockets)
|
5
|
+
|
6
|
+
Use [Dart Sass](https://sass-lang.com/dart-sass) with Sprockets and the Ruby on Rails asset pipeline.
|
7
|
+
|
8
|
+
This gem is a fork of [sass/sassc-rails](https://github.com/sass/sassc-rails)
|
9
|
+
which maintains API compatibility but delegates to the
|
10
|
+
[dartsass-ruby](https://github.com/tablecheck/sass-embedded-host-ruby) gem
|
11
|
+
which uses Dart Sass instead of the libsass C implmentation.
|
12
|
+
|
13
|
+
For ease of upgrading, the root namespace `::SassC` is still used by this gem,
|
14
|
+
although it is now a misnomer. This is planned to be renamed in a future
|
15
|
+
major version release.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'dartsass-sprockets'
|
23
|
+
```
|
24
|
+
|
25
|
+
This will automatically configure your default Rails
|
26
|
+
`config.assets.css_compressor` to use `:sass`.
|
27
|
+
|
28
|
+
### Upgrading to Dart Sass
|
29
|
+
|
30
|
+
This gem is a drop-in replacement to [sass-rails](https://github.com/rails/sass-rails).
|
31
|
+
Note the following differences:
|
32
|
+
|
33
|
+
* `config.sass.style` values `:nested` and `:compact` will behave as `:expanded`. Use `:compressed` for minification.
|
34
|
+
* `config.sass.line_comments` option is ignored and will always be disabled.
|
35
|
+
|
36
|
+
## Inline Source Maps
|
37
|
+
|
38
|
+
To turn on inline source maps, add the following configuration
|
39
|
+
to your `development.rb` file:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# config/environments/development.rb
|
43
|
+
config.sass.inline_source_maps = true
|
44
|
+
```
|
45
|
+
|
46
|
+
After adding this config line, you may need to clear your assets cache
|
47
|
+
(`rm -r tmp/cache/assets`), stop Spring, and restart your Rails server.
|
48
|
+
|
49
|
+
Note these source maps are *inline* and will be appended to the compiled
|
50
|
+
`application.css` file. (They will *not* generate additional files.)
|
51
|
+
|
52
|
+
## Alternatives
|
53
|
+
|
54
|
+
* [dartsass-rails](https://github.com/rails/dartsass-rails): The Rails organization
|
55
|
+
maintains its own wrapper for Dart Sass. Unlike this gem, dartsass-rails does
|
56
|
+
not support Sprockets.
|
57
|
+
|
58
|
+
## Credits
|
59
|
+
|
60
|
+
* This gem is maintained and used in production by [TableCheck](https://www.tablecheck.com/en/join). (We'd be very glad if the Sass organization could take over maintainership in the future!)
|
61
|
+
* Credit to [Ryan Boland](https://ryanboland.com) and the authors of the original
|
62
|
+
[sass/sassc-rails](https://github.com/sass/sassc-rails) and
|
63
|
+
[sass-rails](https://github.com/rails/sass-rails) gems.
|
64
|
+
* See our [awesome contributors](https://github.com/tablecheck/sassc-ruby/graphs/contributors).
|
65
|
+
|
66
|
+
### Contributing
|
67
|
+
|
68
|
+
1. Fork it ([https://github.com/tablecheck/dartsass-sprockets/fork](https://github.com/tablecheck/dartsass-sprockets/fork))
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`) - try to include tests
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create a new Pull Request
|
@@ -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,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,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
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/class/attribute'
|
4
|
+
require 'sprockets/railtie'
|
5
|
+
|
6
|
+
module SassC::Rails
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
|
+
config.sass = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
# Establish static configuration defaults
|
11
|
+
# Emit scss files during stylesheet generation of scaffold
|
12
|
+
config.sass.preferred_syntax = :scss
|
13
|
+
# Initialize the load paths to an empty array
|
14
|
+
config.sass.load_paths = []
|
15
|
+
|
16
|
+
# Display line comments above each selector as a debugging aid
|
17
|
+
config.sass.line_comments = true
|
18
|
+
|
19
|
+
# Set the default stylesheet engine
|
20
|
+
# It can be overridden by passing:
|
21
|
+
# --stylesheet_engine=sass
|
22
|
+
# to the rails generate command
|
23
|
+
config.app_generators.stylesheet_engine config.sass.preferred_syntax
|
24
|
+
|
25
|
+
if config.respond_to?(:annotations)
|
26
|
+
config.annotations.register_extensions("scss", "sass") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Remove the sass middleware if it gets inadvertently enabled by applications.
|
30
|
+
config.after_initialize do |app|
|
31
|
+
app.config.middleware.delete(Sass::Plugin::Rack) if defined?(Sass::Plugin::Rack)
|
32
|
+
end
|
33
|
+
|
34
|
+
initializer :setup_sass, group: :all do |app|
|
35
|
+
# Only emit one kind of syntax because though we have registered two kinds of generators
|
36
|
+
syntax = app.config.sass.preferred_syntax.to_sym
|
37
|
+
alt_syntax = syntax == :sass ? "scss" : "sass"
|
38
|
+
app.config.generators.hide_namespace alt_syntax
|
39
|
+
|
40
|
+
# Override stylesheet engine to the preferred syntax
|
41
|
+
config.app_generators.stylesheet_engine syntax
|
42
|
+
|
43
|
+
# Establish configuration defaults that are environmental in nature
|
44
|
+
# if config.sass.full_exception.nil?
|
45
|
+
# # Display a stack trace in the css output when in development-like environments.
|
46
|
+
# config.sass.full_exception = app.config.consider_all_requests_local
|
47
|
+
# end
|
48
|
+
|
49
|
+
app.config.assets.configure do |env|
|
50
|
+
env.context_class.class_eval do
|
51
|
+
class_attribute :sass_config
|
52
|
+
self.sass_config = app.config.sass
|
53
|
+
end
|
54
|
+
|
55
|
+
if env.respond_to?(:register_transformer)
|
56
|
+
env.register_transformer 'text/sass', 'text/css', SassC::Rails::SassTemplate.new
|
57
|
+
env.register_transformer 'text/scss', 'text/css', SassC::Rails::ScssTemplate.new
|
58
|
+
end
|
59
|
+
|
60
|
+
if env.respond_to?(:register_engine)
|
61
|
+
[
|
62
|
+
['.sass', SassC::Rails::SassTemplate],
|
63
|
+
['.scss', SassC::Rails::ScssTemplate]
|
64
|
+
].each do |engine|
|
65
|
+
engine << { silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
|
66
|
+
env.register_engine(*engine)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
initializer :setup_compression, group: :all do |app|
|
73
|
+
if !Rails.env.development?
|
74
|
+
app.config.assets.css_compressor = :sass unless app.config.assets.has_key?(:css_compressor)
|
75
|
+
else
|
76
|
+
# Use expanded output instead of the sass default of :nested unless specified
|
77
|
+
app.config.sass.style ||= :expanded
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sprockets/version"
|
4
|
+
require 'sprockets/sass_processor'
|
5
|
+
require "sprockets/utils"
|
6
|
+
|
7
|
+
module SassC::Rails
|
8
|
+
class SassTemplate < Sprockets::SassProcessor
|
9
|
+
def initialize(options = {}, &block)
|
10
|
+
@cache_version = options[:cache_version]
|
11
|
+
@cache_key = "#{self.class.name}:#{VERSION}:#{SassC::VERSION}:#{@cache_version}".freeze
|
12
|
+
#@importer_class = options[:importer] || Sass::Importers::Filesystem
|
13
|
+
@sass_config = options[:sass_config] || {}
|
14
|
+
@functions = Module.new do
|
15
|
+
include Functions
|
16
|
+
include options[:functions] if options[:functions]
|
17
|
+
class_eval(&block) if block_given?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(input)
|
22
|
+
context = input[:environment].context_class.new(input)
|
23
|
+
|
24
|
+
options = {
|
25
|
+
filename: input[:filename],
|
26
|
+
line_comments: line_comments?,
|
27
|
+
syntax: self.class.syntax,
|
28
|
+
load_paths: input[:environment].paths,
|
29
|
+
importer: SassC::Rails::Importer,
|
30
|
+
sprockets: {
|
31
|
+
context: context,
|
32
|
+
environment: input[:environment],
|
33
|
+
dependencies: context.metadata[:dependency_paths]
|
34
|
+
}
|
35
|
+
}.merge!(config_options) { |key, left, right| safe_merge(key, left, right) }
|
36
|
+
|
37
|
+
engine = ::SassC::Engine.new(input[:data], options)
|
38
|
+
|
39
|
+
css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do
|
40
|
+
engine.render
|
41
|
+
end
|
42
|
+
|
43
|
+
context.metadata.merge(data: css)
|
44
|
+
end
|
45
|
+
|
46
|
+
def config_options
|
47
|
+
opts = { style: sass_style, load_paths: load_paths }
|
48
|
+
|
49
|
+
|
50
|
+
if Rails.application.config.sass.inline_source_maps
|
51
|
+
opts.merge!({
|
52
|
+
source_map_file: ".",
|
53
|
+
source_map_embed: true,
|
54
|
+
source_map_contents: true,
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
opts
|
59
|
+
end
|
60
|
+
|
61
|
+
def sass_style
|
62
|
+
(Rails.application.config.sass.style || :expanded).to_sym
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_paths
|
66
|
+
Rails.application.config.sass.load_paths || []
|
67
|
+
end
|
68
|
+
|
69
|
+
def line_comments?
|
70
|
+
Rails.application.config.sass.line_comments
|
71
|
+
end
|
72
|
+
|
73
|
+
def safe_merge(_key, left, right)
|
74
|
+
if [left, right].all? { |v| v.is_a? Hash }
|
75
|
+
left.merge(right) { |k, l, r| safe_merge(k, l, r) }
|
76
|
+
elsif [left, right].all? { |v| v.is_a? Array }
|
77
|
+
(left + right).uniq
|
78
|
+
else
|
79
|
+
right
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# The methods in the Functions module were copied here from sprockets in order to
|
84
|
+
# override the Value class names (e.g. ::SassC::Script::Value::String)
|
85
|
+
module Functions
|
86
|
+
def asset_path(path, options = {})
|
87
|
+
path = path.value
|
88
|
+
|
89
|
+
path, _, query, fragment = URI.split(path)[5..8]
|
90
|
+
path = sprockets_context.asset_path(path, options)
|
91
|
+
query = "?#{query}" if query
|
92
|
+
fragment = "##{fragment}" if fragment
|
93
|
+
|
94
|
+
::SassC::Script::Value::String.new("#{path}#{query}#{fragment}", :string)
|
95
|
+
end
|
96
|
+
|
97
|
+
def asset_url(path, options = {})
|
98
|
+
::SassC::Script::Value::String.new("url(#{asset_path(path, options).value})")
|
99
|
+
end
|
100
|
+
|
101
|
+
def asset_data_url(path)
|
102
|
+
url = sprockets_context.asset_data_uri(path.value)
|
103
|
+
::SassC::Script::Value::String.new("url(" + url + ")")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class ScssTemplate < SassTemplate
|
109
|
+
def self.syntax
|
110
|
+
:scss
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/sassc/rails.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rails/version"
|
4
|
+
|
5
|
+
require "sassc"
|
6
|
+
require_relative "rails/functions"
|
7
|
+
require_relative "rails/importer"
|
8
|
+
require_relative "rails/template"
|
9
|
+
require_relative "rails/compressor"
|
10
|
+
require_relative "rails/railtie"
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dartsass-sprockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Boland
|
8
|
+
- Johnny Shields
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: dartsass-ruby
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: tilt
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: railties
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 4.0.0
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 4.0.0
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: sprockets
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: sprockets-rails
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
description: Use Dart Sass with Sprockets and the Ruby on Rails asset pipeline.
|
141
|
+
email:
|
142
|
+
- ryan@tanookilabs.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- LICENSE.txt
|
148
|
+
- README.md
|
149
|
+
- lib/dartsass-sprockets.rb
|
150
|
+
- lib/rails/generators/sass/assets/assets_generator.rb
|
151
|
+
- lib/rails/generators/sass/scaffold/scaffold_generator.rb
|
152
|
+
- lib/rails/generators/sass_scaffold.rb
|
153
|
+
- lib/rails/generators/scss/assets/assets_generator.rb
|
154
|
+
- lib/rails/generators/scss/scaffold/scaffold_generator.rb
|
155
|
+
- lib/sassc/rails.rb
|
156
|
+
- lib/sassc/rails/compressor.rb
|
157
|
+
- lib/sassc/rails/functions.rb
|
158
|
+
- lib/sassc/rails/importer.rb
|
159
|
+
- lib/sassc/rails/railtie.rb
|
160
|
+
- lib/sassc/rails/template.rb
|
161
|
+
- lib/sassc/rails/version.rb
|
162
|
+
homepage: https://github.com/sass/dartsass-sprockets
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 2.6.0
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubygems_version: 3.4.4
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Use Dart Sass with Sprockets and the Ruby on Rails asset pipeline.
|
185
|
+
test_files: []
|