condenser-rails 1.0 → 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.
- checksums.yaml +4 -4
- data/lib/condenser/rails/context.rb +2 -0
- data/lib/condenser/rails/helper.rb +90 -41
- data/lib/condenser/rails/task.rb +2 -0
- data/lib/condenser/rails/utils.rb +2 -0
- data/lib/condenser/rails/version.rb +3 -1
- data/lib/condenser/rails.rb +2 -0
- data/lib/condenser/railtie.rb +7 -18
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ea54efa8084fec3370c9109968566c25fc42e2c1dda0117af935509cdd3d04
|
4
|
+
data.tar.gz: 85d88db655be386be3fb03bcd0fdaf176b032a41d6ef0ee5025de6bfb3215bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f2939a3411dd310790767e50da0dc331421752082a4f548d7e1c5dc2dffa82e3b5ea559afa9d570fc5398f0eaaa933b61184fad727b11c59162441aa390f69
|
7
|
+
data.tar.gz: bdcb847ece9af49935ec5497d053912e7114871463f1af9573e73441c7500609d7a5a80cd675d7971ae16219e84c76c7e15a3b7fe669f3bc7dcc1c58d2028719
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'action_view'
|
2
4
|
require 'condenser'
|
3
5
|
require 'active_support/core_ext/class/attribute'
|
@@ -61,75 +63,115 @@ module Condenser::Rails
|
|
61
63
|
def asset_integrity(path, options = {})
|
62
64
|
asset_resolver.integrity(path)
|
63
65
|
end
|
64
|
-
|
65
|
-
#
|
66
|
+
|
67
|
+
# Get type for asset path. (module or nil for javascript)
|
68
|
+
#
|
69
|
+
# path - String path
|
70
|
+
# options - Hash options
|
66
71
|
#
|
67
|
-
#
|
72
|
+
# Returns String integrity attribute or nil if no asset was found.
|
73
|
+
def asset_type(path, options = {})
|
74
|
+
asset_resolver.type(path)
|
75
|
+
end
|
76
|
+
|
77
|
+
# TODO: perhaps prepend this function and add integrity if set to true?
|
68
78
|
def javascript_include_tag(*sources)
|
69
79
|
options = sources.extract_options!.stringify_keys
|
70
80
|
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
71
|
-
|
81
|
+
preload_links = []
|
82
|
+
use_preload_links_header = options["preload_links_header"].nil? ? preload_links_header : options.delete("preload_links_header")
|
83
|
+
nopush = options["nopush"].nil? ? true : options.delete("nopush")
|
84
|
+
crossorigin = options.delete("crossorigin")
|
85
|
+
crossorigin = "anonymous" if crossorigin == true
|
86
|
+
integrity = options["integrity"]
|
72
87
|
|
73
88
|
sources_tags = sources.uniq.map { |source|
|
74
89
|
href = path_to_javascript(source, path_options)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
90
|
+
integrity = if options["integrity"] == true
|
91
|
+
asset_integrity(source.to_s.delete_suffix('.js')+'.js')
|
92
|
+
elsif options["integrity"] != false
|
93
|
+
options["integrity"]
|
94
|
+
end
|
95
|
+
type = if !options.has_key?('type')
|
96
|
+
asset_type(source.to_s.delete_suffix('.js')+'.js')
|
97
|
+
else
|
98
|
+
options["type"]
|
99
|
+
end
|
100
|
+
rel = options["type"] == "module" ? "modulepreload" : "preload"
|
79
101
|
|
102
|
+
if use_preload_links_header && !options["defer"] && href.present? && !href.start_with?("data:")
|
103
|
+
preload_link = "<#{href}>; rel=#{rel}; as=script"
|
104
|
+
preload_link += "; crossorigin=#{crossorigin}" unless crossorigin.nil?
|
105
|
+
preload_link += "; integrity=#{integrity}" unless integrity.nil?
|
106
|
+
preload_link += "; nonce=#{content_security_policy_nonce}" if options["nonce"] == true
|
107
|
+
preload_link += "; nopush" if nopush
|
108
|
+
preload_links << preload_link
|
109
|
+
end
|
110
|
+
tag_options = {
|
111
|
+
"src" => href,
|
112
|
+
"crossorigin" => crossorigin
|
113
|
+
}.merge!(options.except('integrity', 'type'))
|
80
114
|
if tag_options["nonce"] == true
|
81
115
|
tag_options["nonce"] = content_security_policy_nonce
|
82
116
|
end
|
83
|
-
|
84
|
-
if
|
85
|
-
if tag_options["integrity"] == true
|
86
|
-
tag_options["integrity"] = asset_integrity(source.to_s.delete_suffix('.js')+'.js')
|
87
|
-
elsif tag_options["integrity"] == false
|
88
|
-
tag_options.delete('integrity')
|
89
|
-
end
|
90
|
-
else
|
91
|
-
tag_options.delete('integrity')
|
92
|
-
end
|
117
|
+
tag_options['type'] = type if type
|
118
|
+
tag_options['integrity'] = integrity if integrity
|
93
119
|
|
94
120
|
content_tag("script", "", tag_options)
|
95
121
|
}.join("\n").html_safe
|
96
122
|
|
97
|
-
|
123
|
+
if use_preload_links_header
|
124
|
+
send_preload_links_header(preload_links)
|
125
|
+
end
|
98
126
|
|
99
127
|
sources_tags
|
100
128
|
end
|
101
129
|
|
102
|
-
#
|
103
|
-
#
|
104
|
-
# Eventually will be deprecated and replaced by source maps.
|
130
|
+
# TODO: perhaps prepend this function and add integrity if set to true?
|
105
131
|
def stylesheet_link_tag(*sources)
|
106
132
|
options = sources.extract_options!.stringify_keys
|
107
|
-
path_options = options.extract!("protocol", "host", "skip_pipeline").symbolize_keys
|
108
|
-
|
109
|
-
|
133
|
+
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
134
|
+
use_preload_links_header = options["preload_links_header"].nil? ? preload_links_header : options.delete("preload_links_header")
|
135
|
+
preload_links = []
|
136
|
+
crossorigin = options.delete("crossorigin")
|
137
|
+
crossorigin = "anonymous" if crossorigin == true
|
138
|
+
nopush = options["nopush"].nil? ? true : options.delete("nopush")
|
139
|
+
|
110
140
|
sources_tags = sources.uniq.map { |source|
|
111
141
|
href = path_to_stylesheet(source, path_options)
|
112
|
-
|
142
|
+
integrity = if options["integrity"] == true
|
143
|
+
asset_integrity(source.to_s.delete_suffix('.css')+'.css')
|
144
|
+
elsif options["integrity"] != false
|
145
|
+
options["integrity"]
|
146
|
+
end
|
147
|
+
|
148
|
+
if use_preload_links_header && href.present? && !href.start_with?("data:")
|
149
|
+
preload_link = "<#{href}>; rel=preload; as=style"
|
150
|
+
preload_link += "; crossorigin=#{crossorigin}" unless crossorigin.nil?
|
151
|
+
preload_link += "; integrity=#{integrity}" unless integrity.nil?
|
152
|
+
preload_link += "; nopush" if nopush
|
153
|
+
preload_links << preload_link
|
154
|
+
end
|
113
155
|
tag_options = {
|
114
156
|
"rel" => "stylesheet",
|
115
|
-
"
|
157
|
+
"crossorigin" => crossorigin,
|
116
158
|
"href" => href
|
117
|
-
}.merge!(options)
|
118
|
-
|
119
|
-
|
120
|
-
if tag_options["integrity"] == true
|
121
|
-
tag_options["integrity"] = asset_integrity(source.to_s.delete_suffix('.css')+'.css')
|
122
|
-
elsif tag_options["integrity"] == false
|
123
|
-
tag_options.delete('integrity')
|
124
|
-
end
|
125
|
-
else
|
126
|
-
tag_options.delete('integrity')
|
159
|
+
}.merge!(options.except('integrity'))
|
160
|
+
if tag_options["nonce"] == true
|
161
|
+
tag_options["nonce"] = content_security_policy_nonce
|
127
162
|
end
|
163
|
+
tag_options['integrity'] = integrity if integrity
|
128
164
|
|
165
|
+
if apply_stylesheet_media_default && tag_options["media"].blank?
|
166
|
+
tag_options["media"] = "screen"
|
167
|
+
end
|
168
|
+
|
129
169
|
tag(:link, tag_options)
|
130
170
|
}.join("\n").html_safe
|
131
171
|
|
132
|
-
|
172
|
+
if use_preload_links_header
|
173
|
+
send_preload_links_header(preload_links)
|
174
|
+
end
|
133
175
|
|
134
176
|
sources_tags
|
135
177
|
end
|
@@ -175,13 +217,16 @@ module Condenser::Rails
|
|
175
217
|
end
|
176
218
|
|
177
219
|
def asset_path(path)
|
178
|
-
@manifest[path][
|
220
|
+
@manifest[path][:path]
|
179
221
|
end
|
180
222
|
|
181
223
|
def integrity(path)
|
182
|
-
@manifest[path][
|
224
|
+
@manifest[path]&.[](:integrity)
|
183
225
|
end
|
184
226
|
|
227
|
+
def type(path)
|
228
|
+
@manifest[path]&.[](:type)
|
229
|
+
end
|
185
230
|
end
|
186
231
|
|
187
232
|
class Environment #:nodoc:
|
@@ -201,7 +246,11 @@ module Condenser::Rails
|
|
201
246
|
end
|
202
247
|
|
203
248
|
def integrity(path)
|
204
|
-
@env.find(path)&.integrity
|
249
|
+
@env.find(path)&.export&.integrity
|
250
|
+
end
|
251
|
+
|
252
|
+
def type(path)
|
253
|
+
@env.find(path)&.export&.type
|
205
254
|
end
|
206
255
|
|
207
256
|
private
|
data/lib/condenser/rails/task.rb
CHANGED
data/lib/condenser/rails.rb
CHANGED
data/lib/condenser/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails'
|
2
4
|
require 'rails/railtie'
|
3
5
|
require 'action_controller/railtie'
|
@@ -58,14 +60,9 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
module SassFunctions
|
62
|
-
def asset_path(path, options = {})
|
63
|
-
SassC::Script::Value::String.new(condenser_context.asset_path(path.value, options), :string)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
63
|
config.assets = OrderedOptions.new
|
68
64
|
config.assets._blocks = []
|
65
|
+
config.assets._pipeline = nil
|
69
66
|
config.assets.path = []
|
70
67
|
config.assets.precompile = %w(application.css application.js **/*.jpg **/*.png **/*.gif)
|
71
68
|
config.assets.prefix = "/assets"
|
@@ -73,7 +70,7 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
73
70
|
|
74
71
|
config.assets.compile = true
|
75
72
|
config.assets.digest = true
|
76
|
-
config.assets.cache_limit =
|
73
|
+
config.assets.cache_limit = 1_000.megabytes
|
77
74
|
config.assets.compressors = [:zlib]
|
78
75
|
|
79
76
|
config.assets.configure do |app, env|
|
@@ -128,18 +125,10 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
128
125
|
config = app.config
|
129
126
|
|
130
127
|
if config.assets._pipeline
|
131
|
-
|
128
|
+
config.assets._pipeline.call(env)
|
132
129
|
else
|
133
|
-
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new
|
134
|
-
|
135
|
-
})
|
136
|
-
|
137
|
-
if ::Rails.env == 'development'
|
138
|
-
env.register_preprocessor 'application/javascript', Condenser::JSAnalyzer
|
139
|
-
else
|
140
|
-
env.register_preprocessor 'application/javascript', Condenser::BabelProcessor
|
141
|
-
end
|
142
|
-
|
130
|
+
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new
|
131
|
+
env.register_preprocessor 'application/javascript', Condenser::JSAnalyzer
|
143
132
|
env.register_exporter 'application/javascript', Condenser::RollupProcessor
|
144
133
|
|
145
134
|
if ::Rails.env != 'development'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condenser-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: condenser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.5.21
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: Condenser integration for Rails
|