jekyll-assets 2.1.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -2
- data/LICENSE +2 -2
- data/README.md +38 -31
- data/Rakefile +1 -40
- data/lib/jekyll-assets.rb +3 -1
- data/lib/jekyll/assets.rb +18 -16
- data/lib/jekyll/assets/addons.rb +3 -9
- data/lib/jekyll/assets/addons/autoprefixer.rb +6 -2
- data/lib/jekyll/assets/addons/bootstrap.rb +3 -1
- data/lib/jekyll/assets/addons/fontawesome.rb +7 -0
- data/lib/jekyll/assets/addons/{js_es6.rb → javascript.rb} +3 -1
- data/lib/jekyll/assets/addons/less.rb +9 -0
- data/lib/jekyll/assets/cached.rb +13 -2
- data/lib/jekyll/assets/config.rb +24 -14
- data/lib/jekyll/assets/env.rb +92 -40
- data/lib/jekyll/assets/hook.rb +14 -4
- data/lib/jekyll/assets/hooks.rb +5 -5
- data/lib/jekyll/assets/hooks/cache.rb +11 -3
- data/lib/jekyll/assets/hooks/compression.rb +12 -2
- data/lib/jekyll/assets/hooks/{configuration.rb → config.rb} +3 -1
- data/lib/jekyll/assets/hooks/erb.rb +15 -0
- data/lib/jekyll/assets/hooks/helpers.rb +4 -3
- data/lib/jekyll/assets/hooks/jekyll/drops.rb +3 -1
- data/lib/jekyll/assets/hooks/jekyll/setup.rb +6 -8
- data/lib/jekyll/assets/hooks/jekyll/write.rb +6 -2
- data/lib/jekyll/assets/hooks/logger.rb +6 -2
- data/lib/jekyll/assets/hooks/sources.rb +4 -1
- data/lib/jekyll/assets/hooks/sprockets.rb +3 -1
- data/lib/jekyll/assets/hooks/version.rb +6 -2
- data/lib/jekyll/assets/liquid.rb +3 -1
- data/lib/jekyll/assets/liquid/drop.rb +20 -2
- data/lib/jekyll/assets/liquid/filters.rb +13 -14
- data/lib/jekyll/assets/liquid/tag.rb +101 -39
- data/lib/jekyll/assets/liquid/tag/defaults.rb +2 -0
- data/lib/jekyll/assets/liquid/tag/defaults/image.rb +25 -5
- data/lib/jekyll/assets/liquid/tag/parser.rb +27 -19
- data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +33 -20
- data/lib/jekyll/assets/liquid/tag/proxies.rb +21 -16
- data/lib/jekyll/assets/logger.rb +29 -15
- data/lib/jekyll/assets/manifest.rb +98 -0
- data/lib/jekyll/assets/patches.rb +4 -2
- data/lib/jekyll/assets/patches/jekyll/site.rb +0 -4
- data/lib/jekyll/assets/patches/kernel.rb +4 -14
- data/lib/jekyll/assets/patches/sprockets/asset.rb +10 -4
- data/lib/jekyll/assets/patches/sprockets/helpers.rb +31 -0
- data/lib/jekyll/assets/processors.rb +1 -0
- data/lib/jekyll/assets/processors/less.rb +68 -0
- data/lib/jekyll/assets/processors/liquid.rb +46 -0
- data/lib/jekyll/assets/proxies.rb +1 -0
- data/lib/jekyll/assets/proxies/magick.rb +167 -0
- data/lib/jekyll/assets/version.rb +4 -2
- metadata +52 -23
- data/lib/jekyll/assets/addons/compass.rb +0 -11
- data/lib/jekyll/assets/addons/font_awesome.rb +0 -5
- data/lib/jekyll/assets/addons/processors/liquid.rb +0 -31
- data/lib/jekyll/assets/addons/proxies/magick.rb +0 -126
- data/lib/jekyll/assets/hooks/context_patches.rb +0 -17
- data/lib/jekyll/assets/hooks/disable_erb.rb +0 -10
- data/lib/jekyll/assets/patches/jekyll/cleaner.rb +0 -15
@@ -1,7 +1,11 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
Jekyll::Hooks.register :site, :post_write do |jekyll|
|
6
|
-
jekyll.sprockets.
|
8
|
+
if jekyll.sprockets.asset_config["autowrite"]
|
9
|
+
then jekyll.sprockets.write_all
|
10
|
+
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
Jekyll::Assets::Hook.register :env, :init do
|
6
|
-
|
8
|
+
if jekyll.config["verbose"]
|
9
|
+
self.logger = Jekyll::Assets::Logger.new
|
10
|
+
end
|
7
11
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
Jekyll::Assets::Hook.register :env, :init do
|
6
8
|
asset_config["sources"] ||= []
|
9
|
+
|
7
10
|
asset_config["sources"].each do |path|
|
8
11
|
append_path jekyll.in_source_dir(path)
|
9
12
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
Jekyll::Assets::Hook.register :env, :init do
|
6
8
|
jekyll.sprockets = self
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
Jekyll::Assets::Hook.register :env, :init do
|
6
|
-
self.version = Digest::MD5.hexdigest(
|
8
|
+
self.version = Digest::MD5.hexdigest(
|
9
|
+
asset_config.inspect
|
10
|
+
)
|
7
11
|
end
|
data/lib/jekyll/assets/liquid.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
module Jekyll
|
6
8
|
module Assets
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
require "fastimage"
|
6
8
|
|
@@ -15,33 +17,46 @@ module Jekyll
|
|
15
17
|
@asset = nil
|
16
18
|
end
|
17
19
|
|
20
|
+
# --------------------------------------------------------------------
|
21
|
+
|
22
|
+
def_delegator :asset, :digest_path
|
18
23
|
def_delegator :asset, :logical_path
|
19
24
|
def_delegator :asset, :content_type, :type
|
20
25
|
def_delegator :asset, :content_type
|
21
26
|
def_delegator :asset, :filename
|
22
27
|
|
28
|
+
# --------------------------------------------------------------------
|
29
|
+
|
23
30
|
def basename
|
24
31
|
File.basename(@path)
|
25
32
|
end
|
26
33
|
|
34
|
+
# --------------------------------------------------------------------
|
35
|
+
|
27
36
|
def width
|
28
37
|
if image?
|
29
38
|
dimensions.first
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
42
|
+
# --------------------------------------------------------------------
|
43
|
+
|
33
44
|
def height
|
34
45
|
if image?
|
35
46
|
dimensions.last
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
50
|
+
# --------------------------------------------------------------------
|
51
|
+
|
39
52
|
def dimensions
|
40
53
|
if image?
|
41
54
|
@dimensions ||= FastImage.new(asset.filename).size
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
58
|
+
# --------------------------------------------------------------------
|
59
|
+
|
45
60
|
private
|
46
61
|
def image?
|
47
62
|
%W(image/png image/jpeg image/gif).include?(
|
@@ -49,9 +64,12 @@ module Jekyll
|
|
49
64
|
)
|
50
65
|
end
|
51
66
|
|
67
|
+
# --------------------------------------------------------------------
|
68
|
+
|
52
69
|
private
|
53
70
|
def asset
|
54
|
-
@asset ||= @jekyll.sprockets.
|
71
|
+
@asset ||= @jekyll.sprockets.manifest.find(@path) \
|
72
|
+
.first
|
55
73
|
end
|
56
74
|
end
|
57
75
|
end
|
@@ -1,21 +1,17 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
module Jekyll
|
6
8
|
module Assets
|
7
9
|
module Liquid
|
8
10
|
module Filters
|
9
|
-
ACCEPTABLE_FILTERS =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
stylesheet
|
14
|
-
javascript
|
15
|
-
style
|
16
|
-
img
|
17
|
-
js
|
18
|
-
)
|
11
|
+
ACCEPTABLE_FILTERS = [:css, :img, :asset_path, :stylesheet,
|
12
|
+
:javascript, :style, :img, :js]
|
13
|
+
|
14
|
+
# --------------------------------------------------------------------
|
19
15
|
|
20
16
|
ACCEPTABLE_FILTERS.each do |val|
|
21
17
|
define_method val do |path, args = ""|
|
@@ -23,9 +19,12 @@ module Jekyll
|
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
22
|
+
|
23
|
+
#
|
24
|
+
|
25
|
+
::Liquid::Template.register_filter(
|
26
|
+
Filters
|
27
|
+
)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
29
|
-
|
30
|
-
# Register it with Liquid, good luck from here.
|
31
|
-
Liquid::Template.register_filter(Jekyll::Assets::Liquid::Filters)
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012-
|
3
|
+
# Copyright: 2012 - 2016 - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
require "fastimage"
|
6
8
|
|
@@ -14,17 +16,23 @@ module Jekyll
|
|
14
16
|
require_relative "tag/parser"
|
15
17
|
attr_reader :args
|
16
18
|
|
19
|
+
# --------------------------------------------------------------------
|
20
|
+
|
17
21
|
class << self
|
18
22
|
public :new
|
19
23
|
end
|
20
24
|
|
25
|
+
# --------------------------------------------------------------------
|
26
|
+
|
21
27
|
class AssetNotFoundError < StandardError
|
22
28
|
def initialize(asset)
|
23
29
|
super "Could not find the asset `#{asset}'"
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
|
-
#
|
33
|
+
# --------------------------------------------------------------------
|
34
|
+
# Tags that we allow our users to use.
|
35
|
+
# --------------------------------------------------------------------
|
28
36
|
|
29
37
|
AcceptableTags = %W(
|
30
38
|
img
|
@@ -39,15 +47,19 @@ module Jekyll
|
|
39
47
|
js
|
40
48
|
).freeze
|
41
49
|
|
42
|
-
#
|
50
|
+
# --------------------------------------------------------------------
|
51
|
+
# The HTML version of every tag that we accept.
|
52
|
+
# --------------------------------------------------------------------
|
43
53
|
|
44
54
|
Tags = {
|
45
|
-
"css" => %
|
46
|
-
"js" => %
|
47
|
-
"img" => %
|
55
|
+
"css" => %(<link type="text/css" rel="stylesheet" href="%s"%s>),
|
56
|
+
"js" => %(<script type="text/javascript" src="%s"%s></script>),
|
57
|
+
"img" => %(<img src="%s"%s>)
|
48
58
|
}.freeze
|
49
59
|
|
50
|
-
#
|
60
|
+
# --------------------------------------------------------------------
|
61
|
+
# Allows us to normalize tags so we can simplify logic.
|
62
|
+
# --------------------------------------------------------------------
|
51
63
|
|
52
64
|
Alias = {
|
53
65
|
"image" => "img",
|
@@ -56,9 +68,10 @@ module Jekyll
|
|
56
68
|
"style" => "css"
|
57
69
|
}.freeze
|
58
70
|
|
59
|
-
#
|
71
|
+
# --------------------------------------------------------------------
|
60
72
|
|
61
73
|
def initialize(tag, args, tokens)
|
74
|
+
tag = tag.to_s
|
62
75
|
@tokens = tokens
|
63
76
|
@tag = from_alias(tag)
|
64
77
|
@args = Parser.new(args, @tag)
|
@@ -66,34 +79,39 @@ module Jekyll
|
|
66
79
|
super
|
67
80
|
end
|
68
81
|
|
82
|
+
# --------------------------------------------------------------------
|
69
83
|
# NOTE: We only attach to the regenerator if you are using digested
|
70
84
|
# assets, otherwise we forego any association with it so that we keep
|
71
85
|
# your builds ultra fast, this is ideal in dev. Disable digests and
|
72
86
|
# let us process independent so the entire site isn't regenerated
|
73
87
|
# because of a single asset change.
|
88
|
+
# --------------------------------------------------------------------
|
74
89
|
|
75
90
|
def render(context)
|
76
|
-
args = @args.parse_liquid(context)
|
77
91
|
site = context.registers[:site]
|
78
92
|
page = context.registers.fetch(:page, {})
|
93
|
+
args = @args.parse_liquid(context)
|
79
94
|
sprockets = site.sprockets
|
80
95
|
page = page["path"]
|
81
96
|
|
82
97
|
asset = find_asset(args, sprockets)
|
83
98
|
add_as_jekyll_dependency(site, sprockets, page, asset)
|
84
99
|
process_tag(args, sprockets, asset)
|
100
|
+
|
85
101
|
rescue => e
|
86
|
-
capture_and_out_error
|
102
|
+
capture_and_out_error(
|
103
|
+
site, e
|
104
|
+
)
|
87
105
|
end
|
88
106
|
|
89
|
-
#
|
107
|
+
# --------------------------------------------------------------------
|
90
108
|
|
91
109
|
private
|
92
110
|
def from_alias(tag)
|
93
111
|
Alias.key?(tag) ? Alias[tag] : tag
|
94
112
|
end
|
95
113
|
|
96
|
-
#
|
114
|
+
# --------------------------------------------------------------------
|
97
115
|
|
98
116
|
private
|
99
117
|
def process_tag(args, sprockets, asset)
|
@@ -102,34 +120,26 @@ module Jekyll
|
|
102
120
|
build_html(args, sprockets, asset)
|
103
121
|
end
|
104
122
|
|
105
|
-
#
|
123
|
+
# --------------------------------------------------------------------
|
106
124
|
|
107
125
|
private
|
108
126
|
def build_html(args, sprockets, asset, path = get_path(sprockets, asset))
|
109
|
-
if @tag == "asset_path"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
asset.to_s
|
114
|
-
|
115
|
-
elsif args.key?(:data) && args[:data].key?(:uri)
|
116
|
-
format(Tags[@tag], asset.data_uri, \
|
117
|
-
args.to_html)
|
118
|
-
|
119
|
-
else
|
120
|
-
format(Tags[@tag], path, \
|
121
|
-
args.to_html)
|
122
|
-
end
|
127
|
+
return path if @tag == "asset_path"
|
128
|
+
return asset.to_s if @tag == "asset" || @tag == "asset_source"
|
129
|
+
return format(Tags[@tag], asset.data_uri, args.to_html) if args.key?(:data) && args[:data].key?(:uri)
|
130
|
+
format(Tags[@tag], path, args.to_html)
|
123
131
|
end
|
124
132
|
|
125
|
-
#
|
133
|
+
# --------------------------------------------------------------------
|
126
134
|
|
127
135
|
private
|
128
136
|
def get_path(sprockets, asset)
|
129
|
-
sprockets.prefix_path(
|
137
|
+
sprockets.prefix_path(
|
138
|
+
sprockets.digest?? asset.digest_path : asset.logical_path
|
139
|
+
)
|
130
140
|
end
|
131
141
|
|
132
|
-
#
|
142
|
+
# --------------------------------------------------------------------
|
133
143
|
|
134
144
|
private
|
135
145
|
def add_as_jekyll_dependency(site, sprockets, page, asset)
|
@@ -140,34 +150,84 @@ module Jekyll
|
|
140
150
|
end
|
141
151
|
end
|
142
152
|
|
143
|
-
#
|
153
|
+
# --------------------------------------------------------------------
|
144
154
|
|
145
155
|
private
|
146
156
|
def find_asset(args, sprockets)
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
157
|
+
out = _find_asset(args[:file],
|
158
|
+
args[:sprockets] ||= {}, sprockets
|
159
|
+
)
|
160
|
+
|
161
|
+
if !out
|
162
|
+
raise(
|
163
|
+
AssetNotFoundError, args[
|
164
|
+
:file
|
165
|
+
]
|
166
|
+
)
|
167
|
+
|
151
168
|
else
|
152
169
|
out.liquid_tags << self
|
153
|
-
!args.proxies?? out : ProxiedAsset.new(
|
154
|
-
out, args, sprockets, self
|
170
|
+
!args.proxies?? out : ProxiedAsset.new(
|
171
|
+
out, args, sprockets, self
|
172
|
+
)
|
155
173
|
end
|
156
174
|
end
|
157
175
|
|
176
|
+
# --------------------------------------------------------------------
|
177
|
+
|
178
|
+
private
|
179
|
+
def _find_asset(file, args, sprockets)
|
180
|
+
if args.empty? then sprockets.manifest.find(file).first
|
181
|
+
elsif args.size == 1 && args.key?(:accept)
|
182
|
+
if File.extname(file) == ""
|
183
|
+
file = file + _ext_for(args[
|
184
|
+
:accept
|
185
|
+
])
|
186
|
+
end
|
187
|
+
|
188
|
+
sprockets.manifest.find(file).find do |asset|
|
189
|
+
asset.content_type == args[
|
190
|
+
:accept
|
191
|
+
]
|
192
|
+
end
|
193
|
+
else
|
194
|
+
sprockets.find_asset(
|
195
|
+
file, args
|
196
|
+
)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# --------------------------------------------------------------------
|
201
|
+
|
202
|
+
private
|
203
|
+
def _ext_for(type)
|
204
|
+
out = Sprockets.mime_exts.select do |k, v|
|
205
|
+
v == type
|
206
|
+
end
|
207
|
+
|
208
|
+
out.keys \
|
209
|
+
.first
|
210
|
+
end
|
211
|
+
|
212
|
+
# --------------------------------------------------------------------
|
158
213
|
# There is no guarantee that Jekyll will pass on the error for some
|
159
214
|
# reason (unless you are just booting up) so we capture that error and
|
160
215
|
# always output it, it can lead to some double errors but I would
|
161
216
|
# rather there be a double error than no error.
|
217
|
+
# --------------------------------------------------------------------
|
162
218
|
|
163
219
|
private
|
164
220
|
def capture_and_out_error(site, error)
|
165
221
|
if error.is_a?(Sass::SyntaxError)
|
166
222
|
file = error.sass_filename.gsub(/#{Regexp.escape(site.source)}\//, "")
|
167
|
-
Jekyll.logger.error(%
|
223
|
+
Jekyll.logger.error(%(Error in #{file}:#{error.sass_line} #{
|
224
|
+
error
|
225
|
+
}))
|
226
|
+
|
168
227
|
else
|
169
|
-
Jekyll.logger.error
|
228
|
+
Jekyll.logger.error(
|
170
229
|
"", error.to_s
|
230
|
+
)
|
171
231
|
end
|
172
232
|
|
173
233
|
raise error
|
@@ -177,6 +237,8 @@ module Jekyll
|
|
177
237
|
end
|
178
238
|
end
|
179
239
|
|
240
|
+
# ----------------------------------------------------------------------------
|
241
|
+
|
180
242
|
Jekyll::Assets::Liquid::Tag::AcceptableTags.each do |tag|
|
181
243
|
Liquid::Template.register_tag tag, Jekyll::Assets::Liquid::Tag
|
182
244
|
end
|