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.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +71 -8
- data/Rakefile +1 -0
- data/lib/jekyll-assets.rb +1 -2
- data/lib/jekyll/assets/compressors/sassc.rb +32 -0
- data/lib/jekyll/assets/compressors/scss.rb +30 -0
- data/lib/jekyll/assets/compressors/uglify.rb +30 -0
- data/lib/jekyll/assets/config.rb +1 -1
- data/lib/jekyll/assets/default.rb +1 -2
- data/lib/jekyll/assets/env.rb +1 -38
- data/lib/jekyll/assets/extensible.rb +1 -0
- data/lib/jekyll/assets/hook.rb +32 -79
- data/lib/jekyll/assets/html.rb +1 -6
- data/lib/jekyll/assets/patches/functions.rb +5 -7
- data/lib/jekyll/assets/plugins/alternates.rb +79 -0
- data/lib/jekyll/assets/plugins/font-awesome.rb +0 -1
- data/lib/jekyll/assets/plugins/html/pic.rb +1 -1
- data/lib/jekyll/assets/plugins/liquid.rb +1 -1
- data/lib/jekyll/assets/plugins/prefixer.rb +1 -1
- data/lib/jekyll/assets/plugins/proxy/magick.rb +10 -2
- data/lib/jekyll/assets/plugins/searcher.rb +1 -1
- data/lib/jekyll/assets/plugins/srcmap.rb +47 -0
- data/lib/jekyll/assets/plugins/srcmap/css.rb +35 -0
- data/lib/jekyll/assets/plugins/srcmap/javascript.rb +29 -0
- data/lib/jekyll/assets/plugins/srcmap/writer.rb +187 -0
- data/lib/jekyll/assets/tag.rb +2 -2
- data/lib/jekyll/assets/utils.rb +35 -18
- data/lib/jekyll/assets/version.rb +1 -1
- data/lib/jekyll/assets/writer.rb +30 -33
- metadata +11 -7
- data/lib/jekyll/assets/map.rb +0 -57
- data/lib/jekyll/assets/map/css.rb +0 -43
- data/lib/jekyll/assets/map/javascript.rb +0 -43
- data/lib/jekyll/assets/map/writer.rb +0 -192
data/lib/jekyll/assets/html.rb
CHANGED
@@ -10,13 +10,9 @@ module Jekyll
|
|
10
10
|
class HTML < Extensible
|
11
11
|
attr_reader :doc
|
12
12
|
|
13
|
-
# --
|
14
|
-
# rubocop:disable Style/RedundantReturn
|
15
13
|
# --
|
16
14
|
def self.skips
|
17
|
-
|
18
|
-
inline path data pic
|
19
|
-
)
|
15
|
+
%i(inline path data pic)
|
20
16
|
end
|
21
17
|
|
22
18
|
# --
|
@@ -31,7 +27,6 @@ module Jekyll
|
|
31
27
|
# Search for plugins and runners and then run them.
|
32
28
|
# @param [Sprockets::Asset] the current asset.
|
33
29
|
# @note look inside of plugins for examples.
|
34
|
-
# rubocop:enable Style/RedundantReturn
|
35
30
|
# @return [String] the final result.
|
36
31
|
# @param [Env] env the env.
|
37
32
|
# --
|
@@ -6,15 +6,13 @@ module Jekyll
|
|
6
6
|
module Assets
|
7
7
|
module Patches
|
8
8
|
module SassFunctions
|
9
|
+
SprocketsString = ::Sprockets::Autoload::Sass::Script::String
|
10
|
+
|
9
11
|
def asset_path(path, options = {})
|
10
12
|
path, args = path.value.split(%r!\s+!, 2)
|
11
|
-
path, = URI.split(path)
|
12
|
-
path = "#{path} #{args}"
|
13
|
-
|
14
|
-
# We strip the query string, and the fragment.
|
15
|
-
path = sprockets_context.asset_path(path, options)
|
16
|
-
::Sprockets::Autoload::Sass::Script::String.new \
|
17
|
-
path, :string
|
13
|
+
path, fragment = URI.split(path).values_at(5, 8)
|
14
|
+
path = sprockets_context.asset_path("#{path} #{args}", options)
|
15
|
+
SprocketsString.new [path, fragment].compact.join("#")
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2018 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
if Jekyll::Assets::Utils.activate("crass")
|
6
|
+
module Jekyll
|
7
|
+
module Assets
|
8
|
+
module Plugins
|
9
|
+
NODER = %r!/\*\! @alternate \*/!
|
10
|
+
RTEST = %r!#{Regexp.union(%w(-ms- -webkit- -moz- -o-).freeze)}!
|
11
|
+
NODE1 = { node: :whitespace, pos: 28, raw: " " }.freeze
|
12
|
+
NODE2 = {
|
13
|
+
raw: "/*! @alternate */",
|
14
|
+
pos: 0, # It's ignored. @see Crass::Parser.stringify
|
15
|
+
value: "! @alternate ",
|
16
|
+
node: :comment,
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
NODE3 = {
|
20
|
+
raw: "/* @alternate */",
|
21
|
+
pos: 0, # It's ignored. @see Crass::Parser.stringify
|
22
|
+
value: "@alternate ",
|
23
|
+
node: :comment,
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
class Alternates
|
27
|
+
def call(input)
|
28
|
+
comp = input[:environment].asset_config[:compression]
|
29
|
+
data = Crass.parse(input[:data] || "", preserve_comments: true)
|
30
|
+
data.each do |v|
|
31
|
+
next unless v[:node] == :style_rule
|
32
|
+
v[:children] = v[:children].each_with_object([]) do |c, a|
|
33
|
+
if alternate?(c)
|
34
|
+
a << (comp ? NODE2 : NODE3)
|
35
|
+
a << NODE1
|
36
|
+
end
|
37
|
+
|
38
|
+
a << c
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
{
|
43
|
+
data: Crass::Parser.stringify(data, {
|
44
|
+
preserve_comments: true,
|
45
|
+
}),
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def alternate?(c)
|
51
|
+
c[:node] == :property && (
|
52
|
+
c[:name] =~ RTEST || c[:value] =~ RTEST
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# --
|
58
|
+
# When compression is enabled we need to make sure to
|
59
|
+
# run an extra step, because when compression is being
|
60
|
+
# ran, we have to guard with /*! so we've to strip.
|
61
|
+
# --
|
62
|
+
Hook.register :asset, :after_compression do |_, o, t|
|
63
|
+
next unless t == "text/css"
|
64
|
+
|
65
|
+
o.update({
|
66
|
+
# Remember we guard against compression.
|
67
|
+
data: o[:data].gsub(NODER, " #{NODE3[:raw]} "),
|
68
|
+
})
|
69
|
+
end
|
70
|
+
|
71
|
+
# --
|
72
|
+
Hook.register :env, :after_init, priority: 2 do
|
73
|
+
register_bundle_processor "text/css",
|
74
|
+
Alternates.new
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -39,7 +39,7 @@ module Jekyll
|
|
39
39
|
# Because we need to keep some support for 3.x we register it
|
40
40
|
# two different ways depending on the type of Sprockets.
|
41
41
|
# --
|
42
|
-
if !
|
42
|
+
if !Utils.old_sprockets?
|
43
43
|
Liquid::TYPES.each do |k, v|
|
44
44
|
to = Utils.strip_secondary_content_type(k)
|
45
45
|
charset = Sprockets.mime_types[to][:charset]
|
@@ -18,7 +18,7 @@ Jekyll::Assets::Utils.javascript? do
|
|
18
18
|
})
|
19
19
|
end
|
20
20
|
|
21
|
-
Jekyll::Assets::Hook.register :env, :after_init do
|
21
|
+
Jekyll::Assets::Hook.register :env, :after_init, priority: 1 do
|
22
22
|
config = asset_config[:plugins][:css][:autoprefixer]
|
23
23
|
AutoprefixerRails.install(self, jekyll.safe ? config : {
|
24
24
|
# Your configuration here.
|
@@ -27,8 +27,12 @@ module Jekyll
|
|
27
27
|
img = ::MiniMagick::Image.open(@file)
|
28
28
|
magick_format(img) if @args[:magick][:format]
|
29
29
|
img.combine_options do |c|
|
30
|
-
|
31
|
-
|
30
|
+
@args[:magick].keys.reject { |k| k == :format }.each do |k|
|
31
|
+
m = "magick_#{k}"
|
32
|
+
|
33
|
+
if self.class.private_method_defined?(m)
|
34
|
+
method(m).arity == 2 ? send(m, img, c) : send(m, c)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -125,6 +129,10 @@ module Jekyll
|
|
125
129
|
width, height = img.width / 2, img.height / 2 if @args[:magick].key?(:half)
|
126
130
|
cmd.resize "#{width}x#{height}" if width && height
|
127
131
|
end
|
132
|
+
|
133
|
+
alias magick_double magick_preset_resize
|
134
|
+
alias magick_quarter magick_preset_resize
|
135
|
+
alias magick_half magick_preset_resize
|
128
136
|
end
|
129
137
|
end
|
130
138
|
end
|
@@ -78,7 +78,7 @@ Jekyll::Assets::Hook.register :config, :before_merge do |c|
|
|
78
78
|
end
|
79
79
|
|
80
80
|
# --
|
81
|
-
Jekyll::Hooks.register
|
81
|
+
Jekyll::Hooks.register %i(pages documents posts), :post_render do |d|
|
82
82
|
if d.site.sprockets.asset_config["plugins"]["img"]["searcher"]
|
83
83
|
if d.output_ext == ".html"
|
84
84
|
Jekyll::Assets::Plugins::Searcher.new(d).run
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2018 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
unless Jekyll::Assets::Utils.old_sprockets?
|
6
|
+
require_relative "srcmap/css"
|
7
|
+
require_relative "srcmap/javascript"
|
8
|
+
require_relative "srcmap/writer"
|
9
|
+
|
10
|
+
module Jekyll
|
11
|
+
module Assets
|
12
|
+
module Plugins
|
13
|
+
module SrcMap
|
14
|
+
NAME = "%<name>s.map"
|
15
|
+
DIR_NAME = "source-maps"
|
16
|
+
DIR = Pathutil.new(DIR_NAME)
|
17
|
+
EXT = ".map"
|
18
|
+
|
19
|
+
# --
|
20
|
+
# @return [String] the map name.
|
21
|
+
# Take the path, and attach the map extension.
|
22
|
+
# @note this just saves logic.
|
23
|
+
# --
|
24
|
+
def self.map_path(env:, asset:)
|
25
|
+
[
|
26
|
+
path({
|
27
|
+
asset: asset,
|
28
|
+
env: env,
|
29
|
+
}),
|
30
|
+
EXT,
|
31
|
+
].join
|
32
|
+
end
|
33
|
+
|
34
|
+
# --
|
35
|
+
# @note this is used for anything in source-maps.
|
36
|
+
# Strip the filename and return a relative sourcemap path.
|
37
|
+
# @return [Pathutil] the path.
|
38
|
+
# --
|
39
|
+
def self.path(env:, asset:)
|
40
|
+
DIR.join(env.strip_paths(asset.is_a?(Sprockets::Asset) ?
|
41
|
+
asset.filename : asset))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2018 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Assets
|
7
|
+
module Plugins
|
8
|
+
Hook.register :asset, :after_compression, priority: 3 do |i, o, t|
|
9
|
+
next unless t == "text/css"
|
10
|
+
|
11
|
+
env = i[:environment]
|
12
|
+
asset = env.find_asset!(i[:filename], pipeline: :source)
|
13
|
+
path = asset.filename.sub(env.jekyll.in_source_dir + "/", "")
|
14
|
+
url = SrcMap.map_path(asset: asset, env: env)
|
15
|
+
url = env.prefix_url(url)
|
16
|
+
|
17
|
+
o.update({
|
18
|
+
data: <<~CSS
|
19
|
+
#{o[:data].strip}
|
20
|
+
/*# sourceMappingURL=#{url} */
|
21
|
+
/*# sourceURL=#{path} */
|
22
|
+
CSS
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
# --
|
27
|
+
Hook.register :env, :after_init, priority: 1 do
|
28
|
+
next if asset_config[:compression]
|
29
|
+
if asset_config[:source_maps]
|
30
|
+
then asset_config[:compression] = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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 Plugins
|
10
|
+
Hook.register :asset, :after_compression, priority: 3 do |i, o, t|
|
11
|
+
next unless t == "application/javascript"
|
12
|
+
|
13
|
+
env = i[:environment]
|
14
|
+
asset = env.find_asset!(i[:filename], pipeline: :source)
|
15
|
+
path = asset.filename.sub(env.jekyll.in_source_dir + "/", "")
|
16
|
+
url = SrcMap.map_path(asset: asset, env: env)
|
17
|
+
url = env.prefix_url(url)
|
18
|
+
|
19
|
+
o.update({
|
20
|
+
data: <<~TXT
|
21
|
+
#{o[:data].strip}
|
22
|
+
//# sourceMappingURL=#{url}
|
23
|
+
//# sourceURL=#{path}
|
24
|
+
TXT
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,187 @@
|
|
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 Plugins
|
11
|
+
module SrcMap
|
12
|
+
class Writer < Sprockets::Exporters::Base
|
13
|
+
alias env environment
|
14
|
+
|
15
|
+
def skip?(_)
|
16
|
+
!env.asset_config[:source_maps] ||
|
17
|
+
!asset.metadata[:map]
|
18
|
+
end
|
19
|
+
|
20
|
+
# --
|
21
|
+
def call
|
22
|
+
clean_file!
|
23
|
+
clean_sources!
|
24
|
+
write_map!
|
25
|
+
write_src!
|
26
|
+
end
|
27
|
+
|
28
|
+
# --
|
29
|
+
# Provides our custom manifest key, full of files.
|
30
|
+
# @note We push everything from the file we are writing to the maps.
|
31
|
+
# @return [Array<String>]
|
32
|
+
# --
|
33
|
+
def files
|
34
|
+
@files ||= begin
|
35
|
+
key = "sourceMapFiles"
|
36
|
+
out = env.manifest.data[key] ||= []
|
37
|
+
unless Manifest.keep_keys.include?(key)
|
38
|
+
Manifest.keep_keys << key
|
39
|
+
end
|
40
|
+
|
41
|
+
out
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# --
|
46
|
+
# @return [HashWithIndifferentAccess]
|
47
|
+
# @note do not modify the original map.
|
48
|
+
# Provides a modifible SourceMap
|
49
|
+
# --
|
50
|
+
private
|
51
|
+
def map
|
52
|
+
@map ||= asset.metadata[:map]
|
53
|
+
.with_indifferent_access
|
54
|
+
end
|
55
|
+
|
56
|
+
# --
|
57
|
+
# @return [HashWithIndifferentAccess]
|
58
|
+
# @note this is frozen so you can't modify.
|
59
|
+
# Provides an unmodifiable SourceMap
|
60
|
+
# --
|
61
|
+
private
|
62
|
+
def original_map
|
63
|
+
@original_map ||= asset.metadata[:map]
|
64
|
+
.with_indifferent_access.freeze
|
65
|
+
end
|
66
|
+
|
67
|
+
# --
|
68
|
+
# @note something like _assets/*
|
69
|
+
# Makes sure that the name sits in the asset path.
|
70
|
+
# @return [String]
|
71
|
+
# --
|
72
|
+
private
|
73
|
+
def clean_file!
|
74
|
+
map[:file] = base.join(map[:file]).to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
# --
|
78
|
+
private
|
79
|
+
def clean_sources!
|
80
|
+
if map[:sources]
|
81
|
+
then map[:sources] = map[:sources].map do |v|
|
82
|
+
base.join(strip_src(v))
|
83
|
+
end
|
84
|
+
else
|
85
|
+
map[:sections].each do |v|
|
86
|
+
v[:map][:sources] = v[:map][:sources].map do |vv|
|
87
|
+
base.join(strip_src(vv))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
map
|
93
|
+
end
|
94
|
+
|
95
|
+
# --
|
96
|
+
private
|
97
|
+
def strip_src(path)
|
98
|
+
path = Pathutil.new(path)
|
99
|
+
base = path.basename.gsub(%r!\.source!, "")
|
100
|
+
return path.dirname.join(base).to_s unless path.dirname == "."
|
101
|
+
base.to_s if path.dirname == "."
|
102
|
+
end
|
103
|
+
|
104
|
+
# --
|
105
|
+
# @note we shim this on name.
|
106
|
+
# Privates the base directory in the source.
|
107
|
+
# @return [String]
|
108
|
+
# --
|
109
|
+
private
|
110
|
+
def base
|
111
|
+
Pathutil.new(asset.filename.sub(env.jekyll
|
112
|
+
.in_source_dir + "/", "")).dirname
|
113
|
+
end
|
114
|
+
|
115
|
+
# --
|
116
|
+
# rubocop:disable Layout/BlockEndNewline
|
117
|
+
# rubocop:disable Layout/MultilineBlockLayout
|
118
|
+
# rubocop:disable Style/BlockDelimiters
|
119
|
+
# --
|
120
|
+
private
|
121
|
+
def map_files
|
122
|
+
return original_map[:sources] if original_map.key?(:sources)
|
123
|
+
original_map[:sections].map { |v| v[:map][:sources] \
|
124
|
+
if v.key?(:map) }.flatten.compact
|
125
|
+
end
|
126
|
+
|
127
|
+
# --
|
128
|
+
# rubocop:enable Layout/BlockEndNewline
|
129
|
+
# rubocop:enable Layout/MultilineBlockLayout
|
130
|
+
# rubocop:enable Style/BlockDelimiters
|
131
|
+
# --
|
132
|
+
private
|
133
|
+
def write_map!
|
134
|
+
path = SrcMap.map_path(asset: asset, env: env)
|
135
|
+
write(env.in_dest_dir(path)) do |f|
|
136
|
+
files.push(path)
|
137
|
+
f.write(map.to_json)
|
138
|
+
files.uniq!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# --
|
143
|
+
private
|
144
|
+
def strip_base(asset)
|
145
|
+
return asset if asset.is_a?(Sprockets::Asset)
|
146
|
+
asset.sub(base + "/", "")
|
147
|
+
end
|
148
|
+
|
149
|
+
# --
|
150
|
+
private
|
151
|
+
def write_src!
|
152
|
+
[asset_path, map_files].flatten.compact.uniq.each do |v|
|
153
|
+
next unless (v = env.find_asset(strip_base(v), pipeline: :source))
|
154
|
+
path = map_path(v.filename)
|
155
|
+
|
156
|
+
write(environment.in_dest_dir(path)) do |f|
|
157
|
+
f.write(v.source)
|
158
|
+
files.push(path.to_s)
|
159
|
+
.uniq!
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# --
|
165
|
+
private
|
166
|
+
def asset_path
|
167
|
+
base.join(env.strip_paths(@asset.filename)).to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
# --
|
171
|
+
private
|
172
|
+
def map_path(file)
|
173
|
+
asset = base.join(env.strip_paths(file))
|
174
|
+
SrcMap.path({
|
175
|
+
asset: asset, env: env
|
176
|
+
})
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# --
|
181
|
+
Hook.register :env, :after_init, priority: 3 do
|
182
|
+
register_exporter("*/*", Writer)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|