jekyll-assets 2.0.0.pre.beta4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +79 -9
- data/lib/jekyll-assets.rb +4 -0
- data/lib/jekyll/assets.rb +14 -15
- data/lib/jekyll/assets/addons.rb +10 -0
- data/lib/jekyll/assets/addons/autoprefixer.rb +4 -0
- data/lib/jekyll/assets/addons/bootstrap.rb +4 -0
- data/lib/jekyll/assets/addons/compass.rb +4 -0
- data/lib/jekyll/assets/addons/font_awesome.rb +4 -0
- data/lib/jekyll/assets/addons/js_es6.rb +4 -0
- data/lib/jekyll/assets/addons/proxies/magick.rb +57 -27
- data/lib/jekyll/assets/cached.rb +4 -0
- data/lib/jekyll/assets/config.rb +7 -3
- data/lib/jekyll/assets/env.rb +68 -107
- data/lib/jekyll/assets/hook.rb +19 -12
- data/lib/jekyll/assets/hooks.rb +19 -0
- data/lib/jekyll/assets/hooks/cache.rb +4 -0
- data/lib/jekyll/assets/hooks/compression.rb +4 -0
- data/lib/jekyll/assets/hooks/configuration.rb +4 -0
- data/lib/jekyll/assets/hooks/context_patches.rb +5 -0
- data/lib/jekyll/assets/hooks/disable_erb.rb +4 -0
- data/lib/jekyll/assets/hooks/helpers.rb +4 -0
- data/lib/jekyll/assets/hooks/jekyll/asset_drops.rb +7 -0
- data/lib/jekyll/assets/hooks/jekyll/ignore.rb +9 -0
- data/lib/jekyll/{hooks → assets/hooks/jekyll}/initialize.rb +4 -0
- data/lib/jekyll/{hooks → assets/hooks/jekyll}/write_assets.rb +4 -0
- data/lib/jekyll/assets/hooks/logger.rb +4 -0
- data/lib/jekyll/assets/hooks/sources.rb +5 -1
- data/lib/jekyll/assets/hooks/sprockets.rb +4 -0
- data/lib/jekyll/assets/hooks/version.rb +5 -1
- data/lib/jekyll/assets/liquid.rb +13 -0
- data/lib/jekyll/assets/liquid/drop.rb +59 -0
- data/lib/jekyll/assets/liquid/filters.rb +16 -1
- data/lib/jekyll/assets/liquid/tag.rb +61 -37
- data/lib/jekyll/assets/liquid/tag/defaults.rb +18 -0
- data/lib/jekyll/assets/liquid/tag/defaults/image.rb +51 -0
- data/lib/jekyll/assets/liquid/tag/parser.rb +56 -28
- data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +14 -12
- data/lib/jekyll/assets/liquid/tag/proxies.rb +28 -24
- data/lib/jekyll/assets/logger.rb +13 -13
- data/lib/jekyll/assets/patches.rb +8 -0
- data/lib/jekyll/assets/patches/jekyll/cleaner.rb +4 -0
- data/lib/jekyll/assets/patches/jekyll/site.rb +4 -0
- data/lib/jekyll/assets/patches/kernel.rb +8 -0
- data/lib/jekyll/assets/patches/sprockets/asset.rb +6 -2
- data/lib/jekyll/assets/version.rb +5 -1
- metadata +33 -11
- data/lib/jekyll/assets/patches/hash.rb +0 -5
data/lib/jekyll/assets/hook.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
module Jekyll
|
2
6
|
module Assets
|
3
7
|
class Hook
|
@@ -25,37 +29,40 @@ module Jekyll
|
|
25
29
|
@_all ||= {}
|
26
30
|
end
|
27
31
|
|
28
|
-
# ---------------------------------------------------------------------
|
29
32
|
# Trigger a hook, giving an optional block where we pass you the,
|
30
33
|
# proc we got and then you can do as you please (such as instance eval)
|
31
34
|
# but if you do not give us one then we simply pass the args.
|
32
|
-
# ---------------------------------------------------------------------
|
33
35
|
|
34
36
|
def self.trigger(base, _point, *args, &block)
|
35
37
|
raise ArgumentError, "Do not give args with a block" if args.size > 0 && block_given?
|
36
|
-
if all.has_key?(base) && all
|
38
|
+
if all.has_key?(base) && all[base].has_key?(_point)
|
37
39
|
Set.new.merge(point(base, _point, :early)).merge(point(base, _point)).map do |v|
|
38
40
|
block_given?? block.call(v) : v.call(*args)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
#
|
45
|
+
#
|
44
46
|
|
45
47
|
def self.point(base, point, _when = :late)
|
46
|
-
point = all
|
47
|
-
|
48
|
-
|
48
|
+
point = all[base][point] ||= {
|
49
|
+
:late => Set.new,
|
50
|
+
:early => Set.new
|
51
|
+
}
|
52
|
+
|
53
|
+
point[_when]
|
49
54
|
end
|
50
55
|
|
51
|
-
#
|
56
|
+
#
|
52
57
|
|
53
58
|
def self.register(base, point, _when = :late, &block)
|
54
59
|
raise UnknownHookError.new(base: base) unless HookPoints.has_key?(base)
|
55
|
-
point = HookAliases
|
56
|
-
raise UnknownHookError.new(point: point) unless HookPoints
|
57
|
-
all
|
58
|
-
|
60
|
+
point = HookAliases[base][point] if HookAliases.fetch(base, {}).has_key?(point)
|
61
|
+
raise UnknownHookError.new(point: point) unless HookPoints[base].include?(point)
|
62
|
+
all[base] ||= {}
|
63
|
+
|
64
|
+
point(base, point, _when). \
|
65
|
+
add(block)
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require_relative "hooks/jekyll/initialize"
|
6
|
+
require_relative "hooks/jekyll/write_assets"
|
7
|
+
require_relative "hooks/jekyll/asset_drops"
|
8
|
+
require_relative "hooks/jekyll/ignore"
|
9
|
+
|
10
|
+
require_relative "hooks/compression"
|
11
|
+
require_relative "hooks/configuration"
|
12
|
+
require_relative "hooks/context_patches"
|
13
|
+
require_relative "hooks/disable_erb"
|
14
|
+
require_relative "hooks/helpers"
|
15
|
+
require_relative "hooks/logger"
|
16
|
+
require_relative "hooks/sources"
|
17
|
+
require_relative "hooks/sprockets"
|
18
|
+
require_relative "hooks/version"
|
19
|
+
require_relative "hooks/cache"
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
Jekyll::Assets::Hook.register :env, :init do
|
2
6
|
if (cache_dir = asset_config.fetch("cache", ".asset-cache"))
|
3
7
|
self.cache = Sprockets::Cache::FileStore.new(jekyll.in_source_dir(cache_dir))
|
@@ -1,8 +1,13 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
Jekyll::Assets::Hook.register :env, :init do
|
2
6
|
context_class.class_eval do
|
3
7
|
alias_method :_old_asset_path, :asset_path
|
4
8
|
def asset_path(asset, opts = {})
|
5
9
|
out = _old_asset_path asset
|
10
|
+
|
6
11
|
return unless out
|
7
12
|
path = environment.find_asset(resolve(asset))
|
8
13
|
environment.parent.used.add(path)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
Jekyll::Hooks.register :site, :after_reset do |jekyll|
|
6
|
+
unless jekyll.config["exclude"].grep(/\A\.asset\-cache\/?/)
|
7
|
+
jekyll.config["exclude"].push(".asset-cache/")
|
8
|
+
end
|
9
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
Jekyll::Assets::Hook.register :env, :init do
|
2
|
-
asset_config
|
6
|
+
(asset_config["sources"] ||= []).each do |path|
|
3
7
|
append_path jekyll.in_source_dir(path)
|
4
8
|
end
|
5
9
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
Jekyll::Assets::Hook.register :env, :init do
|
2
|
-
self.version = Digest::MD5.hexdigest(
|
6
|
+
self.version = Digest::MD5.hexdigest(asset_config.inspect)
|
3
7
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Assets
|
7
|
+
module Liquid
|
8
|
+
require_relative "liquid/drop"
|
9
|
+
require_relative "liquid/filters"
|
10
|
+
require_relative "liquid/tag"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require "fastimage"
|
6
|
+
|
7
|
+
module Jekyll
|
8
|
+
module Assets
|
9
|
+
module Liquid
|
10
|
+
class Drop < ::Liquid::Drop
|
11
|
+
extend Forwardable
|
12
|
+
def initialize(path, jekyll)
|
13
|
+
@path = path
|
14
|
+
@jekyll = jekyll
|
15
|
+
@asset = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def_delegator :asset, :logical_path
|
19
|
+
def_delegator :asset, :content_type, :type
|
20
|
+
def_delegator :asset, :content_type
|
21
|
+
def_delegator :asset, :filename
|
22
|
+
|
23
|
+
def basename
|
24
|
+
File.basename(@path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def width
|
28
|
+
if image?
|
29
|
+
dimensions.first
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def height
|
34
|
+
if image?
|
35
|
+
dimensions.last
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def dimensions
|
40
|
+
if image?
|
41
|
+
@dimensions ||= FastImage.new(asset.filename).size
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def image?
|
47
|
+
%(image/png image/jpeg image/gif).include?(
|
48
|
+
asset.content_type
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def asset
|
54
|
+
return @asset ||= @jekyll.sprockets.find_asset(@path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,8 +1,23 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
1
5
|
module Jekyll
|
2
6
|
module Assets
|
3
7
|
module Liquid
|
4
8
|
module Filters
|
5
|
-
%W(
|
9
|
+
AcceptableFilters = %W(
|
10
|
+
css
|
11
|
+
image
|
12
|
+
asset_path
|
13
|
+
stylesheet
|
14
|
+
javascript
|
15
|
+
style
|
16
|
+
img
|
17
|
+
js
|
18
|
+
)
|
19
|
+
|
20
|
+
AcceptableFilters.each do |val|
|
6
21
|
define_method val do |path, args = ""|
|
7
22
|
Tag.send(:new, val, "#{path} #{args}", "").render(@context)
|
8
23
|
end
|
@@ -1,18 +1,46 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012-2015 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require "fastimage"
|
6
|
+
|
1
7
|
module Jekyll
|
2
8
|
module Assets
|
3
9
|
module Liquid
|
4
10
|
class Tag < ::Liquid::Tag
|
11
|
+
require_relative "tag/proxies"
|
5
12
|
require_relative "tag/proxied_asset"
|
13
|
+
require_relative "tag/defaults"
|
6
14
|
require_relative "tag/parser"
|
7
15
|
attr_reader :args
|
8
16
|
|
17
|
+
class << self
|
18
|
+
public \
|
19
|
+
:new
|
20
|
+
end
|
21
|
+
|
9
22
|
class AssetNotFoundError < StandardError
|
10
23
|
def initialize(asset)
|
11
24
|
super "Could not find the asset `#{asset}'"
|
12
25
|
end
|
13
26
|
end
|
14
27
|
|
15
|
-
#
|
28
|
+
#
|
29
|
+
|
30
|
+
AcceptableTags = %W(
|
31
|
+
img
|
32
|
+
image
|
33
|
+
javascript
|
34
|
+
asset_source
|
35
|
+
stylesheet
|
36
|
+
asset_path
|
37
|
+
style
|
38
|
+
asset
|
39
|
+
css
|
40
|
+
js
|
41
|
+
)
|
42
|
+
|
43
|
+
#
|
16
44
|
|
17
45
|
Tags = {
|
18
46
|
"css" => %Q{<link type="text/css" rel="stylesheet" href="%s"%s>},
|
@@ -20,7 +48,7 @@ module Jekyll
|
|
20
48
|
"img" => %Q{<img src="%s"%s>}
|
21
49
|
}
|
22
50
|
|
23
|
-
#
|
51
|
+
#
|
24
52
|
|
25
53
|
Alias = {
|
26
54
|
"image" => "img",
|
@@ -29,7 +57,7 @@ module Jekyll
|
|
29
57
|
"style" => "css"
|
30
58
|
}
|
31
59
|
|
32
|
-
#
|
60
|
+
#
|
33
61
|
|
34
62
|
def initialize(tag, args, tokens)
|
35
63
|
@tokens = tokens
|
@@ -39,18 +67,18 @@ module Jekyll
|
|
39
67
|
super
|
40
68
|
end
|
41
69
|
|
42
|
-
# ---------------------------------------------------------------------
|
43
70
|
# NOTE: We only attach to the regenerator if you are using digested
|
44
71
|
# assets, otherwise we forego any association with it so that we keep
|
45
72
|
# your builds ultra fast, this is ideal in dev. Disable digests and
|
46
73
|
# let us process independent so the entire site isn't regenerated
|
47
74
|
# because of a single asset change.
|
48
|
-
# ---------------------------------------------------------------------
|
49
75
|
|
50
76
|
def render(context)
|
51
|
-
|
52
|
-
|
77
|
+
@args.parse_liquid!(context)
|
78
|
+
site = context.registers[:site]
|
79
|
+
page = context.registers.fetch(:page, {})
|
53
80
|
sprockets = site.sprockets
|
81
|
+
page = page["path"]
|
54
82
|
|
55
83
|
asset = find_asset(sprockets)
|
56
84
|
add_as_jekyll_dependency(site, sprockets, page, asset)
|
@@ -60,55 +88,53 @@ module Jekyll
|
|
60
88
|
site, e
|
61
89
|
end
|
62
90
|
|
63
|
-
#
|
91
|
+
#
|
64
92
|
|
65
93
|
private
|
66
94
|
def from_alias(tag)
|
67
|
-
Alias.has_key?(tag) ? Alias
|
95
|
+
Alias.has_key?(tag) ? Alias[tag] : tag
|
68
96
|
end
|
69
97
|
|
70
|
-
#
|
98
|
+
#
|
71
99
|
|
72
100
|
private
|
73
101
|
def process_tag(sprockets, asset)
|
74
102
|
sprockets.used.add(asset) unless @tag == "asset_source"
|
75
|
-
|
76
|
-
|
103
|
+
Defaults.set_defaults_for!(@tag, @args ||= {}, asset)
|
104
|
+
build_html(sprockets, asset)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
|
109
|
+
private
|
110
|
+
def build_html(sprockets, asset, path = get_path(sprockets, asset))
|
77
111
|
if @tag == "asset_path"
|
78
|
-
return
|
112
|
+
return path
|
79
113
|
|
80
114
|
elsif @tag == "asset" || @tag == "asset_source"
|
81
115
|
return asset.to_s
|
82
116
|
|
83
|
-
elsif @args.has_key?(:data) && @args
|
84
|
-
return Tags
|
117
|
+
elsif @args.has_key?(:data) && @args[:data].has_key?(:uri)
|
118
|
+
return Tags[@tag] % [
|
85
119
|
asset.data_uri, @args.to_html
|
86
120
|
]
|
87
121
|
|
88
122
|
else
|
89
|
-
return Tags
|
90
|
-
|
123
|
+
return Tags[@tag] % [
|
124
|
+
path, @args.to_html
|
91
125
|
]
|
92
126
|
end
|
93
127
|
end
|
94
128
|
|
95
|
-
#
|
129
|
+
#
|
96
130
|
|
97
131
|
private
|
98
132
|
def get_path(sprockets, asset)
|
99
|
-
sprockets.prefix_path(sprockets.digest?? asset.digest_path :
|
100
|
-
|
101
|
-
|
102
|
-
# ---------------------------------------------------------------------
|
103
|
-
|
104
|
-
private
|
105
|
-
def set_img_alt(asset)
|
106
|
-
if !@args.has_key?(:html) || !@args.fetch(:html).has_key?("alt")
|
107
|
-
@args.fetch_or_store(:html, {}).store("alt", asset.logical_path)
|
108
|
-
end
|
133
|
+
sprockets.prefix_path(sprockets.digest?? asset.digest_path : \
|
134
|
+
asset.logical_path)
|
109
135
|
end
|
110
136
|
|
111
|
-
#
|
137
|
+
#
|
112
138
|
|
113
139
|
private
|
114
140
|
def add_as_jekyll_dependency(site, sprockets, page, asset)
|
@@ -119,26 +145,24 @@ module Jekyll
|
|
119
145
|
end
|
120
146
|
end
|
121
147
|
|
122
|
-
#
|
148
|
+
#
|
123
149
|
|
124
150
|
private
|
125
151
|
def find_asset(sprockets)
|
126
|
-
file, _sprockets = @args
|
152
|
+
file, _sprockets = @args[:file], @args[:sprockets] ||= {}
|
127
153
|
if !(out = sprockets.find_asset(file, _sprockets))
|
128
|
-
raise AssetNotFoundError, @args
|
154
|
+
raise AssetNotFoundError, @args[:file]
|
129
155
|
else
|
130
156
|
out.liquid_tags << self
|
131
|
-
!args.has_proxies?? out : ProxiedAsset.new(
|
132
|
-
@args, sprockets, self)
|
157
|
+
!args.has_proxies?? out : ProxiedAsset.new( \
|
158
|
+
out, @args, sprockets, self)
|
133
159
|
end
|
134
160
|
end
|
135
161
|
|
136
|
-
# ---------------------------------------------------------------------
|
137
162
|
# There is no guarantee that Jekyll will pass on the error for some
|
138
163
|
# reason (unless you are just booting up) so we capture that error and
|
139
164
|
# always output it, it can lead to some double errors but I would
|
140
165
|
# rather there be a double error than no error.
|
141
|
-
# ---------------------------------------------------------------------
|
142
166
|
|
143
167
|
private
|
144
168
|
def capture_and_out_error(site, error)
|
@@ -157,6 +181,6 @@ module Jekyll
|
|
157
181
|
end
|
158
182
|
end
|
159
183
|
|
160
|
-
|
184
|
+
Jekyll::Assets::Liquid::Tag::AcceptableTags.each do |tag|
|
161
185
|
Liquid::Template.register_tag tag, Jekyll::Assets::Liquid::Tag
|
162
186
|
end
|