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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -2
  3. data/LICENSE +2 -2
  4. data/README.md +38 -31
  5. data/Rakefile +1 -40
  6. data/lib/jekyll-assets.rb +3 -1
  7. data/lib/jekyll/assets.rb +18 -16
  8. data/lib/jekyll/assets/addons.rb +3 -9
  9. data/lib/jekyll/assets/addons/autoprefixer.rb +6 -2
  10. data/lib/jekyll/assets/addons/bootstrap.rb +3 -1
  11. data/lib/jekyll/assets/addons/fontawesome.rb +7 -0
  12. data/lib/jekyll/assets/addons/{js_es6.rb → javascript.rb} +3 -1
  13. data/lib/jekyll/assets/addons/less.rb +9 -0
  14. data/lib/jekyll/assets/cached.rb +13 -2
  15. data/lib/jekyll/assets/config.rb +24 -14
  16. data/lib/jekyll/assets/env.rb +92 -40
  17. data/lib/jekyll/assets/hook.rb +14 -4
  18. data/lib/jekyll/assets/hooks.rb +5 -5
  19. data/lib/jekyll/assets/hooks/cache.rb +11 -3
  20. data/lib/jekyll/assets/hooks/compression.rb +12 -2
  21. data/lib/jekyll/assets/hooks/{configuration.rb → config.rb} +3 -1
  22. data/lib/jekyll/assets/hooks/erb.rb +15 -0
  23. data/lib/jekyll/assets/hooks/helpers.rb +4 -3
  24. data/lib/jekyll/assets/hooks/jekyll/drops.rb +3 -1
  25. data/lib/jekyll/assets/hooks/jekyll/setup.rb +6 -8
  26. data/lib/jekyll/assets/hooks/jekyll/write.rb +6 -2
  27. data/lib/jekyll/assets/hooks/logger.rb +6 -2
  28. data/lib/jekyll/assets/hooks/sources.rb +4 -1
  29. data/lib/jekyll/assets/hooks/sprockets.rb +3 -1
  30. data/lib/jekyll/assets/hooks/version.rb +6 -2
  31. data/lib/jekyll/assets/liquid.rb +3 -1
  32. data/lib/jekyll/assets/liquid/drop.rb +20 -2
  33. data/lib/jekyll/assets/liquid/filters.rb +13 -14
  34. data/lib/jekyll/assets/liquid/tag.rb +101 -39
  35. data/lib/jekyll/assets/liquid/tag/defaults.rb +2 -0
  36. data/lib/jekyll/assets/liquid/tag/defaults/image.rb +25 -5
  37. data/lib/jekyll/assets/liquid/tag/parser.rb +27 -19
  38. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +33 -20
  39. data/lib/jekyll/assets/liquid/tag/proxies.rb +21 -16
  40. data/lib/jekyll/assets/logger.rb +29 -15
  41. data/lib/jekyll/assets/manifest.rb +98 -0
  42. data/lib/jekyll/assets/patches.rb +4 -2
  43. data/lib/jekyll/assets/patches/jekyll/site.rb +0 -4
  44. data/lib/jekyll/assets/patches/kernel.rb +4 -14
  45. data/lib/jekyll/assets/patches/sprockets/asset.rb +10 -4
  46. data/lib/jekyll/assets/patches/sprockets/helpers.rb +31 -0
  47. data/lib/jekyll/assets/processors.rb +1 -0
  48. data/lib/jekyll/assets/processors/less.rb +68 -0
  49. data/lib/jekyll/assets/processors/liquid.rb +46 -0
  50. data/lib/jekyll/assets/proxies.rb +1 -0
  51. data/lib/jekyll/assets/proxies/magick.rb +167 -0
  52. data/lib/jekyll/assets/version.rb +4 -2
  53. metadata +52 -23
  54. data/lib/jekyll/assets/addons/compass.rb +0 -11
  55. data/lib/jekyll/assets/addons/font_awesome.rb +0 -5
  56. data/lib/jekyll/assets/addons/processors/liquid.rb +0 -31
  57. data/lib/jekyll/assets/addons/proxies/magick.rb +0 -126
  58. data/lib/jekyll/assets/hooks/context_patches.rb +0 -17
  59. data/lib/jekyll/assets/hooks/disable_erb.rb +0 -10
  60. data/lib/jekyll/assets/patches/jekyll/cleaner.rb +0 -15
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  module Jekyll
6
8
  module Assets
@@ -12,9 +14,28 @@ module Jekyll
12
14
  def liquid_proxies
13
15
  Liquid::Tag::Proxies
14
16
  end
17
+
18
+ # --------------------------------------------------------------------
19
+
20
+ def init(jekyll)
21
+ new(jekyll)
22
+ jekyll.sprockets.excludes.map(&jekyll.config["exclude"].method(:<<))
23
+ jekyll.config["keep_files"] |= jekyll.sprockets.asset_config["prefix"] \
24
+ .gsub(/\A\//, "").to_a
25
+ end
26
+ end
27
+
28
+ # ----------------------------------------------------------------------
29
+ # Disables GZIP. You should be using your server to do this and even
30
+ # if you don't, there are far better and more efficient algorithms out
31
+ # right now that are in beta. Try Googling Googles new compression.
32
+ # ----------------------------------------------------------------------
33
+
34
+ def skip_gzip?
35
+ true
15
36
  end
16
37
 
17
- #
38
+ # ----------------------------------------------------------------------
18
39
 
19
40
  def excludes
20
41
  excludes = Set.new
@@ -22,7 +43,7 @@ module Jekyll
22
43
  excludes
23
44
  end
24
45
 
25
- #
46
+ # ----------------------------------------------------------------------
26
47
 
27
48
  def all_unparsed_assets
28
49
  @unparsed_assets ||= logical_paths.select do |(_, val)|
@@ -30,48 +51,61 @@ module Jekyll
30
51
  end
31
52
  end
32
53
 
33
- #
54
+ # ----------------------------------------------------------------------
34
55
 
35
56
  def to_liquid_payload
36
57
  jekyll.sprockets.all_unparsed_assets.each_with_object({}) do |(key, val), hash|
37
- hash[key] = Jekyll::Assets::Liquid::Drop.new(val, jekyll)
58
+ hash[key] = Jekyll::Assets::Liquid::Drop.new(
59
+ val, jekyll
60
+ )
38
61
  end
39
62
  end
40
63
 
41
- #
64
+ # ----------------------------------------------------------------------
42
65
 
43
66
  def initialize(path, jekyll = nil)
44
- jekyll, path = path, nil if path.is_a?(Jekyll::Site)
45
- @jekyll = jekyll
46
- @used = Set.new
67
+ (jekyll = path; path = nil) if path.is_a?(Jekyll::Site)
47
68
 
69
+ @used = Set.new
70
+ @jekyll = jekyll
48
71
  path ? super(path) : super()
49
72
  Hook.trigger :env, :init do |hook|
50
- hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(&hook)
73
+ hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(
74
+ &hook
75
+ )
51
76
  end
52
77
  end
53
78
 
54
- #
79
+ # ----------------------------------------------------------------------
55
80
 
56
81
  def liquid_proxies
57
82
  self.class.liquid_proxies
58
83
  end
59
84
 
85
+ # ----------------------------------------------------------------------
60
86
  # Make sure a path falls withint our cache dir.
87
+ # ----------------------------------------------------------------------
61
88
 
62
89
  def in_cache_dir(*paths)
63
- cache_dir = asset_config["cache"] || ".asset-cache"
64
- jekyll.in_source_dir(cache_dir, *paths)
90
+ jekyll.in_source_dir(asset_config["cache"] || ".asset-cache",
91
+ *paths
92
+ )
65
93
  end
66
94
 
95
+ # ----------------------------------------------------------------------
67
96
  # Merged form of `#extra_assets`
97
+ # ----------------------------------------------------------------------
68
98
 
69
99
  def all_assets
70
- Set.new(@used).merge extra_assets
100
+ Set.new(@used).merge(
101
+ extra_assets
102
+ )
71
103
  end
72
104
 
105
+ # ----------------------------------------------------------------------
73
106
  # Assets you tell us you want to always compile, even if you do not
74
107
  # use them. Just like Rails this is probably normally used.
108
+ # ----------------------------------------------------------------------
75
109
 
76
110
  def extra_assets
77
111
  assets = asset_config["assets"] ||= []
@@ -80,53 +114,63 @@ module Jekyll
80
114
  end
81
115
  end
82
116
 
83
- #
117
+ # ----------------------------------------------------------------------
84
118
 
85
119
  def cdn?
86
120
  !dev? && asset_config.key?("cdn") && \
87
121
  asset_config["cdn"]
88
122
  end
89
123
 
90
- #
124
+ # ----------------------------------------------------------------------
125
+ # rubocop:disable Style/ExtraSpacing
126
+ # ----------------------------------------------------------------------
91
127
 
92
128
  def baseurl
93
129
  ary = []
94
130
 
95
131
  ary << jekyll.config["baseurl"] unless cdn? && asset_config["skip_baseurl_with_cdn"]
96
132
  ary << asset_config[ "prefix"] unless cdn? && asset_config[ "skip_prefix_with_cdn"]
133
+
97
134
  File.join(*ary.delete_if do |val|
98
135
  val.nil? || val.empty?
99
136
  end)
100
137
  end
101
138
 
102
- #
139
+ # ----------------------------------------------------------------------
140
+ # rubocop:enable Style/ExtraSpacing
141
+ # ----------------------------------------------------------------------
103
142
 
104
143
  def dev?
105
144
  %W(development test).include?(Jekyll.env)
106
145
  end
107
146
 
108
- #
147
+ # ----------------------------------------------------------------------
109
148
 
110
149
  def compress?(what)
111
- !!asset_config["compress"] \
112
- .fetch(what, false)
150
+ !!asset_config["compress"].fetch(
151
+ what, false
152
+ )
113
153
  end
114
154
 
115
- #
155
+ # ----------------------------------------------------------------------
116
156
 
117
157
  def asset_config
118
158
  jekyll.config["assets"] ||= {}
119
159
  end
120
160
 
121
- #
161
+ # ----------------------------------------------------------------------
122
162
 
123
163
  def digest?
124
- !!asset_config["digest"]
164
+ !!asset_config[
165
+ "digest"
166
+ ]
125
167
  end
126
168
 
169
+ # ----------------------------------------------------------------------
127
170
  # Prefix path prefixes the path with the baseurl and the cdn if it
128
171
  # exists and is in the right mode to use it. Otherwise it will only use
129
172
  # the baseurl and asset prefix. All of these can be adjusted.
173
+ # ----------------------------------------------------------------------
130
174
 
131
175
  def prefix_path(path = nil)
132
176
  cdn = asset_config["cdn"]
@@ -140,37 +184,45 @@ module Jekyll
140
184
  url.chomp("/")
141
185
  end
142
186
 
143
- #
187
+ # ----------------------------------------------------------------------
144
188
 
145
189
  def cached
146
- Cached.new(self)
190
+ return @cached ||= Cached.new(
191
+ self
192
+ )
147
193
  end
148
194
 
149
- #
195
+ # ----------------------------------------------------------------------
196
+
197
+ def manifest
198
+ return @manifest ||= Manifest.new(self, jekyll.in_dest_dir(
199
+ asset_config["prefix"]
200
+ ))
201
+ end
202
+
203
+ # ----------------------------------------------------------------------
204
+ # Write assets with the manifest if they aren't proxied assets. If
205
+ # they are then we go on to write them ourselves. We don't necessarily
206
+ # integrate with the manifest that deeply because it's hard.
207
+ # ----------------------------------------------------------------------
150
208
 
151
209
  def write_all
152
- past = self.class.past ||= Set.new
153
- (@used.any?? all_assets : past).each do |obj|
154
- if past.add(obj) && path = as_path(obj)
155
- obj.write_to path
156
- end
210
+ assets = all_assets.partition { |v| v.is_a?(Liquid::Tag::ProxiedAsset) }
211
+ manifest.compile(assets.last.map(&:logical_path))
212
+
213
+ assets.first.map do |asset|
214
+ asset.write_to(jekyll.in_dest_dir(File.join(asset_config["prefix"],
215
+ digest?? asset.digest_path : asset.logical_path
216
+ )))
157
217
  end
158
218
  end
159
219
 
160
- #
220
+ # ----------------------------------------------------------------------
161
221
 
162
222
  private
163
223
  def strip_path(path)
164
224
  path.sub(jekyll.in_source_dir("/"), "")
165
225
  end
166
-
167
- #
168
-
169
- private
170
- def as_path(v)
171
- path = digest?? v.digest_path : v.logical_path
172
- jekyll.in_dest_dir(File.join(asset_config[ "prefix"], path))
173
- end
174
226
  end
175
227
  end
176
228
  end
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  module Jekyll
6
8
  module Assets
@@ -11,6 +13,8 @@ module Jekyll
11
13
  end
12
14
  end
13
15
 
16
+ # ----------------------------------------------------------------------
17
+
14
18
  HOOK_ALIASES = {
15
19
  :env => {
16
20
  :post_init => :init,
@@ -18,22 +22,28 @@ module Jekyll
18
22
  }
19
23
  }
20
24
 
25
+ # ----------------------------------------------------------------------
26
+
21
27
  HOOK_POINTS = {
22
28
  :env => [
23
29
  :init
24
30
  ]
25
31
  }
26
32
 
33
+ # ----------------------------------------------------------------------
34
+
27
35
  def self.all
28
36
  @_all ||= {}
29
37
  end
30
38
 
39
+ # ----------------------------------------------------------------------
31
40
  # Trigger a hook, giving an optional block where we pass you the,
32
41
  # proc we got and then you can do as you please (such as instance eval)
33
42
  # but if you do not give us one then we simply pass the args.
43
+ # ----------------------------------------------------------------------
34
44
 
35
45
  def self.trigger(base, point_, *args, &block)
36
- raise ArgumentError, "Do not give args with a block" if args.size > 0 && block_given?
46
+ raise ArgumentError, "Do not give args with a block" if !args.empty? && block_given?
37
47
  if all.key?(base) && all[base].key?(point_)
38
48
  Set.new.merge(point(base, point_, :early)).merge(point(base, point_)).map do |v|
39
49
  block_given?? block.call(v) : v.call(*args)
@@ -41,7 +51,7 @@ module Jekyll
41
51
  end
42
52
  end
43
53
 
44
- #
54
+ # ----------------------------------------------------------------------
45
55
 
46
56
  def self.point(base, point, when_ = :late)
47
57
  point = all[base][point] ||= {
@@ -52,7 +62,7 @@ module Jekyll
52
62
  point[when_]
53
63
  end
54
64
 
55
- #
65
+ # ----------------------------------------------------------------------
56
66
 
57
67
  def self.register(base, point, when_ = :late, &block)
58
68
  raise UnknownHookError, base: base unless HOOK_POINTS.key?(base)
@@ -1,18 +1,18 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  require_relative "hooks/jekyll/drops"
6
8
  require_relative "hooks/jekyll/setup"
7
9
  require_relative "hooks/jekyll/write"
8
-
9
10
  require_relative "hooks/compression"
10
- require_relative "hooks/configuration"
11
- require_relative "hooks/context_patches"
12
- require_relative "hooks/disable_erb"
11
+ require_relative "hooks/config"
13
12
  require_relative "hooks/helpers"
14
13
  require_relative "hooks/logger"
15
14
  require_relative "hooks/sources"
16
15
  require_relative "hooks/sprockets"
17
16
  require_relative "hooks/version"
18
17
  require_relative "hooks/cache"
18
+ require_relative "hooks/erb"
@@ -1,9 +1,17 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  Jekyll::Assets::Hook.register :env, :init do
6
- if (cache_dir = asset_config.fetch("cache", ".asset-cache"))
7
- self.cache = Sprockets::Cache::FileStore.new(jekyll.in_source_dir(cache_dir))
8
+ cache_dir = asset_config.fetch("cache",
9
+ ".asset-cache"
10
+ )
11
+
12
+ if cache_dir
13
+ self.cache = Sprockets::Cache::FileStore.new(
14
+ jekyll.in_source_dir(cache_dir)
15
+ )
8
16
  end
9
17
  end
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
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 compress?("css")
@@ -9,7 +11,15 @@ Jekyll::Assets::Hook.register :env, :init do
9
11
 
10
12
  if compress?("js")
11
13
  try_require "uglifier" do
12
- self.js_compressor = :uglify
14
+ if !jekyll.safe && (opts = self.asset_config.fetch("external", {}).fetch("uglifier", nil))
15
+ self.js_compressor = Uglifier.new(
16
+ opts.symbolize_keys
17
+ )
18
+
19
+ else
20
+ self.js_compressor = \
21
+ :uglify
22
+ end
13
23
  end
14
24
  end
15
25
  end
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  Jekyll::Assets::Hook.register :env, :init, :early do
6
8
  jekyll.config["assets"] = Jekyll::Assets::Config.merge(asset_config)
@@ -0,0 +1,15 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2012 - 2016 - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ Jekyll::Assets::Hook.register :env, :init, :early do
8
+ self.config = hash_reassoc(config, :engines) do |hash|
9
+ hash.delete(
10
+ ".erb"
11
+ )
12
+
13
+ hash
14
+ end
15
+ end
@@ -1,11 +1,12 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
4
-
5
- require "sprockets/helpers"
5
+ # ----------------------------------------------------------------------------
6
6
 
7
7
  Jekyll::Assets::Hook.register :env, :init do
8
8
  Sprockets::Helpers.configure do |config|
9
+ config.manifest = manifest
9
10
  config.prefix = prefix_path
10
11
  config.digest = digest?
11
12
  end
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  Jekyll::Hooks.register :site, :pre_render do |jekyll, payload|
6
8
  payload["assets"] = jekyll.sprockets.to_liquid_payload
@@ -1,13 +1,11 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  Jekyll::Hooks.register :site, :after_reset do |jekyll|
6
- Jekyll::Assets::Env.new(jekyll)
7
-
8
- jekyll.sprockets.excludes.each do |exclude|
9
- unless jekyll.config["exclude"].grep(%r!\A#{Regexp.escape(exclude)}/?!).size > 0
10
- jekyll.config["exclude"] << exclude
11
- end
12
- end
8
+ Jekyll::Assets::Env.init(
9
+ jekyll
10
+ )
13
11
  end