sprockets-sass_embedded 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +109 -0
- data/lib/sprockets/sass_embedded/sass_compressor.rb +77 -0
- data/lib/sprockets/sass_embedded/sass_processor.rb +323 -0
- data/lib/sprockets/sass_embedded/scss_processor.rb +12 -0
- data/lib/sprockets/sass_embedded/version.rb +7 -0
- data/lib/sprockets/sass_embedded.rb +19 -0
- data/sprockets-sass_embedded.gemspec +32 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f6b62daf25c2209dc30a139a96936334c2dd0716f9f167900a6437e1cf73f99
|
4
|
+
data.tar.gz: 88ac1cffbca937c8cd4b718601c341e18d075e1387efc818367e4c35997ecda9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b64eb2a10cd6632ed8dad9951da98913480e8cb590809a4dcbd382935caa74b3aa76dbc1e14f1fc2cd39a0b1222362367d068de3cddbf3ef000a57e4ad403b6a
|
7
|
+
data.tar.gz: 6b7bcd2e47436fd26a9c46a04242e7dc70b12727489e3748d357545fe7d430c198cc3f18e86034d3d39f9e50acdff0fbb1afcd506be474fd1c3b8f2e3e901205
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Jason Garber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# sprockets-sass_embedded
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/sprockets-sass_embedded)
|
4
|
+
[](https://rubygems.org/gems/sprockets-sass_embedded)
|
5
|
+
[](https://github.com/jgarber623/sprockets-sass_embedded/actions/workflows/ci.yml)
|
6
|
+
[](https://codeclimate.com/github/jgarber623/sprockets-sass_embedded)
|
7
|
+
[](https://codeclimate.com/github/jgarber623/sprockets-sass_embedded/code)
|
8
|
+
|
9
|
+
**A Ruby gem for processing and compressing [Sass](https://sass-lang.com) files using [Sprockets 4](https://github.com/rails/sprockets) and [Embedded Dart Sass](https://github.com/ntkme/sass-embedded-host-ruby).**
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Before installing and using sprockets-sass_embedded, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. If you're using [Bundler](https://bundler.io) to manage gem dependencies, add sprockets-sass_embedded to your project's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'sprockets-sass_embedded'
|
17
|
+
```
|
18
|
+
|
19
|
+
…and run `bundle install` in your shell.
|
20
|
+
|
21
|
+
To install the gem manually, run the following in your shell:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
gem install sprockets-sass_embedded
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
sprockets-sass_embedded works with projects leveraging Sprockets 4 for asset processing. With minimal configuration changes, [Ruby on Rails](https://rubyonrails.org), [Sinatra](https://sinatrarb.com), and [Roda](http://roda.jeremyevans.net) applications can take advantage of the features in recent versions of Dart Sass. sprockets-sass_embedded uses [Natsuki](https://github.com/ntkme)'s [sass-embedded](https://github.com/ntkme/sass-embedded-host-ruby) gem whose platform-specific releases closely track (and match version-for-version) the official [dart-sass](https://github.com/sass/dart-sass) project's releases.
|
30
|
+
|
31
|
+
The examples below assume a Sass file named `application.scss` located in the assets path (e.g. `app/assets/stylesheets/application.scss`) appropriate for your app's framework. Asset paths are highly configurable, so the location of your asset files may vary.
|
32
|
+
|
33
|
+
### Ruby on Rails
|
34
|
+
|
35
|
+
With sprockets-sass_embedded added to your project's Gemfile and installed, set `config.assets.css_compressor = :sass_embedded` in your application's environment configuration. See the [Configuring Assets](https://guides.rubyonrails.org/configuring.html#configuring-assets) guide for additional details.
|
36
|
+
|
37
|
+
### Sinatra
|
38
|
+
|
39
|
+
In Sinatra applications, sprockets-sass_embedded can work in conjunction with the [sinatra-asset-pipeline](https://rubygems.org/gems/sinatra-asset-pipeline) gem. Using [sinatra-asset-pipeline's defaults](https://github.com/kalasjocke/sinatra-asset-pipeline/blob/master/lib/sinatra/asset_pipeline.rb#L7-L18), a sample `app.rb` file may look like:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class App < Sinatra::Base
|
43
|
+
set :assets_precompile, %w(application.css)
|
44
|
+
|
45
|
+
set :assets_css_compressor, :sass_embedded
|
46
|
+
|
47
|
+
register Sinatra::AssetPipeline
|
48
|
+
|
49
|
+
get '/' do
|
50
|
+
'Hello, world!'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### Roda
|
56
|
+
|
57
|
+
Similar to Sinatra, Roda applications may be configured to use sprockets-sass_embedded alongside the [roda-sprockets](https://rubygems.org/gems/roda-sprockets) gem. A sample `config.ru` file might look like:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
class App < Roda
|
61
|
+
plugin :render
|
62
|
+
|
63
|
+
plugin :sprockets,
|
64
|
+
css_compressor: :sass_embedded,
|
65
|
+
debug: false,
|
66
|
+
precompile: %w[application.css]
|
67
|
+
|
68
|
+
route do |r|
|
69
|
+
r.sprockets unless opts[:environment] == 'production'
|
70
|
+
|
71
|
+
r.root do
|
72
|
+
render :index
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
run App.freeze.app
|
78
|
+
```
|
79
|
+
|
80
|
+
## Asset Helpers
|
81
|
+
|
82
|
+
sprockets-sass-embedded includes a number of familiar helpers (e.g. `image_path`, `image_url`, `font_path`, `font_url`) that generate asset paths for use in your application. See [the `Functions` module](https://github.com/jgarber623/sprockets-sass_embedded/blob/main/lib/sprockets/sass_embedded/sass_processor.rb#L144-L318) in `lib/sprockets/sass_embedded/sass_processor.rb` for the available helpers.
|
83
|
+
|
84
|
+
```scss
|
85
|
+
@font-face {
|
86
|
+
font-family: "Hot Rush";
|
87
|
+
src: font_url("hot-rush.woff2") format("woff2"),
|
88
|
+
font_url("hot-rush.woff") format("woff");
|
89
|
+
}
|
90
|
+
|
91
|
+
html {
|
92
|
+
background: image_url("vaporwave.png") repeat 50% 50%;
|
93
|
+
font-family: "Times New Roman"
|
94
|
+
}
|
95
|
+
|
96
|
+
h1 {
|
97
|
+
font-family: "Hot Rush";
|
98
|
+
}
|
99
|
+
```
|
100
|
+
|
101
|
+
## Acknowledgments
|
102
|
+
|
103
|
+
sprockets-sass_embedded implements [Natsuki](https://github.com/ntkme)'s work from [rails/sprockets#737](https://github.com/rails/sprockets/pull/737) and wouldn't exist if not for their work bringing Dart Sass to Sprockets-enabled Ruby projects. Sprockets' internal workings are _fairly_ complicated, so the [Extending Sprockets guide](https://github.com/rails/sprockets/blob/main/guides/extending_sprockets.md) was also helpful.
|
104
|
+
|
105
|
+
sprockets-sass_embedded is written and maintained by [Jason Garber](https://sixtwothree.org).
|
106
|
+
|
107
|
+
## License
|
108
|
+
|
109
|
+
sprockets-sass_embedded is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module SassEmbedded
|
5
|
+
# Sass CSS minifier.
|
6
|
+
#
|
7
|
+
# @example Using the default options.
|
8
|
+
#
|
9
|
+
# environment.register_bundle_processor 'text/css',
|
10
|
+
# Sprockets::SassEmbedded::SassCompressor
|
11
|
+
#
|
12
|
+
# @example Passing options to the SassEmbedded compiler.
|
13
|
+
#
|
14
|
+
# environment.register_bundle_processor 'text/css',
|
15
|
+
# Sprockets::SassEmbedded::SassCompressor.new({ ... })
|
16
|
+
#
|
17
|
+
class SassCompressor
|
18
|
+
VERSION = '1'
|
19
|
+
|
20
|
+
private_constant :VERSION
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
def self.cache_key
|
24
|
+
instance.cache_key
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param input [Hash]
|
28
|
+
# @return [Hash{Symbol => String}]
|
29
|
+
def self.call(input)
|
30
|
+
instance.call(input)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Sprockets::SassEmbedded::SassCompressor]
|
34
|
+
def self.instance
|
35
|
+
@instance ||= new
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param options [Hash]
|
39
|
+
def initialize(**options)
|
40
|
+
@options = {
|
41
|
+
source_map: true,
|
42
|
+
style: :compressed,
|
43
|
+
syntax: :css
|
44
|
+
}.merge(options).freeze
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [String]
|
48
|
+
def cache_key
|
49
|
+
@cache_key ||=
|
50
|
+
[
|
51
|
+
self.class.name,
|
52
|
+
Autoload::SassEmbedded::Embedded::VERSION,
|
53
|
+
VERSION,
|
54
|
+
DigestUtils.digest(@options)
|
55
|
+
].join(':')
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param input [Hash]
|
59
|
+
# @return [Hash{Symbol => String}]
|
60
|
+
def call(input)
|
61
|
+
result = Autoload::SassEmbedded.compile_string(
|
62
|
+
input[:data],
|
63
|
+
**@options.merge(url: URIUtils.build_asset_uri(input[:filename]))
|
64
|
+
)
|
65
|
+
|
66
|
+
css = result.css
|
67
|
+
|
68
|
+
map = SourceMapUtils.combine_source_maps(
|
69
|
+
input[:metadata][:map],
|
70
|
+
SourceMapUtils.format_source_map(JSON.parse(result.source_map), input)
|
71
|
+
)
|
72
|
+
|
73
|
+
{ data: css, map: map }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module SassEmbedded
|
5
|
+
class SassProcessor
|
6
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/Options#functions
|
7
|
+
class DartSassFunctionsHash
|
8
|
+
# @param functions [Module]
|
9
|
+
# @param options [Hash{Symbol => Hash}]
|
10
|
+
def initialize(functions, options)
|
11
|
+
@functions = functions
|
12
|
+
|
13
|
+
instance.define_singleton_method(:options, -> { options })
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash{String => Proc}]
|
17
|
+
def to_hash
|
18
|
+
@functions
|
19
|
+
.public_instance_methods
|
20
|
+
.each_with_object({}) do |symbol, obj|
|
21
|
+
parameters = instance.method(symbol)
|
22
|
+
.parameters
|
23
|
+
.filter_map { |parameter| "$#{parameter.last}" if parameter.first == :req }
|
24
|
+
|
25
|
+
obj["#{symbol}(#{parameters.join(', ')})"] = ->(args) { instance.send(symbol, *args) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :to_h, :to_hash
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def instance
|
34
|
+
@instance ||= Class.new.extend(@functions)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private_constant :DartSassFunctionsHash
|
39
|
+
|
40
|
+
VERSION = '1'
|
41
|
+
|
42
|
+
private_constant :VERSION
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def self.cache_key
|
46
|
+
instance.cache_key
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.call(input)
|
50
|
+
instance.call(input)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Sprockets::SassEmbedded::SassProcessor]
|
54
|
+
def self.instance
|
55
|
+
@instance ||= new
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Symbol]
|
59
|
+
def self.syntax
|
60
|
+
:indented
|
61
|
+
end
|
62
|
+
|
63
|
+
# Public: Initialize template with custom options.
|
64
|
+
#
|
65
|
+
# options - Hash
|
66
|
+
# cache_version - String custom cache version. Used to force a cache
|
67
|
+
# change after code changes are made to Sass Functions.
|
68
|
+
#
|
69
|
+
def initialize(cache_version: nil, functions: nil, sass_config: {}, **_options)
|
70
|
+
@cache_version = cache_version
|
71
|
+
@sass_config = sass_config
|
72
|
+
|
73
|
+
@functions = Module.new do
|
74
|
+
include Functions
|
75
|
+
include functions if functions
|
76
|
+
class_eval(&block) if block_given?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String]
|
81
|
+
def cache_key
|
82
|
+
@cache_key ||=
|
83
|
+
[
|
84
|
+
self.class.name,
|
85
|
+
VERSION,
|
86
|
+
Autoload::SassEmbedded::Embedded::VERSION,
|
87
|
+
@cache_version
|
88
|
+
].join(':')
|
89
|
+
end
|
90
|
+
|
91
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
92
|
+
def call(input)
|
93
|
+
context = input[:environment].context_class.new(input)
|
94
|
+
|
95
|
+
options = merge_options(
|
96
|
+
functions: DartSassFunctionsHash.new(
|
97
|
+
@functions,
|
98
|
+
sprockets: {
|
99
|
+
context: context,
|
100
|
+
dependencies: context.metadata[:dependencies],
|
101
|
+
environment: input[:environment]
|
102
|
+
}
|
103
|
+
).to_h,
|
104
|
+
load_paths: context.environment.paths,
|
105
|
+
source_map: true,
|
106
|
+
syntax: self.class.syntax,
|
107
|
+
url: URIUtils.build_asset_uri(input[:filename])
|
108
|
+
)
|
109
|
+
|
110
|
+
result = Autoload::SassEmbedded.compile_string(input[:data], **options)
|
111
|
+
|
112
|
+
css = result.css
|
113
|
+
|
114
|
+
map = SourceMapUtils.combine_source_maps(
|
115
|
+
input[:metadata][:map],
|
116
|
+
SourceMapUtils.format_source_map(JSON.parse(result.source_map), input)
|
117
|
+
)
|
118
|
+
|
119
|
+
sass_dependencies = Set.new
|
120
|
+
|
121
|
+
result.loaded_urls.each do |url|
|
122
|
+
scheme, _host, path, _query = URIUtils.split_file_uri(url)
|
123
|
+
|
124
|
+
next unless scheme == 'file'
|
125
|
+
|
126
|
+
sass_dependencies << path
|
127
|
+
context.metadata[:dependencies] << URIUtils.build_file_digest_uri(path)
|
128
|
+
end
|
129
|
+
|
130
|
+
context.metadata.merge(data: css, map: map, sass_dependencies: sass_dependencies)
|
131
|
+
end
|
132
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def merge_options(options)
|
137
|
+
defaults = @sass_config.dup
|
138
|
+
|
139
|
+
if (load_paths = defaults.delete(:load_paths))
|
140
|
+
options[:load_paths] += load_paths
|
141
|
+
end
|
142
|
+
|
143
|
+
options.merge!(defaults)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Functions injected into Sass context during Sprockets evaluation.
|
147
|
+
#
|
148
|
+
# This module may be extended to add global functionality to all Sprockets
|
149
|
+
# Sass environments. Scoping your functions to just your environment is
|
150
|
+
# preferred.
|
151
|
+
#
|
152
|
+
# @example
|
153
|
+
#
|
154
|
+
# module Sprockets::SassProcessor::Functions
|
155
|
+
# def asset_path(path, options = {})
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
module Functions
|
160
|
+
# Generate a URL for asset path.
|
161
|
+
#
|
162
|
+
# @param path [Sass::Script::String]
|
163
|
+
# @param options [Hash]
|
164
|
+
# @return [SassEmbedded::Value::String]
|
165
|
+
def asset_path(path, **options)
|
166
|
+
path = path.text
|
167
|
+
|
168
|
+
path, _, query, fragment = URI.split(path)[5..8]
|
169
|
+
path = sprockets_context.asset_path(path, options)
|
170
|
+
query = "?#{query}" if query
|
171
|
+
fragment = "##{fragment}" if fragment
|
172
|
+
|
173
|
+
Autoload::SassEmbedded::Value::String.new("#{path}#{query}#{fragment}", quoted: true)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Generate an asset +url()+ link.
|
177
|
+
#
|
178
|
+
# @param path [Sass::Script::String]
|
179
|
+
# @return [SassEmbedded::Value::String]
|
180
|
+
def asset_url(path, **options)
|
181
|
+
Autoload::SassEmbedded::Value::String.new("url(#{asset_path(path, options).text})", quoted: false)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Generate a URL for image path.
|
185
|
+
#
|
186
|
+
# @param path [Sass::Script::String]
|
187
|
+
# @return [SassEmbedded::Value::String]
|
188
|
+
def image_path(path)
|
189
|
+
asset_path(path, type: :image)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Generate an image +url()+ link.
|
193
|
+
#
|
194
|
+
# @param path [Sass::Script::String]
|
195
|
+
# @return [SassEmbedded::Value::String]
|
196
|
+
def image_url(path)
|
197
|
+
asset_url(path, type: :image)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Generate a URL for video path.
|
201
|
+
#
|
202
|
+
# @param path [Sass::Script::String]
|
203
|
+
# @return [SassEmbedded::Value::String]
|
204
|
+
def video_path(path)
|
205
|
+
asset_path(path, type: :video)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Generate a video +url()+ link.
|
209
|
+
#
|
210
|
+
# @param path [Sass::Script::String]
|
211
|
+
# @return [SassEmbedded::Value::String]
|
212
|
+
def video_url(path)
|
213
|
+
asset_url(path, type: :video)
|
214
|
+
end
|
215
|
+
|
216
|
+
# Generate a URL for audio path.
|
217
|
+
#
|
218
|
+
# @param path [Sass::Script::String]
|
219
|
+
# @return [SassEmbedded::Value::String]
|
220
|
+
def audio_path(path)
|
221
|
+
asset_path(path, type: :audio)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Generate an audio +url()+ link.
|
225
|
+
#
|
226
|
+
# @param path [Sass::Script::String]
|
227
|
+
# @return [SassEmbedded::Value::String]
|
228
|
+
def audio_url(path)
|
229
|
+
asset_url(path, type: :audio)
|
230
|
+
end
|
231
|
+
|
232
|
+
# Generate a URL for font path.
|
233
|
+
#
|
234
|
+
# @param path [Sass::Script::String]
|
235
|
+
# @return [SassEmbedded::Value::String]
|
236
|
+
def font_path(path)
|
237
|
+
asset_path(path, type: :font)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Generate a font +url()+ link.
|
241
|
+
#
|
242
|
+
# @param path [Sass::Script::String]
|
243
|
+
# @return [SassEmbedded::Value::String]
|
244
|
+
def font_url(path)
|
245
|
+
asset_url(path, type: :font)
|
246
|
+
end
|
247
|
+
|
248
|
+
# Generate a URL for JavaScript path.
|
249
|
+
#
|
250
|
+
# @param path [Sass::Script::String]
|
251
|
+
# @return [SassEmbedded::Value::String]
|
252
|
+
def javascript_path(path)
|
253
|
+
asset_path(path, type: :javascript)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Generate a JavaScript +url()+ link.
|
257
|
+
#
|
258
|
+
# @param path [Sass::Script::String]
|
259
|
+
# @return [SassEmbedded::Value::String]
|
260
|
+
def javascript_url(path)
|
261
|
+
asset_url(path, type: :javascript)
|
262
|
+
end
|
263
|
+
|
264
|
+
# Generate a URL for stylesheet path.
|
265
|
+
#
|
266
|
+
# @param path [Sass::Script::String]
|
267
|
+
# @return [SassEmbedded::Value::String]
|
268
|
+
def stylesheet_path(path)
|
269
|
+
asset_path(path, type: :stylesheet)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Generate a stylesheet +url()+ link.
|
273
|
+
#
|
274
|
+
# @param path [Sass::Script::String]
|
275
|
+
# @return [SassEmbedded::Value::String]
|
276
|
+
def stylesheet_url(path)
|
277
|
+
asset_url(path, type: :stylesheet)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Generate a +data:+ URI for asset path.
|
281
|
+
#
|
282
|
+
# @param path [Sass::Script::String]
|
283
|
+
# @return [SassEmbedded::Value::String]
|
284
|
+
def asset_data_uri(path)
|
285
|
+
url = sprockets_context.asset_data_uri(path.text)
|
286
|
+
Autoload::SassEmbedded::Value::String.new(url)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Genearte a +data:+ +url()+ link.
|
290
|
+
#
|
291
|
+
# @param path [Sass::Script::String]
|
292
|
+
# @return [SassEmbedded::Value::String]
|
293
|
+
def asset_data_url(path)
|
294
|
+
Autoload::SassEmbedded::Value::String.new("url(#{asset_data_uri(path)})", quoted: false)
|
295
|
+
end
|
296
|
+
|
297
|
+
protected
|
298
|
+
|
299
|
+
# @deprecated Use #sprockets_environment or #sprockets_dependencies
|
300
|
+
# instead.
|
301
|
+
#
|
302
|
+
# @return [Sprockets::Context]
|
303
|
+
def sprockets_context
|
304
|
+
options[:sprockets][:context]
|
305
|
+
end
|
306
|
+
|
307
|
+
# A mutatable set of dependencies.
|
308
|
+
#
|
309
|
+
# @return [Set]
|
310
|
+
def sprockets_dependencies
|
311
|
+
options[:sprockets][:dependencies]
|
312
|
+
end
|
313
|
+
|
314
|
+
# The Environment.
|
315
|
+
#
|
316
|
+
# @return [Sprockets::Environment]
|
317
|
+
def sprockets_environment
|
318
|
+
options[:sprockets][:environment]
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sass-embedded'
|
4
|
+
require 'sprockets'
|
5
|
+
|
6
|
+
require_relative 'sass_embedded/sass_compressor'
|
7
|
+
require_relative 'sass_embedded/sass_processor'
|
8
|
+
require_relative 'sass_embedded/scss_processor'
|
9
|
+
|
10
|
+
module Sprockets
|
11
|
+
module Autoload
|
12
|
+
SassEmbedded = ::Sass
|
13
|
+
end
|
14
|
+
|
15
|
+
register_transformer 'text/sass', 'text/css', SassEmbedded::SassProcessor
|
16
|
+
register_transformer 'text/scss', 'text/css', SassEmbedded::ScssProcessor
|
17
|
+
|
18
|
+
register_compressor 'text/css', :sass_embedded, SassEmbedded::SassCompressor
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/sprockets/sass_embedded/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = '>= 2.7', '< 4'
|
7
|
+
|
8
|
+
spec.name = 'sprockets-sass_embedded'
|
9
|
+
spec.version = Sprockets::SassEmbedded::VERSION
|
10
|
+
spec.authors = ['Jason Garber']
|
11
|
+
spec.email = ['jason@sixtwothree.org']
|
12
|
+
|
13
|
+
spec.summary = 'Process and compress Sass files using Sprockets 4 and Embedded Dart Sass.'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'https://github.com/jgarber623/sprockets-sass_embedded'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = Dir['lib/**/*'].reject { |f| File.directory?(f) }
|
19
|
+
spec.files += %w[LICENSE README.md]
|
20
|
+
spec.files += %w[sprockets-sass_embedded.gemspec]
|
21
|
+
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.metadata = {
|
25
|
+
'bug_tracker_uri' => "#{spec.homepage}/issues",
|
26
|
+
'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
|
27
|
+
'rubygems_mfa_required' => 'true'
|
28
|
+
}
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'sass-embedded', '>= 1.54.6'
|
31
|
+
spec.add_runtime_dependency 'sprockets', '~> 4.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-sass_embedded
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Garber
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sass-embedded
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.54.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.54.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sprockets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
description: Process and compress Sass files using Sprockets 4 and Embedded Dart Sass.
|
42
|
+
email:
|
43
|
+
- jason@sixtwothree.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- lib/sprockets/sass_embedded.rb
|
51
|
+
- lib/sprockets/sass_embedded/sass_compressor.rb
|
52
|
+
- lib/sprockets/sass_embedded/sass_processor.rb
|
53
|
+
- lib/sprockets/sass_embedded/scss_processor.rb
|
54
|
+
- lib/sprockets/sass_embedded/version.rb
|
55
|
+
- sprockets-sass_embedded.gemspec
|
56
|
+
homepage: https://github.com/jgarber623/sprockets-sass_embedded
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
bug_tracker_uri: https://github.com/jgarber623/sprockets-sass_embedded/issues
|
61
|
+
changelog_uri: https://github.com/jgarber623/sprockets-sass_embedded/blob/v0.1.0/CHANGELOG.md
|
62
|
+
rubygems_mfa_required: 'true'
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.7'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '4'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.3.16
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Process and compress Sass files using Sprockets 4 and Embedded Dart Sass.
|
85
|
+
test_files: []
|