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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -9
  3. data/lib/jekyll-assets.rb +4 -0
  4. data/lib/jekyll/assets.rb +14 -15
  5. data/lib/jekyll/assets/addons.rb +10 -0
  6. data/lib/jekyll/assets/addons/autoprefixer.rb +4 -0
  7. data/lib/jekyll/assets/addons/bootstrap.rb +4 -0
  8. data/lib/jekyll/assets/addons/compass.rb +4 -0
  9. data/lib/jekyll/assets/addons/font_awesome.rb +4 -0
  10. data/lib/jekyll/assets/addons/js_es6.rb +4 -0
  11. data/lib/jekyll/assets/addons/proxies/magick.rb +57 -27
  12. data/lib/jekyll/assets/cached.rb +4 -0
  13. data/lib/jekyll/assets/config.rb +7 -3
  14. data/lib/jekyll/assets/env.rb +68 -107
  15. data/lib/jekyll/assets/hook.rb +19 -12
  16. data/lib/jekyll/assets/hooks.rb +19 -0
  17. data/lib/jekyll/assets/hooks/cache.rb +4 -0
  18. data/lib/jekyll/assets/hooks/compression.rb +4 -0
  19. data/lib/jekyll/assets/hooks/configuration.rb +4 -0
  20. data/lib/jekyll/assets/hooks/context_patches.rb +5 -0
  21. data/lib/jekyll/assets/hooks/disable_erb.rb +4 -0
  22. data/lib/jekyll/assets/hooks/helpers.rb +4 -0
  23. data/lib/jekyll/assets/hooks/jekyll/asset_drops.rb +7 -0
  24. data/lib/jekyll/assets/hooks/jekyll/ignore.rb +9 -0
  25. data/lib/jekyll/{hooks → assets/hooks/jekyll}/initialize.rb +4 -0
  26. data/lib/jekyll/{hooks → assets/hooks/jekyll}/write_assets.rb +4 -0
  27. data/lib/jekyll/assets/hooks/logger.rb +4 -0
  28. data/lib/jekyll/assets/hooks/sources.rb +5 -1
  29. data/lib/jekyll/assets/hooks/sprockets.rb +4 -0
  30. data/lib/jekyll/assets/hooks/version.rb +5 -1
  31. data/lib/jekyll/assets/liquid.rb +13 -0
  32. data/lib/jekyll/assets/liquid/drop.rb +59 -0
  33. data/lib/jekyll/assets/liquid/filters.rb +16 -1
  34. data/lib/jekyll/assets/liquid/tag.rb +61 -37
  35. data/lib/jekyll/assets/liquid/tag/defaults.rb +18 -0
  36. data/lib/jekyll/assets/liquid/tag/defaults/image.rb +51 -0
  37. data/lib/jekyll/assets/liquid/tag/parser.rb +56 -28
  38. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +14 -12
  39. data/lib/jekyll/assets/liquid/tag/proxies.rb +28 -24
  40. data/lib/jekyll/assets/logger.rb +13 -13
  41. data/lib/jekyll/assets/patches.rb +8 -0
  42. data/lib/jekyll/assets/patches/jekyll/cleaner.rb +4 -0
  43. data/lib/jekyll/assets/patches/jekyll/site.rb +4 -0
  44. data/lib/jekyll/assets/patches/kernel.rb +8 -0
  45. data/lib/jekyll/assets/patches/sprockets/asset.rb +6 -2
  46. data/lib/jekyll/assets/version.rb +5 -1
  47. metadata +33 -11
  48. data/lib/jekyll/assets/patches/hash.rb +0 -5
@@ -0,0 +1,18 @@
1
+ module Jekyll
2
+ module Assets
3
+ module Liquid
4
+ class Tag
5
+ module Defaults
6
+ require_relative "defaults/image"
7
+
8
+ module_function
9
+ def set_defaults_for!(tag, args, asset)
10
+ constants.select { |const| const_get(const).is_for?(tag) }.each do |const|
11
+ const_get(const).new(args, asset).set!
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,51 @@
1
+ module Jekyll
2
+ module Assets
3
+ module Liquid
4
+ class Tag
5
+ module Defaults
6
+ class Image
7
+ def self.is_for?(tag)
8
+ tag == "img" || tag == "image"
9
+ end
10
+
11
+ #
12
+
13
+ def initialize(args, asset)
14
+ @asset = asset
15
+ @args = args
16
+ end
17
+
18
+ #
19
+
20
+ def set!
21
+ set_img_dimensions
22
+ set_img_alt
23
+ end
24
+
25
+ #
26
+
27
+ private
28
+ def set_img_alt
29
+ @args[:html] ||= {}
30
+ if !@args[:html].has_key?("alt")
31
+ then @args[:html]["alt"] = @asset.logical_path
32
+ end
33
+ end
34
+
35
+ #
36
+
37
+ private
38
+ def set_img_dimensions
39
+ dimensions = FastImage.new(@asset.filename).size
40
+ return unless dimensions
41
+ @args[:html] ||= {}
42
+
43
+ @args[:html][ "width"] ||= dimensions.first
44
+ @args[:html]["height"] ||= dimensions. last
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,7 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012-2015 - MIT License
3
+ # Encoding: utf-8
4
+
1
5
  require_relative "proxies"
2
6
  require "forwardable"
3
7
 
@@ -5,7 +9,6 @@ module Jekyll
5
9
  module Assets
6
10
  module Liquid
7
11
 
8
- # -----------------------------------------------------------------------
9
12
  # Examples:
10
13
  # - {% tag value argument:value %}
11
14
  # - {% tag value "argument:value" %}
@@ -13,27 +16,27 @@ module Jekyll
13
16
  # - {% tag value argument:value\:with\:colon %}
14
17
  # - {% tag value argument:"I can even escape \\: here too!" %}
15
18
  # - {% tag value proxy:key:value %}
16
- # -----------------------------------------------------------------------
17
19
 
18
20
  class Tag
19
21
  class Parser
20
22
  attr_reader :args, :raw_args
21
23
  extend Forwardable
22
24
 
23
- def_delegator :@args, :to_h
25
+ def_delegator :@args, :each
24
26
  def_delegator :@args, :has_key?
25
- def_delegator :@args, :fetch_or_store
26
27
  def_delegator :@args, :fetch
27
28
  def_delegator :@args, :store
29
+ def_delegator :@args, :to_h
30
+ def_delegator :@args, :[]=
28
31
  def_delegator :@args, :[]
29
32
 
30
- # -------------------------------------------------------------------
33
+ #
31
34
 
32
35
  Accept = {
33
36
  "css" => "text/css", "js" => "application/javascript"
34
37
  }
35
38
 
36
- # -------------------------------------------------------------------
39
+ #
37
40
 
38
41
  class UnescapedColonError < StandardError
39
42
  def initialize
@@ -41,7 +44,7 @@ module Jekyll
41
44
  end
42
45
  end
43
46
 
44
- # -------------------------------------------------------------------
47
+ #
45
48
 
46
49
  class UnknownProxyError < StandardError
47
50
  def initialize
@@ -49,7 +52,7 @@ module Jekyll
49
52
  end
50
53
  end
51
54
 
52
- # -------------------------------------------------------------------
55
+ #
53
56
 
54
57
  def initialize(args, tag)
55
58
  @raw_args, @tags = args, tag
@@ -58,7 +61,14 @@ module Jekyll
58
61
  set_accept
59
62
  end
60
63
 
61
- # -------------------------------------------------------------------
64
+ #
65
+
66
+ def parse_liquid!(context)
67
+ return @args unless context.is_a?(::Liquid::Context)
68
+ @args = _parse_liquid(@args, context)
69
+ end
70
+
71
+ #
62
72
 
63
73
  def to_html
64
74
  @args.fetch(:html, {}).map do |key, val|
@@ -67,7 +77,7 @@ module Jekyll
67
77
  join
68
78
  end
69
79
 
70
- # -------------------------------------------------------------------
80
+ #
71
81
 
72
82
  def proxies
73
83
  keys = (args.keys - Proxies.base_keys - [:file, :html])
@@ -76,13 +86,13 @@ module Jekyll
76
86
  end
77
87
  end
78
88
 
79
- # -------------------------------------------------------------------
89
+ #
80
90
 
81
91
  def has_proxies?
82
92
  proxies.any?
83
93
  end
84
94
 
85
- # -------------------------------------------------------------------
95
+ #
86
96
 
87
97
  private
88
98
  def parse_raw
@@ -92,15 +102,15 @@ module Jekyll
92
102
  parse_col hash, key
93
103
 
94
104
  else
95
- hash.fetch_or_store(:html, {}). \
96
- store(key, true)
105
+ (hash[:html] ||= {})[key] = \
106
+ true
97
107
  end
98
108
 
99
109
  hash
100
110
  end
101
111
  end
102
112
 
103
- # -------------------------------------------------------------------
113
+ #
104
114
 
105
115
  private
106
116
  def parse_col(hash, key)
@@ -111,51 +121,69 @@ module Jekyll
111
121
  end
112
122
  end
113
123
 
114
- # -------------------------------------------------------------------
124
+ #
115
125
 
116
126
  private
117
127
  def as_bool_or_html(hash, key)
118
128
  okey = key; key, sub_key = key
119
129
  if Proxies.has?(key, @tag, "@#{sub_key}")
120
- hash.fetch_or_store(key.to_sym, {}). \
121
- store(sub_key.to_sym, true)
130
+ (hash[key.to_sym] ||= {})[sub_key.to_sym] = true
122
131
  else
123
- hash.fetch_or_store(:html, {}). \
124
- store(key, okey.fetch(1))
132
+ (hash[:html] ||= {})[key] = \
133
+ okey[1]
125
134
  end
126
135
  end
127
136
 
128
- # -------------------------------------------------------------------
137
+ #
129
138
 
130
139
  private
131
140
  def as_proxy(hash, key)
132
141
  key, sub_key, val = key
133
142
  if Proxies.has?(key, @tag, sub_key)
134
- hash.fetch_or_store(key.to_sym, {}). \
135
- store(sub_key.to_sym, val)
143
+ (hash[key.to_sym] ||= {})[sub_key.to_sym] = \
144
+ val
145
+
136
146
  elsif Proxies.has?(key)
137
147
  raise UnknownProxyError
138
148
  end
139
149
  end
140
150
 
141
- # -------------------------------------------------------------------
151
+ #
142
152
 
143
153
  private
144
154
  def set_accept
145
155
  if Accept.has_key?(@tag) && (!@args.has_key?(:sprockets) || \
146
- !@args.fetch(:sprockets).has_Key?(:accept))
156
+ !@args[:sprockets].has_key?(:accept))
147
157
 
148
- @args.fetch_or_store(:sprockets, {}). \
149
- store(:accept, Accept.fetch(@tag))
158
+ (@args[:sprockets] ||= {})[:accept] = \
159
+ Accept[@tag]
150
160
  end
151
161
  end
152
162
 
153
- # -------------------------------------------------------------------
163
+ #
154
164
 
155
165
  private
156
166
  def from_shellwords
157
167
  Shellwords.shellwords(@raw_args)
158
168
  end
169
+
170
+ #
171
+
172
+ def _parse_liquid(hash, context)
173
+ lqd = context.registers[:site].liquid_renderer. \
174
+ file(raw_args)
175
+
176
+ hash.inject({}) do |hsh, (key, val)|
177
+ if val.is_a?(Hash) || val.is_a?(String)
178
+ val = val.is_a?(Hash) ? _parse_liquid(val, context) : \
179
+ lqd.parse(val).render!(context)
180
+ end
181
+
182
+ hsh.update(
183
+ key => val
184
+ )
185
+ end
186
+ end
159
187
  end
160
188
  end
161
189
  end
@@ -1,3 +1,7 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012-2015 - MIT License
3
+ # Encoding: utf-8
4
+
1
5
  require "forwardable"
2
6
 
3
7
  module Jekyll
@@ -9,8 +13,8 @@ module Jekyll
9
13
  extend Forwardable
10
14
 
11
15
  def_delegator :@asset, :liquid_tags
16
+ def_delegator :@asset, :filename, :source_filename
12
17
  def_delegator :@asset, :content_type
13
- def_delegator :@asset, :filename
14
18
 
15
19
  def initialize(asset, args, env, tag)
16
20
  @env = env
@@ -22,41 +26,39 @@ module Jekyll
22
26
  proxy_file
23
27
  end
24
28
 
25
- # -------------------------------------------------------------------
29
+ #
26
30
 
27
31
  def cached?
28
32
  @_cached
29
33
  end
30
34
 
31
- # -------------------------------------------------------------------
35
+ #
32
36
 
33
37
  def source
34
38
  File.binread(filename)
35
39
  end
36
40
 
37
- # -------------------------------------------------------------------
41
+ #
38
42
 
39
43
  def filename
40
44
  env.in_cache_dir(digest_path)
41
45
  end
42
46
 
43
- # -------------------------------------------------------------------
47
+ #
44
48
 
45
49
  def digest
46
50
  Digest::SHA2.hexdigest(args.proxies.to_s)
47
51
  end
48
52
 
49
- # -------------------------------------------------------------------
50
53
  # We always digest a proxied asset so it's uniq based on what
51
54
  # proxies you give us, it would be ignorant to treat it otherwise,
52
55
  # we also make sure they are URL safe by digesting the args.
53
- # -------------------------------------------------------------------
54
56
 
55
57
  def logical_path
56
58
  digest_path
57
59
  end
58
60
 
59
- # -------------------------------------------------------------------
61
+ #
60
62
 
61
63
  def digest_path
62
64
  name = asset.logical_path; ext = File.extname(name)
@@ -65,24 +67,24 @@ module Jekyll
65
67
  }"
66
68
  end
67
69
 
68
- # -------------------------------------------------------------------
70
+ #
69
71
 
70
72
  def write_to(name)
71
73
  File.binwrite(name, source)
72
74
  end
73
75
 
74
- # -------------------------------------------------------------------
76
+ #
75
77
 
76
78
  private
77
79
  def proxy_file
78
80
  unless cached?
79
81
  args.proxies.each do |key, val|
80
- Proxies.get(key).first.fetch(:class).new(self, val).process
82
+ Proxies.get(key).first[:class].new(self, val, @args).process
81
83
  end
82
84
  end
83
85
  end
84
86
 
85
- # -------------------------------------------------------------------
87
+ #
86
88
 
87
89
  private
88
90
  def cache_file
@@ -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
  module Liquid
@@ -17,82 +21,84 @@ module Jekyll
17
21
  all
18
22
  end
19
23
 
20
- # -------------------------------------------------------------------
24
+ #
21
25
 
22
26
  def self.add(name, tag, *args, &block)
23
27
  add_by_class(*generate_class(name, tag, &block), *args)
24
28
  end
25
29
 
26
- # -------------------------------------------------------------------
30
+ #
27
31
 
28
32
  def self.keys
29
- all.select { |val| !val.fetch(:class).is_a?(Symbol) }.map do |v|
30
- v[:name]
33
+ all.select { |val| !val[:class].is_a?(Symbol) }.map do |val|
34
+ val[:name]
31
35
  end. \
32
36
  flatten
33
37
  end
34
38
 
35
- # -------------------------------------------------------------------
39
+ #
36
40
 
37
41
  def self.base_keys
38
- all.select { |val| val.fetch(:class).is_a?(Symbol) }.map do |v|
39
- v[:name]
42
+ all.select { |val| val[:class].is_a?(Symbol) }.map do |val|
43
+ val[:name]
40
44
  end. \
41
45
  flatten
42
46
  end
43
47
 
44
- # -------------------------------------------------------------------
48
+ #
45
49
 
46
50
  def self.has?(name, tag = nil, arg = nil)
47
51
  get(name, tag, arg).any?
48
52
  end
49
53
 
50
- # -------------------------------------------------------------------
54
+ #
51
55
 
52
56
  def self.get(name, tag = nil, arg = nil)
53
57
  if name && tag && arg
54
58
  get_by_name_and_tag_and_arg(
55
59
  name, tag, arg
56
60
  )
61
+
57
62
  elsif name && tag
58
63
  get_by_name_and_tag(
59
64
  name, tag
60
65
  )
66
+
61
67
  else
62
68
  all.select do |val|
63
- val.fetch(:name).include?(name)
69
+ val[:name].include?(name)
64
70
  end
65
71
  end
66
72
  end
67
73
 
68
- # -------------------------------------------------------------------
74
+ #
69
75
 
70
76
  def self.get_by_name_and_tag_and_arg(name, tag, arg)
71
77
  all.select do |val|
72
- (val.fetch(:name).include?(name)) && \
73
- (val.fetch(:tags).include?(:all) || \
74
- val.fetch(:tags).include?(tag)) && \
75
- (val.fetch(:args).include?( arg))
78
+ (val[:name].include?(name)) && \
79
+ (val[:tags].include?(:all) || \
80
+ val[:tags].include?(tag)) && \
81
+ (val[:args].include?( arg))
76
82
  end
77
83
  end
78
84
 
79
- # -------------------------------------------------------------------
85
+ #
80
86
 
81
87
  def self.get_by_name_and_tag(name, tag)
82
88
  all.select do |val|
83
- (val.fetch(:name).include?(name)) &&
84
- (val.fetch(:tags).include?(:all) || \
85
- val.fetch(:tags).include?(tag))
89
+ (val[:name].include?(name)) &&
90
+ (val[:tags].include?(:all) || \
91
+ val[:tags].include?(tag))
86
92
  end
87
93
  end
88
94
 
89
- # -------------------------------------------------------------------
95
+ #
90
96
 
91
97
  def self.all
92
98
  @_all ||= Set.new
93
99
  end
94
100
 
95
- # -------------------------------------------------------------------
101
+ #
96
102
 
97
103
  private
98
104
  def self.generate_class(name, tag, &block)
@@ -101,15 +107,13 @@ module Jekyll
101
107
  return _class, name, tag
102
108
  end
103
109
 
104
- # -------------------------------------------------------------------
110
+ #
105
111
 
106
112
  private
107
113
  def self.random_name
108
114
  (0...12).map { ("a".."z").to_a.values_at(rand(26)) }.join.capitalize
109
115
  end
110
116
 
111
- # -------------------------------------------------------------------
112
-
113
117
  # TODO: Put in a better place.
114
118
  add_by_class :internal, :data, :all, ["@uri"]
115
119
  add_by_class :internal, :sprockets, :all, [