jekyll-assets 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -204,8 +204,8 @@ module Jekyll
204
204
  env = ctx.registers[:site].sprockets
205
205
 
206
206
  env.logger.error e.message
207
- env.logger.efile env.strip_paths(e.backtrace.first)
208
- env.logger.error "error from file #{args[:argv1]}"
207
+ env.logger.err_file env.strip_paths(e.backtrace.first)
208
+ env.logger.error "error from file #{args[:argv1]}" if args
209
209
  raise e.class, "Sass Error"
210
210
  end
211
211
  end
@@ -5,16 +5,37 @@
5
5
  module Jekyll
6
6
  module Assets
7
7
  module Utils
8
+ def self.old_sprockets?
9
+ @old_sprockets ||= begin
10
+ Gem::Version.new(Sprockets::VERSION) < Gem::Version.new("4.0.beta")
11
+ end
12
+ end
13
+
14
+ # --
15
+ def self.new_uglifier?
16
+ require "uglifier"
17
+ modern_supported_version = "4.0.0"
18
+ Gem::Version.new(Uglifier::VERSION) >= Gem::Version
19
+ .new(modern_supported_version)
20
+ rescue LoadError
21
+ return true
22
+ end
23
+
24
+ # --
8
25
  def self.activate(gem)
9
- return unless Gem::Specification.find_all_by_name(gem)&.any? ||
10
- Gem::Specification.find_by_path(gem)&.any?
26
+ spec = Gem::Specification
27
+ return unless spec.find_all_by_name(gem)&.any? || \
28
+ spec.find_by_path(gem)&.any?
11
29
 
12
30
  require gem
13
31
  if block_given?
14
32
  yield
15
33
  end
34
+
35
+ true
16
36
  end
17
37
 
38
+ # --
18
39
  def self.html_fragment(*a)
19
40
  Nokogiri::HTML.fragment(*a) do |c|
20
41
  c.options = Nokogiri::XML::ParseOptions::NONET | \
@@ -37,6 +58,7 @@ module Jekyll
37
58
  end
38
59
  end
39
60
 
61
+ # --
40
62
  def raw_precompiles
41
63
  asset_config[:raw_precompile].each_with_object([]) do |v, a|
42
64
  if v.is_a?(Hash)
@@ -89,9 +111,8 @@ module Jekyll
89
111
  # --
90
112
  def url_asset(url, type:)
91
113
  name = File.basename(url)
92
- old_ = Env.old_sprockets?
93
114
 
94
- Url.new(*[old_ ? self : nil, {
115
+ Url.new(*[Utils.old_sprockets? ? self : nil, {
95
116
  name: name,
96
117
  filename: url,
97
118
  content_type: type,
@@ -148,25 +169,21 @@ module Jekyll
148
169
  case true
149
170
  when obj.is_a?(Hash) || obj.is_a?(Liquid::Tag::Parser)
150
171
  obj.each_key.with_object(obj) do |k, o|
151
- if o[k].is_a?(String)
152
- then o[k] = parse_liquid(o[k], {
153
- ctx: ctx,
154
- })
155
- end
172
+ o[k] = parse_liquid(o[k], {
173
+ ctx: ctx,
174
+ })
156
175
  end
157
176
  when obj.is_a?(Array)
158
177
  obj.map do |v|
159
- if v.is_a?(String)
160
- then v = parse_liquid(v, {
161
- ctx: ctx,
162
- })
163
- end
164
-
165
- v
178
+ parse_liquid(v, {
179
+ ctx: ctx,
180
+ })
166
181
  end
167
- else
182
+ when obj.is_a?(String)
168
183
  ctx.registers[:site].liquid_renderer.file("(asset:var)")
169
184
  .parse(obj).render!(ctx)
185
+ else
186
+ obj
170
187
  end
171
188
  end
172
189
 
@@ -317,7 +334,7 @@ module Jekyll
317
334
  end
318
335
  end
319
336
  rescue ExecJS::RuntimeUnavailable
320
- nil
337
+ false
321
338
  end
322
339
  end
323
340
  end
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Jekyll
6
6
  module Assets
7
- VERSION = "3.0.7"
7
+ VERSION = "3.0.8"
8
8
  end
9
9
  end
@@ -2,45 +2,42 @@
2
2
  # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
- module SprocketsExportersFileExporterPatches
6
- def skip?(logger)
7
- return true if File.exist?(target)
8
- logger.debug "Writing asset to #{target}"
9
- false
10
- end
11
-
12
- # --
13
- def call
14
- before_hook(asset, env: environment)
15
- after_hook(out = super, {
16
- env: environment, asset: asset
17
- })
5
+ if defined?(Sprockets::Exporters)
6
+ module SprocketsWriterPatches
7
+ def skip?(logger)
8
+ return true if File.exist?(target)
9
+ logger.debug "Writing asset to #{target}"
10
+ false
11
+ end
18
12
 
19
- out
20
- end
13
+ # --
14
+ def call
15
+ before_hook(asset, env: environment)
16
+ after_hook(out = super, {
17
+ env: environment, asset: asset
18
+ })
21
19
 
22
- # --
23
- private
24
- def before_hook(asset, env:)
25
- Jekyll::Assets::Hook.trigger :asset, :before_write do |v|
26
- v.call(asset, env)
20
+ out
27
21
  end
28
- end
29
22
 
30
- # --
31
- private
32
- def after_hook(out, asset:, env:)
33
- Jekyll::Assets::Hook.trigger :asset, :after_write do |v|
34
- v.call(out, asset, env)
23
+ # --
24
+ private
25
+ def before_hook(asset, env:)
26
+ Jekyll::Assets::Hook.trigger :asset, :before_write do |v|
27
+ v.call(asset, env)
28
+ end
35
29
  end
36
- end
37
- end
38
30
 
39
- # --
40
- module Sprockets
41
- module Exporters
42
- class FileExporter
43
- prepend SprocketsExportersFileExporterPatches
31
+ # --
32
+ private
33
+ def after_hook(out, asset:, env:)
34
+ Jekyll::Assets::Hook.trigger :asset, :after_write do |v|
35
+ v.call(out, asset, env)
36
+ end
44
37
  end
45
38
  end
39
+
40
+ # --
41
+ Sprockets::Exporters::FileExporter.send \
42
+ :prepend, SprocketsWriterPatches
46
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-29 00:00:00.000000000 Z
13
+ date: 2018-03-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: execjs
@@ -202,6 +202,9 @@ files:
202
202
  - Rakefile
203
203
  - lib/jekyll-assets.rb
204
204
  - lib/jekyll/assets.rb
205
+ - lib/jekyll/assets/compressors/sassc.rb
206
+ - lib/jekyll/assets/compressors/scss.rb
207
+ - lib/jekyll/assets/compressors/uglify.rb
205
208
  - lib/jekyll/assets/config.rb
206
209
  - lib/jekyll/assets/context.rb
207
210
  - lib/jekyll/assets/default.rb
@@ -213,10 +216,6 @@ files:
213
216
  - lib/jekyll/assets/html.rb
214
217
  - lib/jekyll/assets/logger.rb
215
218
  - lib/jekyll/assets/manifest.rb
216
- - lib/jekyll/assets/map.rb
217
- - lib/jekyll/assets/map/css.rb
218
- - lib/jekyll/assets/map/javascript.rb
219
- - lib/jekyll/assets/map/writer.rb
220
219
  - lib/jekyll/assets/patches/asset.rb
221
220
  - lib/jekyll/assets/patches/cached.rb
222
221
  - lib/jekyll/assets/patches/find_asset.rb
@@ -224,6 +223,7 @@ files:
224
223
  - lib/jekyll/assets/patches/obsolete.rb
225
224
  - lib/jekyll/assets/patches/site.rb
226
225
  - lib/jekyll/assets/plugins.rb
226
+ - lib/jekyll/assets/plugins/alternates.rb
227
227
  - lib/jekyll/assets/plugins/bootstrap.rb
228
228
  - lib/jekyll/assets/plugins/font-awesome.rb
229
229
  - lib/jekyll/assets/plugins/frontmatter.rb
@@ -250,6 +250,10 @@ files:
250
250
  - lib/jekyll/assets/plugins/proxy/magick.rb
251
251
  - lib/jekyll/assets/plugins/proxy/optim.rb
252
252
  - lib/jekyll/assets/plugins/searcher.rb
253
+ - lib/jekyll/assets/plugins/srcmap.rb
254
+ - lib/jekyll/assets/plugins/srcmap/css.rb
255
+ - lib/jekyll/assets/plugins/srcmap/javascript.rb
256
+ - lib/jekyll/assets/plugins/srcmap/writer.rb
253
257
  - lib/jekyll/assets/proxy.rb
254
258
  - lib/jekyll/assets/reader.rb
255
259
  - lib/jekyll/assets/tag.rb
@@ -277,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
281
  version: '0'
278
282
  requirements: []
279
283
  rubyforge_project:
280
- rubygems_version: 2.7.4
284
+ rubygems_version: 2.7.5
281
285
  signing_key:
282
286
  specification_version: 4
283
287
  summary: Assets for Jekyll
@@ -1,57 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2018 - MIT License
3
- # Encoding: utf-8
4
-
5
- require_relative "map/css"
6
- require_relative "map/javascript"
7
- require_relative "map/writer"
8
- require "pathutil"
9
-
10
- module Jekyll
11
- module Assets
12
- module Map
13
- NAME = "%<name>s.map"
14
- DIR_NAME = "source-maps"
15
- DIR = Pathutil.new(DIR_NAME)
16
- EXT = ".map"
17
-
18
- # --
19
- # @return [String] the map name.
20
- # Take the path, and attach the map extension.
21
- # @note this just saves logic.
22
- # --
23
- def self.map_path(env:, asset:)
24
- [
25
- path({
26
- asset: asset,
27
- env: env,
28
- }),
29
- EXT,
30
- ].join
31
- end
32
-
33
- # --
34
- # @note this is used for anything in source-maps.
35
- # Strip the filename and return a relative sourcemap path.
36
- # @return [Pathutil] the path.
37
- # --
38
- def self.path(env:, asset:)
39
- DIR.join(env.strip_paths(asset.is_a?(Sprockets::Asset) ?
40
- asset.filename : asset))
41
- end
42
-
43
- # --
44
- def self.register_on(instance)
45
- return unless instance.asset_config[:source_maps]
46
- unless instance.asset_config[:compression]
47
- instance.logger.warn "Compression is ignored w/ SourceMaps"
48
- end
49
-
50
- # Register everything, so we can get this party started.
51
- [Writer, JavaScript, CSS].map { |v| v.register_on(instance) }
52
- instance.css_compressor, instance.js_compressor =
53
- :source_map, :source_map
54
- end
55
- end
56
- end
57
- end
@@ -1,43 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2018 - MIT License
3
- # Encoding: utf-8
4
-
5
- require "sprockets"
6
-
7
- module Jekyll
8
- module Assets
9
- module Map
10
- class CSS < Sprockets::SassCompressor
11
- def call(input)
12
- out = super(input)
13
- env = input[:environment]
14
- asset = env.find_asset!(input[:filename], pipeline: :source)
15
- path = asset.filename.sub(env.jekyll.in_source_dir + "/", "")
16
- url = Map.map_path(asset: asset, env: env)
17
- url = env.prefix_url(url)
18
-
19
- out.update({
20
- data: <<~CSS
21
- #{out[:data].strip}
22
- /*# sourceMappingURL=#{url} */
23
- /*# sourceURL=#{path} */
24
- CSS
25
- })
26
- end
27
-
28
- def self.register_on(instance)
29
- content_type = "text/css"
30
- instance.register_compressor content_type,
31
- :source_map, CSS
32
- end
33
- end
34
-
35
- # --
36
- # We load late in some cases.
37
- # You can also register it in a Hook.
38
- # Globally Register it.
39
- # --
40
- CSS.register_on(Sprockets)
41
- end
42
- end
43
- end
@@ -1,43 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2018 - MIT License
3
- # Encoding: utf-8
4
-
5
- require "sprockets"
6
-
7
- module Jekyll
8
- module Assets
9
- module Map
10
- class JavaScript < Sprockets::UglifierCompressor
11
- def call(input)
12
- out = super(input)
13
- env = input[:environment]
14
- asset = env.find_asset!(input[:filename], pipeline: :source)
15
- path = asset.filename.sub(env.jekyll.in_source_dir + "/", "")
16
- url = Map.map_path(asset: asset, env: env)
17
- url = env.prefix_url(url)
18
-
19
- out.update({
20
- data: <<~TXT
21
- #{input[:data].strip}
22
- //# sourceMappingURL=#{url}
23
- //# sourceURL=#{path}
24
- TXT
25
- })
26
- end
27
-
28
- def self.register_on(instance)
29
- content_type = "application/javascript"
30
- instance.register_compressor(content_type,
31
- :source_map, self)
32
- end
33
- end
34
-
35
- # --
36
- # We load late in some cases.
37
- # You can also register it in a Hook.
38
- # Globally Register it.
39
- # --
40
- JavaScript.register_on(Sprockets)
41
- end
42
- end
43
- end
@@ -1,192 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2018 - MIT License
3
- # Encoding: utf-8
4
-
5
- require "sprockets"
6
- require "pathutil"
7
-
8
- module Jekyll
9
- module Assets
10
- module Map
11
- class Writer < Sprockets::Exporters::Base
12
- alias env environment
13
-
14
- def skip?(_)
15
- !env.asset_config[:source_maps] ||
16
- !asset.metadata[:map]
17
- end
18
-
19
- # --
20
- def call
21
- clean_file!
22
- clean_sources!
23
- write_map!
24
- write_src!
25
- end
26
-
27
- # --
28
- # Provides our custom manifest key, full of files.
29
- # @note We push everything from the file we are writing to the maps.
30
- # @return [Array<String>]
31
- # --
32
- def files
33
- @files ||= begin
34
- key = "sourceMapFiles"
35
- out = env.manifest.data[key] ||= []
36
- unless Manifest.keep_keys.include?(key)
37
- Manifest.keep_keys << key
38
- end
39
-
40
- out
41
- end
42
- end
43
-
44
- # --
45
- def self.register_on(instance)
46
- instance.register_exporter("*/*", self)
47
- end
48
-
49
- # --
50
- # @return [HashWithIndifferentAccess]
51
- # @note do not modify the original map.
52
- # Provides a modifible SourceMap
53
- # --
54
- private
55
- def map
56
- @map ||= asset.metadata[:map]
57
- .with_indifferent_access
58
- end
59
-
60
- # --
61
- # @return [HashWithIndifferentAccess]
62
- # @note this is frozen so you can't modify.
63
- # Provides an unmodifiable SourceMap
64
- # --
65
- private
66
- def original_map
67
- @original_map ||= asset.metadata[:map]
68
- .with_indifferent_access.freeze
69
- end
70
-
71
- # --
72
- # @note something like _assets/*
73
- # Makes sure that the name sits in the asset path.
74
- # @return [String]
75
- # --
76
- private
77
- def clean_file!
78
- map[:file] = base.join(map[:file]).to_s
79
- end
80
-
81
- # --
82
- private
83
- def clean_sources!
84
- if map[:sources]
85
- then map[:sources] = map[:sources].map do |v|
86
- base.join(strip_src(v))
87
- end
88
- else
89
- map[:sections].each do |v|
90
- v[:map][:sources] = v[:map][:sources].map do |vv|
91
- base.join(strip_src(vv))
92
- end
93
- end
94
- end
95
-
96
- map
97
- end
98
-
99
- # --
100
- private
101
- def strip_src(path)
102
- path = Pathutil.new(path)
103
- base = path.basename.gsub(%r!\.source!, "")
104
- return path.dirname.join(base).to_s unless path.dirname == "."
105
- base.to_s if path.dirname == "."
106
- end
107
-
108
- # --
109
- # @note we shim this on name.
110
- # Privates the base directory in the source.
111
- # @return [String]
112
- # --
113
- private
114
- def base
115
- Pathutil.new(asset.filename.sub(env.jekyll
116
- .in_source_dir + "/", "")).dirname
117
- end
118
-
119
- # --
120
- # rubocop:disable Layout/BlockEndNewline
121
- # rubocop:disable Layout/MultilineBlockLayout
122
- # rubocop:disable Style/BlockDelimiters
123
- # --
124
- private
125
- def map_files
126
- return original_map[:sources] if original_map.key?(:sources)
127
- original_map[:sections].map { |v| v[:map][:sources] \
128
- if v.key?(:map) }.flatten.compact
129
- end
130
-
131
- # --
132
- # rubocop:enable Layout/BlockEndNewline
133
- # rubocop:enable Layout/MultilineBlockLayout
134
- # rubocop:enable Style/BlockDelimiters
135
- # --
136
- private
137
- def write_map!
138
- path = Map.map_path(asset: asset, env: env)
139
- write(env.in_dest_dir(path)) do |f|
140
- files.push(path)
141
- f.write(map.to_json)
142
- files.uniq!
143
- end
144
- end
145
-
146
- # --
147
- private
148
- def strip_base(asset)
149
- return asset if asset.is_a?(Sprockets::Asset)
150
- asset.sub(base + "/", "")
151
- end
152
-
153
- # --
154
- private
155
- def write_src!
156
- [asset_path, map_files].flatten.compact.uniq.each do |v|
157
- next unless (v = env.find_asset(strip_base(v), pipeline: :source))
158
- path = map_path(v.filename)
159
-
160
- write(environment.in_dest_dir(path)) do |f|
161
- f.write(v.source)
162
- files.push(path.to_s)
163
- .uniq!
164
- end
165
- end
166
- end
167
-
168
- # --
169
- private
170
- def asset_path
171
- base.join(env.strip_paths(@asset.filename)).to_s
172
- end
173
-
174
- # --
175
- private
176
- def map_path(file)
177
- asset = base.join(env.strip_paths(file))
178
- Map.path({
179
- asset: asset, env: env
180
- })
181
- end
182
- end
183
-
184
- # --
185
- # We load late in some cases.
186
- # You can also register it in a Hook.
187
- # Globally Register it.
188
- # --
189
- Writer.register_on(Sprockets)
190
- end
191
- end
192
- end