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
@@ -5,8 +5,10 @@ module Jekyll
5
5
  module Defaults
6
6
  require_relative "defaults/image"
7
7
 
8
+ # ------------------------------------------------------------------
8
9
  # TODO: In 3.0 env needs to be enforced, right now it's not
9
10
  # because it's maintain 2.0 API.
11
+ # ------------------------------------------------------------------
10
12
 
11
13
  module_function
12
14
  def set_defaults_for!(tag, args, asset, env = nil)
@@ -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,8 +14,10 @@ module Jekyll
12
14
  tag == "img" || tag == "image"
13
15
  end
14
16
 
17
+ # ----------------------------------------------------------------
15
18
  # TODO: In 3.0 env needs to be enforced if this is not changed,
16
19
  # for now it's not enforced to maintain the 2.0 API.
20
+ # ----------------------------------------------------------------
17
21
 
18
22
  def initialize(args, asset, env = nil)
19
23
  @args = args
@@ -21,14 +25,16 @@ module Jekyll
21
25
  @env = env
22
26
  end
23
27
 
24
- #
28
+ # ----------------------------------------------------------------
25
29
 
26
30
  def set!
27
31
  set_img_dimensions
28
32
  set_img_alt
29
33
  end
30
34
 
35
+ # ----------------------------------------------------------------
31
36
  # TODO: 3.0 - Remove the `!@env`
37
+ # ----------------------------------------------------------------
32
38
 
33
39
  private
34
40
  def set_img_alt
@@ -40,17 +46,31 @@ module Jekyll
40
46
  end
41
47
  end
42
48
 
49
+ # ----------------------------------------------------------------
43
50
  # TODO: 3.0 - Remove the `!@env`
51
+ # ----------------------------------------------------------------
44
52
 
45
53
  private
46
54
  def set_img_dimensions
47
- if !@env || @env.asset_config["features"]["automatic_img_size"]
55
+ resize_image = @env.asset_config["features"]["automatic_img_size"]
56
+
57
+ if !@env || resize_image
48
58
  dimensions = FastImage.new(@asset.filename).size
49
59
  return unless dimensions
50
60
  @args[:html] ||= {}
51
61
 
52
- @args[:html][ "width"] ||= dimensions.first
53
- @args[:html]["height"] ||= dimensions. last
62
+ if resize_image =~ /^\d+$/
63
+ width = (dimensions.first / resize_image.to_f).floor
64
+ height = (dimensions. last / resize_image.to_f).floor
65
+
66
+ else
67
+ width = dimensions.first
68
+ height = dimensions. last
69
+ end
70
+
71
+
72
+ @args[:html][ "width"] ||= width
73
+ @args[:html]["height"] ||= height
54
74
  end
55
75
  end
56
76
  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
  require_relative "proxies"
6
8
  require "forwardable"
@@ -9,6 +11,7 @@ module Jekyll
9
11
  module Assets
10
12
  module Liquid
11
13
 
14
+ # ----------------------------------------------------------------------
12
15
  # Examples:
13
16
  # - {% tag value argument:value %}
14
17
  # - {% tag value "argument:value" %}
@@ -16,6 +19,7 @@ module Jekyll
16
19
  # - {% tag value argument:value\:with\:colon %}
17
20
  # - {% tag value argument:"I can even escape \\: here too!" %}
18
21
  # - {% tag value proxy:key:value %}
22
+ # ----------------------------------------------------------------------
19
23
 
20
24
  class Tag
21
25
  class Parser
@@ -30,13 +34,13 @@ module Jekyll
30
34
  def_delegator :@args, :[]=
31
35
  def_delegator :@args, :[]
32
36
 
33
- #
37
+ # ------------------------------------------------------------------
34
38
 
35
39
  ACCEPT = {
36
40
  "css" => "text/css", "js" => "application/javascript"
37
41
  }
38
42
 
39
- #
43
+ # ------------------------------------------------------------------
40
44
 
41
45
  class UnescapedColonError < StandardError
42
46
  def initialize
@@ -44,7 +48,7 @@ module Jekyll
44
48
  end
45
49
  end
46
50
 
47
- #
51
+ # ------------------------------------------------------------------
48
52
 
49
53
  class UnknownProxyError < StandardError
50
54
  def initialize
@@ -52,7 +56,7 @@ module Jekyll
52
56
  end
53
57
  end
54
58
 
55
- #
59
+ # ------------------------------------------------------------------
56
60
 
57
61
  def initialize(args, tag, processed: false, raw_args: nil)
58
62
  if processed && raw_args
@@ -72,23 +76,27 @@ module Jekyll
72
76
  end
73
77
  end
74
78
 
75
- #
79
+ # ------------------------------------------------------------------
76
80
 
77
81
  def parse_liquid(context)
78
82
  return self unless context.is_a?(Object::Liquid::Context)
79
83
  liquid = context.registers[:site].liquid_renderer.file("(jekyll:assets)")
80
84
  out = parse_hash_liquid(to_h, liquid, context)
81
- self.class.new(out, @tag, raw_args: @raw_args, \
82
- processed: true)
85
+ self.class.new(out, @tag, {
86
+ :raw_args => @raw_args,
87
+ :processed => true
88
+ })
83
89
  end
84
90
 
91
+ # ------------------------------------------------------------------
92
+
85
93
  def to_html
86
94
  (self[:html] || {}).map do |key, val|
87
- %{ #{key}="#{val}"}
95
+ %( #{key}="#{val}")
88
96
  end.join
89
97
  end
90
98
 
91
- #
99
+ # ------------------------------------------------------------------
92
100
 
93
101
  def proxies
94
102
  keys = (args.keys - Proxies.base_keys - [:file, :html])
@@ -97,13 +105,13 @@ module Jekyll
97
105
  end
98
106
  end
99
107
 
100
- #
108
+ # ------------------------------------------------------------------
101
109
 
102
110
  def proxies?
103
111
  proxies.any?
104
112
  end
105
113
 
106
- #
114
+ # ------------------------------------------------------------------
107
115
 
108
116
  private
109
117
  def parse_hash_liquid(hash_, liquid, context)
@@ -114,7 +122,7 @@ module Jekyll
114
122
  end
115
123
  end
116
124
 
117
- #
125
+ # ------------------------------------------------------------------
118
126
 
119
127
  private
120
128
  def parse_raw
@@ -131,17 +139,17 @@ module Jekyll
131
139
  end
132
140
  end
133
141
 
134
- #
142
+ # ------------------------------------------------------------------
135
143
 
136
144
  private
137
145
  def parse_col(hash, key)
138
146
  key.push(key.delete_at(-1).gsub(/\\:/, ":"))
139
147
  return as_proxy hash, key if key.size == 3
140
- return as_bool_or_html hash, key if key.size == 2
148
+ return as_bool_or_html hash, key if key.size == 2 || key.size == 1
141
149
  raise UnescapedColonError
142
150
  end
143
151
 
144
- #
152
+ # ------------------------------------------------------------------
145
153
 
146
154
  private
147
155
  def as_bool_or_html(hash, key)
@@ -155,7 +163,7 @@ module Jekyll
155
163
  end
156
164
  end
157
165
 
158
- #
166
+ # ------------------------------------------------------------------
159
167
 
160
168
  private
161
169
  def as_proxy(hash, key)
@@ -169,7 +177,7 @@ module Jekyll
169
177
  end
170
178
  end
171
179
 
172
- #
180
+ # ------------------------------------------------------------------
173
181
 
174
182
  private
175
183
  def set_accept
@@ -181,7 +189,7 @@ module Jekyll
181
189
  end
182
190
  end
183
191
 
184
- #
192
+ # ------------------------------------------------------------------
185
193
 
186
194
  private
187
195
  def from_shellwords
@@ -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
  require "forwardable"
6
8
 
@@ -12,9 +14,14 @@ module Jekyll
12
14
  attr_reader :args, :asset, :env
13
15
  extend Forwardable
14
16
 
17
+ # ------------------------------------------------------------------
18
+
15
19
  def_delegator :@asset, :liquid_tags
16
20
  def_delegator :@asset, :filename, :source_filename
17
21
  def_delegator :@asset, :content_type
22
+ def_delegator :@asset, :mtime
23
+
24
+ # ------------------------------------------------------------------
18
25
 
19
26
  def initialize(asset, args, env, tag)
20
27
  @env = env
@@ -26,56 +33,58 @@ module Jekyll
26
33
  proxy_file
27
34
  end
28
35
 
29
- #
36
+ # ------------------------------------------------------------------
30
37
 
31
38
  def cached?
32
39
  @_cached
33
40
  end
34
41
 
35
- #
42
+ # ------------------------------------------------------------------
43
+
44
+ def write_to(name)
45
+ FileUtils.mkdir_p File.dirname(name)
46
+ Sprockets::PathUtils.atomic_write(name) do |f|
47
+ f.write source
48
+ end
49
+ end
50
+
51
+ # ------------------------------------------------------------------
36
52
 
37
53
  def source
38
54
  File.binread(filename)
39
55
  end
40
56
 
41
- #
57
+ # ------------------------------------------------------------------
42
58
 
43
59
  def filename
44
60
  env.in_cache_dir(digest_path)
45
61
  end
46
62
 
47
- #
63
+ # ------------------------------------------------------------------
48
64
 
49
65
  def digest
50
66
  Digest::SHA2.hexdigest(args.proxies.to_s)
51
67
  end
52
68
 
69
+ # ------------------------------------------------------------------
53
70
  # We always digest a proxied asset so it's uniq based on what
54
71
  # proxies you give us, it would be ignorant to treat it otherwise,
55
72
  # we also make sure they are URL safe by digesting the args.
73
+ # ------------------------------------------------------------------
56
74
 
57
75
  def logical_path
58
76
  digest_path
59
77
  end
60
78
 
61
- #
79
+ # ------------------------------------------------------------------
62
80
 
63
81
  def digest_path
64
82
  name = asset.logical_path
65
83
  ext = File.extname(name)
66
- "#{File.basename(name, ext)}-#{digest}#{ext}"
84
+ "#{name.chomp(ext)}-#{digest}#{ext}"
67
85
  end
68
86
 
69
- #
70
-
71
- def write_to(name)
72
- FileUtils.mkdir_p File.dirname(name)
73
- Sprockets::PathUtils.atomic_write(name) do |f|
74
- f.write source
75
- end
76
- end
77
-
78
- #
87
+ # ------------------------------------------------------------------
79
88
 
80
89
  private
81
90
  def proxy_file
@@ -86,13 +95,17 @@ module Jekyll
86
95
  end
87
96
  end
88
97
 
89
- #
98
+ # ------------------------------------------------------------------
90
99
 
91
100
  private
92
101
  def cache_file
93
102
  @_cached = File.file?(filename)
94
- FileUtils.cp asset.filename, filename unless @_cached
95
- @_cached
103
+ return @_cached if @_cached
104
+
105
+ dir = File.dirname(filename)
106
+ FileUtils.mkdir_p dir unless dir == env.in_cache_dir
107
+ FileUtils.cp asset.filename, filename
108
+ true
96
109
  end
97
110
  end
98
111
  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
@@ -19,13 +21,13 @@ module Jekyll
19
21
  all
20
22
  end
21
23
 
22
- #
24
+ # ------------------------------------------------------------------
23
25
 
24
26
  def self.add(name, tag, *args, &block)
25
27
  add_by_class(*generate_class(name, tag, &block), *args)
26
28
  end
27
29
 
28
- #
30
+ # ------------------------------------------------------------------
29
31
 
30
32
  def self.keys
31
33
  all.select { |val| !val[:class].is_a?(Symbol) }.map do |val|
@@ -33,7 +35,7 @@ module Jekyll
33
35
  end.flatten
34
36
  end
35
37
 
36
- #
38
+ # ------------------------------------------------------------------
37
39
 
38
40
  def self.base_keys
39
41
  all.select { |val| val[:class].is_a?(Symbol) }.map do |val|
@@ -41,13 +43,13 @@ module Jekyll
41
43
  end.flatten
42
44
  end
43
45
 
44
- #
46
+ # ------------------------------------------------------------------
45
47
 
46
48
  def self.has?(name, tag = nil, arg = nil)
47
49
  get(name, tag, arg).any?
48
50
  end
49
51
 
50
- #
52
+ # ------------------------------------------------------------------
51
53
 
52
54
  def self.get(name, tag = nil, arg = nil)
53
55
  if name && tag && arg then get_by_name_and_tag_and_arg(name, tag, arg)
@@ -61,7 +63,7 @@ module Jekyll
61
63
  end
62
64
  end
63
65
 
64
- #
66
+ # ------------------------------------------------------------------
65
67
 
66
68
  def self.get_by_name_and_tag_and_arg(name, tag, arg)
67
69
  all.select do |val|
@@ -70,7 +72,7 @@ module Jekyll
70
72
  end
71
73
  end
72
74
 
73
- #
75
+ # ------------------------------------------------------------------
74
76
 
75
77
  def self.get_by_name_and_tag(name, tag)
76
78
  all.select do |val|
@@ -79,33 +81,36 @@ module Jekyll
79
81
  end
80
82
  end
81
83
 
82
- #
84
+ # ------------------------------------------------------------------
83
85
 
84
86
  def self.all
85
87
  @_all ||= Set.new
86
88
  end
87
89
 
88
- #
90
+ # ------------------------------------------------------------------
89
91
 
90
- private
92
+ private_class_method
91
93
  def self.generate_class(name, tag, &block)
92
94
  class_ = const_set(random_name, Class.new)
93
95
  class_.class_eval(&block)
94
96
  return class_, name, tag
95
97
  end
96
98
 
97
- #
99
+ # ------------------------------------------------------------------
98
100
 
99
- private
101
+ private_class_method
100
102
  def self.random_name
101
103
  (0...12).map { ("a".."z").to_a.values_at(rand(26)) }.join.capitalize
102
104
  end
103
105
 
106
+ # ------------------------------------------------------------------
104
107
  # TODO: Put in a better place.
108
+ # ------------------------------------------------------------------
109
+
105
110
  add_by_class :internal, :data, :all, ["@uri"]
106
- add_by_class :internal, :sprockets, :all, [
107
- "accept", "write_to"
108
- ]
111
+ add_by_class :internal, :sprockets, :all, %W(
112
+ accept write_to
113
+ )
109
114
  end
110
115
  end
111
116
  end