condenser-rails 0.0.7
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 +2 -0
- data/lib/condenser/rails.rb +4 -0
- data/lib/condenser/rails/context.rb +28 -0
- data/lib/condenser/rails/helper.rb +215 -0
- data/lib/condenser/rails/task.rb +87 -0
- data/lib/condenser/rails/utils.rb +75 -0
- data/lib/condenser/rails/version.rb +5 -0
- data/lib/condenser/railtie.rb +232 -0
- metadata +177 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cbfbac2077b8f13f5a08ab9fff144495ee2ef3f76ea092ba230e8400bd2a7ef6
|
|
4
|
+
data.tar.gz: d2bf8e75d7c1dac414cf6a00de690d1be3b3e3259d1142c2eb157ba8752122ff
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cded87c625d07addcc40e13b368509d269433d918d2fb6d029a713ecdd5f4417a362698e6a166b9d140d5062000270e2496ac1c04d5f3962753147c5d67db531
|
|
7
|
+
data.tar.gz: e4d865e2b28063a24f1b0e7a11b223584bc480cb95936221ef741663788b7c8bc2ce45c6980845f7b3f4bad154b6215575f42eb8a52ebe1bb3bde9d129a4f827
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Jon Bracy
|
|
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,28 @@
|
|
|
1
|
+
require 'action_view/helpers'
|
|
2
|
+
require 'condenser'
|
|
3
|
+
|
|
4
|
+
class Condenser
|
|
5
|
+
module Rails
|
|
6
|
+
|
|
7
|
+
module Context
|
|
8
|
+
include ActionView::Helpers::AssetUrlHelper
|
|
9
|
+
include ActionView::Helpers::AssetTagHelper
|
|
10
|
+
|
|
11
|
+
def self.included(klass)
|
|
12
|
+
klass.class_eval do
|
|
13
|
+
class_attribute :config, :assets_prefix
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def compute_asset_path(path, options = {})
|
|
18
|
+
if asset = environment.find(path)
|
|
19
|
+
@dependencies << asset.source_file
|
|
20
|
+
File.join(assets_prefix || "/", asset.path)
|
|
21
|
+
else
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
require 'action_view'
|
|
2
|
+
require 'condenser'
|
|
3
|
+
require 'active_support/core_ext/class/attribute'
|
|
4
|
+
|
|
5
|
+
module Condenser::Rails
|
|
6
|
+
|
|
7
|
+
class AssetNotFound < StandardError; end
|
|
8
|
+
class AssetNotPrecompiled < StandardError; end
|
|
9
|
+
class AssetNotPrecompiledError < AssetNotPrecompiled
|
|
10
|
+
def initialize(source)
|
|
11
|
+
super(<<~MSG)
|
|
12
|
+
Asset was not declared to be precompiled in production. Add
|
|
13
|
+
`Rails.application.config.assets.precompile += %w( #{source} )` to
|
|
14
|
+
`config/initializers/assets.rb` and restart your server
|
|
15
|
+
MSG
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Helper
|
|
20
|
+
include ActionView::Helpers::AssetUrlHelper
|
|
21
|
+
include ActionView::Helpers::AssetTagHelper
|
|
22
|
+
|
|
23
|
+
VIEW_ACCESSORS = [
|
|
24
|
+
:assets, :assets_manifest, :assets_precompiled,
|
|
25
|
+
:assets_precompiled_regexes, :assets_prefix, :resolve_assets_with
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
def self.included(klass)
|
|
29
|
+
klass.class_attribute(*VIEW_ACCESSORS)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.extended(obj)
|
|
33
|
+
obj.class_eval do
|
|
34
|
+
attr_accessor(*VIEW_ACCESSORS)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path
|
|
39
|
+
# to use the asset pipeline.
|
|
40
|
+
def compute_asset_path(path, options = {})
|
|
41
|
+
if asset_path = resolve_asset_path(path)
|
|
42
|
+
File.join(assets_prefix || "/", asset_path)
|
|
43
|
+
else
|
|
44
|
+
raise Condenser::Rails::AssetNotPrecompiledError.new(path)
|
|
45
|
+
# raise AssetNotFound, "The asset #{ path.inspect } is not present in the asset pipeline.\n"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Resolve the asset path against the Condenser manifest or environment.
|
|
50
|
+
# Returns nil if it's an asset we don't know about.
|
|
51
|
+
def resolve_asset_path(path) #:nodoc:
|
|
52
|
+
asset_resolver.asset_path(path)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Get integrity for asset path.
|
|
56
|
+
#
|
|
57
|
+
# path - String path
|
|
58
|
+
# options - Hash options
|
|
59
|
+
#
|
|
60
|
+
# Returns String integrity attribute or nil if no asset was found.
|
|
61
|
+
def asset_integrity(path, options = {})
|
|
62
|
+
asset_resolver.integrity(path)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Override javascript tag helper to provide debugging support.
|
|
66
|
+
#
|
|
67
|
+
# Eventually will be deprecated and replaced by source maps.
|
|
68
|
+
def javascript_include_tag(*sources)
|
|
69
|
+
options = sources.extract_options!.stringify_keys
|
|
70
|
+
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
|
71
|
+
early_hints_links = []
|
|
72
|
+
|
|
73
|
+
sources_tags = sources.uniq.map { |source|
|
|
74
|
+
href = path_to_javascript(source, path_options)
|
|
75
|
+
early_hints_links << "<#{href}>; rel=preload; as=script"
|
|
76
|
+
tag_options = {
|
|
77
|
+
"src" => href
|
|
78
|
+
}.merge!(options)
|
|
79
|
+
|
|
80
|
+
if tag_options["nonce"] == true
|
|
81
|
+
tag_options["nonce"] = content_security_policy_nonce
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if secure_subresource_integrity_context?
|
|
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
|
|
93
|
+
|
|
94
|
+
content_tag("script", "", tag_options)
|
|
95
|
+
}.join("\n").html_safe
|
|
96
|
+
|
|
97
|
+
request.send_early_hints("Link" => early_hints_links.join("\n")) if respond_to?(:request) && request
|
|
98
|
+
|
|
99
|
+
sources_tags
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Override stylesheet tag helper to provide debugging support.
|
|
103
|
+
#
|
|
104
|
+
# Eventually will be deprecated and replaced by source maps.
|
|
105
|
+
def stylesheet_link_tag(*sources)
|
|
106
|
+
options = sources.extract_options!.stringify_keys
|
|
107
|
+
path_options = options.extract!("protocol", "host", "skip_pipeline").symbolize_keys
|
|
108
|
+
early_hints_links = []
|
|
109
|
+
|
|
110
|
+
sources_tags = sources.uniq.map { |source|
|
|
111
|
+
href = path_to_stylesheet(source, path_options)
|
|
112
|
+
early_hints_links << "<#{href}>; rel=preload; as=style"
|
|
113
|
+
tag_options = {
|
|
114
|
+
"rel" => "stylesheet",
|
|
115
|
+
"media" => "screen",
|
|
116
|
+
"href" => href
|
|
117
|
+
}.merge!(options)
|
|
118
|
+
|
|
119
|
+
if secure_subresource_integrity_context?
|
|
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')
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
tag(:link, tag_options)
|
|
130
|
+
}.join("\n").html_safe
|
|
131
|
+
|
|
132
|
+
request.send_early_hints("Link" => early_hints_links.join("\n")) if respond_to?(:request) && request
|
|
133
|
+
|
|
134
|
+
sources_tags
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
protected
|
|
138
|
+
# Only serve integrity metadata for HTTPS requests:
|
|
139
|
+
# http://www.w3.org/TR/SRI/#non-secure-contexts-remain-non-secure
|
|
140
|
+
def secure_subresource_integrity_context?
|
|
141
|
+
self.request.nil? || self.request && (self.request.local? || self.request.ssl?)
|
|
142
|
+
# respond_to?(:request) && self.request && (self.request.local? || self.request.ssl?)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# compute_asset_extname is in AV::Helpers::AssetUrlHelper
|
|
146
|
+
def path_with_extname(path, options)
|
|
147
|
+
path = path.to_s
|
|
148
|
+
"#{path}#{compute_asset_extname(path, options)}"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Try each asset resolver and return the first non-nil result.
|
|
152
|
+
def asset_resolver
|
|
153
|
+
@asset_resolver ||= HelperAssetResolvers[resolve_assets_with].new(self)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Use a separate module since Helper is mixed in and we needn't pollute
|
|
158
|
+
# the class namespace with our internals.
|
|
159
|
+
module HelperAssetResolvers #:nodoc:
|
|
160
|
+
def self.[](name)
|
|
161
|
+
case name
|
|
162
|
+
when :manifest
|
|
163
|
+
Manifest
|
|
164
|
+
when :environment
|
|
165
|
+
Environment
|
|
166
|
+
else
|
|
167
|
+
raise ArgumentError, "Unrecognized asset resolver: #{name.inspect}. Expected :manifest or :environment"
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class Manifest #:nodoc:
|
|
172
|
+
def initialize(view)
|
|
173
|
+
@manifest = view.assets_manifest
|
|
174
|
+
raise ArgumentError, 'config.assets.resolve_with includes :manifest, but app.assets_manifest is nil' unless @manifest
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def asset_path(path)
|
|
178
|
+
@manifest[path]['path']
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def integrity(path)
|
|
182
|
+
@manifest[path]['integrity']
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
class Environment #:nodoc:
|
|
188
|
+
def initialize(view)
|
|
189
|
+
raise ArgumentError, 'config.assets.resolve_with includes :environment, but app.assets is nil' unless view.assets
|
|
190
|
+
@env = view.assets
|
|
191
|
+
@precompiled_assets = view.assets_precompiled_regexes
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def asset_path(path)
|
|
195
|
+
if asset = @env.find(path)
|
|
196
|
+
if !precompiled?(asset.filename)
|
|
197
|
+
raise Condenser::Rails::AssetNotPrecompiledError.new(asset.filename)
|
|
198
|
+
end
|
|
199
|
+
asset.export.path
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def integrity(path)
|
|
204
|
+
@env.find(path)&.integrity
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
private
|
|
208
|
+
|
|
209
|
+
def precompiled?(path)
|
|
210
|
+
@precompiled_assets.find { |glob| glob =~ path }
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/condensertask'
|
|
3
|
+
require 'condenser'
|
|
4
|
+
# require 'action_view'
|
|
5
|
+
# require 'action_view/base'
|
|
6
|
+
|
|
7
|
+
module Condenser::Rails
|
|
8
|
+
class Task < Rake::CondenserTask
|
|
9
|
+
attr_accessor :app
|
|
10
|
+
|
|
11
|
+
def initialize(app = nil)
|
|
12
|
+
self.app = app
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def environment
|
|
17
|
+
if app
|
|
18
|
+
# Use initialized app.assets or force build an environment if
|
|
19
|
+
# config.assets.compile is disabled
|
|
20
|
+
app.assets || Condenser::Railtie.build_environment(app)
|
|
21
|
+
else
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def output
|
|
27
|
+
if app
|
|
28
|
+
config = app.config
|
|
29
|
+
File.join(config.paths['public'].first, config.assets.prefix)
|
|
30
|
+
else
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def assets
|
|
36
|
+
if app
|
|
37
|
+
app.config.assets.precompile
|
|
38
|
+
else
|
|
39
|
+
super
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def manifest
|
|
44
|
+
if app
|
|
45
|
+
Condenser::Manifest.new(environment, output, app.config.assets.manifest)
|
|
46
|
+
else
|
|
47
|
+
super
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def define
|
|
52
|
+
namespace :assets do
|
|
53
|
+
%w( environment precompile clean clobber ).each do |task|
|
|
54
|
+
Rake::Task[task].clear if Rake::Task.task_defined?(task)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Override this task change the loaded dependencies
|
|
58
|
+
desc "Load asset compile environment"
|
|
59
|
+
task :environment do
|
|
60
|
+
# Load full Rails environment by default
|
|
61
|
+
Rake::Task['environment'].invoke
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc "Compile all the assets named in config.assets.precompile"
|
|
65
|
+
task :precompile => :environment do
|
|
66
|
+
with_logger do
|
|
67
|
+
manifest.compile(assets)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
desc "Remove old compiled assets"
|
|
72
|
+
task :clean, [:keep] => :environment do |t, args|
|
|
73
|
+
with_logger do
|
|
74
|
+
manifest.clean #Integer(args.keep || self.keep)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "Remove compiled assets"
|
|
79
|
+
task :clobber => :environment do
|
|
80
|
+
with_logger do
|
|
81
|
+
manifest.clobber
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# based on http://cpan.uwinnipeg.ca/htdocs/Text-Glob/Text/Glob.pm.html#glob_to_regex_string from https://github.com/alexch/rerun/blob/master/lib/rerun/glob.rb
|
|
2
|
+
|
|
3
|
+
module Condenser::Rails
|
|
4
|
+
module Utils
|
|
5
|
+
NO_LEADING_DOT = '(?=[^\.])' # todo
|
|
6
|
+
START_OF_FILENAME = '(\A|\/)' # beginning of string or a slash
|
|
7
|
+
END_OF_STRING = '\z'
|
|
8
|
+
|
|
9
|
+
def self.smoosh chars
|
|
10
|
+
out = []
|
|
11
|
+
until chars.empty?
|
|
12
|
+
char = chars.shift
|
|
13
|
+
if char == "*" and chars.first == "*"
|
|
14
|
+
chars.shift
|
|
15
|
+
chars.shift if chars.first == "/"
|
|
16
|
+
out.push("**")
|
|
17
|
+
else
|
|
18
|
+
out.push(char)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
out
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.glob_to_regex(glob_string)
|
|
25
|
+
chars = smoosh(glob_string.split(''))
|
|
26
|
+
|
|
27
|
+
curlies = 0
|
|
28
|
+
escaping = false
|
|
29
|
+
string = chars.map do |char|
|
|
30
|
+
if escaping
|
|
31
|
+
escaping = false
|
|
32
|
+
char
|
|
33
|
+
else
|
|
34
|
+
case char
|
|
35
|
+
when '**'
|
|
36
|
+
"([^/]+/)*"
|
|
37
|
+
when '*'
|
|
38
|
+
".*"
|
|
39
|
+
when "?"
|
|
40
|
+
"."
|
|
41
|
+
when "."
|
|
42
|
+
"\\."
|
|
43
|
+
|
|
44
|
+
when "{"
|
|
45
|
+
curlies += 1
|
|
46
|
+
"("
|
|
47
|
+
when "}"
|
|
48
|
+
if curlies > 0
|
|
49
|
+
curlies -= 1
|
|
50
|
+
")"
|
|
51
|
+
else
|
|
52
|
+
char
|
|
53
|
+
end
|
|
54
|
+
when ","
|
|
55
|
+
if curlies > 0
|
|
56
|
+
"|"
|
|
57
|
+
else
|
|
58
|
+
char
|
|
59
|
+
end
|
|
60
|
+
when "\\"
|
|
61
|
+
escaping = true
|
|
62
|
+
"\\"
|
|
63
|
+
|
|
64
|
+
else
|
|
65
|
+
char
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end.join
|
|
70
|
+
|
|
71
|
+
Regexp.new(START_OF_FILENAME + string + END_OF_STRING)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
require 'rails'
|
|
2
|
+
require 'rails/railtie'
|
|
3
|
+
require 'action_controller/railtie'
|
|
4
|
+
require 'active_support/core_ext/module/remove_method'
|
|
5
|
+
require 'active_support/core_ext/numeric/bytes'
|
|
6
|
+
require 'condenser'
|
|
7
|
+
require 'condenser/rails/utils'
|
|
8
|
+
require 'condenser/rails/context'
|
|
9
|
+
require 'condenser/rails/helper'
|
|
10
|
+
require 'condenser/rails/version'
|
|
11
|
+
# require 'sprockets/rails/quiet_assets'
|
|
12
|
+
# require 'sprockets/rails/route_wrapper'
|
|
13
|
+
|
|
14
|
+
module Rails
|
|
15
|
+
class Application
|
|
16
|
+
|
|
17
|
+
# Undefine Rails' assets method before redefining it, to avoid warnings.
|
|
18
|
+
remove_possible_method :assets
|
|
19
|
+
remove_possible_method :assets=
|
|
20
|
+
|
|
21
|
+
# Returns Condenser::Manifest for app config.
|
|
22
|
+
attr_accessor :assets
|
|
23
|
+
|
|
24
|
+
# Returns Condenser::Manifest for app config.
|
|
25
|
+
attr_accessor :assets_manifest
|
|
26
|
+
|
|
27
|
+
# Called from asset helpers to alert you if you reference an asset URL that
|
|
28
|
+
# isn't precompiled and hence won't be available in production.
|
|
29
|
+
def asset_precompiled?(logical_path)
|
|
30
|
+
precompiled_assets.find { |glob| glob =~ logical_path }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Lazy-load the precompile list so we don't cause asset compilation at app
|
|
34
|
+
# boot time, but ensure we cache the list so we don't recompute it for each
|
|
35
|
+
# request or test case.
|
|
36
|
+
def precompiled_assets
|
|
37
|
+
@precompiled_assets ||= config.assets.precompile.map { |s| Condenser::Rails::Utils.glob_to_regex(s) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Engine < Railtie
|
|
42
|
+
initializer :append_assets_path, group: :all do |app|
|
|
43
|
+
app.config.assets.path.unshift(*paths["vendor/assets"].existent_directories)
|
|
44
|
+
app.config.assets.path.unshift(*paths["lib/assets"].existent_directories)
|
|
45
|
+
app.config.assets.path.unshift(*paths["app/assets"].existent_directories)
|
|
46
|
+
app.config.assets.npm_path = app.root.join('node_modules').to_s
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Condenser::Railtie < ::Rails::Railtie
|
|
52
|
+
|
|
53
|
+
class OrderedOptions < ActiveSupport::OrderedOptions
|
|
54
|
+
def configure(&block)
|
|
55
|
+
self._blocks << block
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module SassFunctions
|
|
60
|
+
def asset_path(path, options = {})
|
|
61
|
+
SassC::Script::Value::String.new(condenser_context.asset_path(path.value, options), :string)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
config.assets = OrderedOptions.new
|
|
66
|
+
config.assets._blocks = []
|
|
67
|
+
config.assets.path = []
|
|
68
|
+
config.assets.precompile = %w(application.css application.js **/*.jpg **/*.png **/*.gif)
|
|
69
|
+
config.assets.prefix = "/assets"
|
|
70
|
+
config.assets.quiet = false
|
|
71
|
+
|
|
72
|
+
# initializer :quiet_assets do |app|
|
|
73
|
+
# if app.config.assets.quiet
|
|
74
|
+
# app.middleware.insert_before ::Rails::Rack::Logger, ::Condenser::Rails::QuietAssets
|
|
75
|
+
# end
|
|
76
|
+
# end
|
|
77
|
+
|
|
78
|
+
# config.assets.version = ""
|
|
79
|
+
config.assets.compile = true
|
|
80
|
+
config.assets.digest = true
|
|
81
|
+
config.assets.cache_limit = 50.megabytes
|
|
82
|
+
config.assets.compressors = [:zlib]
|
|
83
|
+
|
|
84
|
+
config.assets.configure do |app, env|
|
|
85
|
+
config.assets.path.each { |path| env.append_path(path) }
|
|
86
|
+
if config.assets.npm_path && File.directory?(config.assets.npm_path)
|
|
87
|
+
env.append_npm_path(config.assets.npm_path)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
config.assets.configure do |app, env|
|
|
92
|
+
env.context_class.send :include, ::Condenser::Rails::Context
|
|
93
|
+
env.context_class.assets_prefix = config.assets.prefix
|
|
94
|
+
env.context_class.config = config.action_controller
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
config.assets.configure do |app, env|
|
|
98
|
+
env.cache = Condenser::Cache::FileStore.new(
|
|
99
|
+
File.join(app.root, 'tmp', 'cache', 'assets', Rails.env),
|
|
100
|
+
size: config.assets.cache_limit,
|
|
101
|
+
logger: env.logger
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Sprockets.register_dependency_resolver 'rails-env' do
|
|
106
|
+
# ::Rails.env.to_s
|
|
107
|
+
# end
|
|
108
|
+
|
|
109
|
+
# config.assets.configure do |env|
|
|
110
|
+
# env.depend_on 'rails-env'
|
|
111
|
+
# end
|
|
112
|
+
|
|
113
|
+
# config.assets.configure do |app, env|
|
|
114
|
+
# env.version = config.assets.version
|
|
115
|
+
# end
|
|
116
|
+
|
|
117
|
+
rake_tasks do |app|
|
|
118
|
+
require 'condenser/rails/task'
|
|
119
|
+
Condenser::Rails::Task.new(app)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def resolve_minifier(value)
|
|
123
|
+
if value.is_a?(Symbol) || value.is_a?(String)
|
|
124
|
+
"Condenser::#{value.to_s.camelize}Minifier".constantize
|
|
125
|
+
else
|
|
126
|
+
value
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def resolve_writer(value)
|
|
131
|
+
if value.is_a?(Symbol) || value.is_a?(String)
|
|
132
|
+
"Condenser::#{value.to_s.camelize}Writer".constantize.new
|
|
133
|
+
else
|
|
134
|
+
value
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def build_environment(app, initialized = nil)
|
|
139
|
+
initialized = app.initialized? if initialized.nil?
|
|
140
|
+
unless initialized
|
|
141
|
+
::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
env = Condenser.new(pipeline: false)
|
|
145
|
+
config = app.config
|
|
146
|
+
|
|
147
|
+
# Run app.assets.configure blocks
|
|
148
|
+
config.assets._blocks.each do |block|
|
|
149
|
+
block.call(app, env)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new({
|
|
153
|
+
functions: Condenser::Railtie::SassFunctions
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
# Set compressors after the configure blocks since they can
|
|
157
|
+
# define new compressors and we only accept existent compressors.
|
|
158
|
+
env.register_preprocessor 'application/javascript', Condenser::BabelProcessor
|
|
159
|
+
env.register_exporter 'application/javascript', Condenser::RollupProcessor
|
|
160
|
+
|
|
161
|
+
env.register_minifier 'application/javascript', resolve_minifier(config.assets.js_minifier)
|
|
162
|
+
env.register_minifier 'text/css', resolve_minifier(config.assets.css_minifier)
|
|
163
|
+
|
|
164
|
+
env.register_writer Condenser::FileWriter.new
|
|
165
|
+
config.assets.compressors&.each do |writer|
|
|
166
|
+
env.register_writer resolve_writer(writer)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# No more configuration changes at this point.
|
|
170
|
+
# With cache classes on, Sprockets won't check the FS when files
|
|
171
|
+
# change. Preferable in production when the FS only changes on
|
|
172
|
+
# deploys when the app restarts.
|
|
173
|
+
if config.cache_classes
|
|
174
|
+
env = env.cached
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
env
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def self.build_manifest(app)
|
|
181
|
+
config = app.config
|
|
182
|
+
|
|
183
|
+
path = File.join(config.paths['public'].first, config.assets.prefix)
|
|
184
|
+
Condenser::Manifest.new(app.assets, path, config.assets.manifest || app.root.join('config', 'assets.json'))
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
config.after_initialize do |app|
|
|
188
|
+
config = app.config
|
|
189
|
+
|
|
190
|
+
if config.assets.compile
|
|
191
|
+
config.assets.precompile
|
|
192
|
+
require 'condenser/server'
|
|
193
|
+
app.assets = self.build_environment(app, true)
|
|
194
|
+
app.routes.prepend do
|
|
195
|
+
mount Condenser::Server.new(app.assets, logger: Rails.logger) => config.assets.prefix
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
app.assets_manifest = build_manifest(app)
|
|
200
|
+
|
|
201
|
+
if config.assets.resolve_with.nil?
|
|
202
|
+
config.assets.resolve_with = if config.assets.compile
|
|
203
|
+
:environment
|
|
204
|
+
else
|
|
205
|
+
:manifest
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# ActionDispatch::Routing::RouteWrapper.class_eval do
|
|
210
|
+
# class_attribute :assets_prefix
|
|
211
|
+
#
|
|
212
|
+
# self.assets_prefix = config.assets.prefix
|
|
213
|
+
# end
|
|
214
|
+
|
|
215
|
+
ActiveSupport.on_load(:action_view) do
|
|
216
|
+
include ::Condenser::Rails::Helper
|
|
217
|
+
|
|
218
|
+
# Copy relevant config to AV context
|
|
219
|
+
self.assets_prefix = config.assets.prefix
|
|
220
|
+
if config.assets.compile
|
|
221
|
+
self.assets_precompiled = config.assets.precompile
|
|
222
|
+
self.assets_precompiled_regexes = app.precompiled_assets
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
self.assets = app.assets
|
|
226
|
+
self.assets_manifest = app.assets_manifest
|
|
227
|
+
|
|
228
|
+
self.resolve_assets_with = config.assets.resolve_with
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: condenser-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.7
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jonathan Bracy
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: condenser
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.0.7
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.0.7
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: actionpack
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '6.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '6.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activesupport
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '6.0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '6.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: railties
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '6.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '6.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: sassc
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: uglifier
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: minitest-reporters
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
description:
|
|
140
|
+
email: jonbracy@gmail.com
|
|
141
|
+
executables: []
|
|
142
|
+
extensions: []
|
|
143
|
+
extra_rdoc_files: []
|
|
144
|
+
files:
|
|
145
|
+
- LICENSE
|
|
146
|
+
- README.md
|
|
147
|
+
- lib/condenser/rails.rb
|
|
148
|
+
- lib/condenser/rails/context.rb
|
|
149
|
+
- lib/condenser/rails/helper.rb
|
|
150
|
+
- lib/condenser/rails/task.rb
|
|
151
|
+
- lib/condenser/rails/utils.rb
|
|
152
|
+
- lib/condenser/rails/version.rb
|
|
153
|
+
- lib/condenser/railtie.rb
|
|
154
|
+
homepage: https://github.com/malomalo/condenser-rails
|
|
155
|
+
licenses:
|
|
156
|
+
- MIT
|
|
157
|
+
metadata: {}
|
|
158
|
+
post_install_message:
|
|
159
|
+
rdoc_options: []
|
|
160
|
+
require_paths:
|
|
161
|
+
- lib
|
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: 2.5.0
|
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
|
+
requirements:
|
|
169
|
+
- - ">="
|
|
170
|
+
- !ruby/object:Gem::Version
|
|
171
|
+
version: '0'
|
|
172
|
+
requirements: []
|
|
173
|
+
rubygems_version: 3.0.3
|
|
174
|
+
signing_key:
|
|
175
|
+
specification_version: 4
|
|
176
|
+
summary: Condenser integration for Rails
|
|
177
|
+
test_files: []
|