jekyll-assets 2.0.0.pre.beta2 → 2.0.0.pre.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/README.md +33 -40
  4. data/lib/jekyll/assets.rb +18 -16
  5. data/lib/jekyll/assets/addons/autoprefixer.rb +5 -0
  6. data/lib/jekyll/assets/addons/bootstrap.rb +1 -0
  7. data/lib/jekyll/assets/addons/compass.rb +7 -0
  8. data/lib/jekyll/assets/addons/font_awesome.rb +1 -0
  9. data/lib/jekyll/assets/{extras/es6.rb → addons/js_es6.rb} +1 -1
  10. data/lib/jekyll/assets/addons/proxies/magick.rb +92 -0
  11. data/lib/jekyll/assets/config.rb +48 -0
  12. data/lib/jekyll/assets/env.rb +110 -91
  13. data/lib/jekyll/assets/hook.rb +42 -25
  14. data/lib/jekyll/assets/hooks/cache.rb +5 -0
  15. data/lib/jekyll/assets/hooks/compression.rb +11 -0
  16. data/lib/jekyll/assets/hooks/configuration.rb +3 -0
  17. data/lib/jekyll/assets/hooks/context_patches.rb +12 -0
  18. data/lib/jekyll/assets/hooks/disable_erb.rb +6 -0
  19. data/lib/jekyll/assets/hooks/helpers.rb +8 -0
  20. data/lib/jekyll/assets/hooks/logger.rb +3 -0
  21. data/lib/jekyll/assets/hooks/sources.rb +5 -0
  22. data/lib/jekyll/assets/hooks/sprockets.rb +3 -0
  23. data/lib/jekyll/assets/hooks/version.rb +3 -0
  24. data/lib/jekyll/assets/liquid/filters.rb +16 -0
  25. data/lib/jekyll/assets/liquid/tag.rb +162 -0
  26. data/lib/jekyll/assets/liquid/tag/parser.rb +163 -0
  27. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +98 -0
  28. data/lib/jekyll/assets/liquid/tag/proxies.rb +122 -0
  29. data/lib/jekyll/assets/logger.rb +34 -11
  30. data/lib/jekyll/assets/patches/hash.rb +5 -0
  31. data/lib/jekyll/assets/patches/jekyll/cleaner.rb +2 -2
  32. data/lib/jekyll/assets/patches/kernel.rb +31 -0
  33. data/lib/jekyll/assets/patches/sprockets/asset.rb +6 -6
  34. data/lib/jekyll/assets/version.rb +1 -1
  35. data/lib/jekyll/hooks/initialize.rb +3 -0
  36. data/lib/jekyll/hooks/write_assets.rb +3 -0
  37. metadata +28 -17
  38. data/lib/jekyll/assets/configuration.rb +0 -51
  39. data/lib/jekyll/assets/context.rb +0 -23
  40. data/lib/jekyll/assets/extras/font-awesome.rb +0 -1
  41. data/lib/jekyll/assets/extras/helpers.rb +0 -6
  42. data/lib/jekyll/assets/extras/prefix.rb +0 -5
  43. data/lib/jekyll/assets/filters.rb +0 -17
  44. data/lib/jekyll/assets/helpers.rb +0 -37
  45. data/lib/jekyll/assets/hooks/post_read.rb +0 -3
  46. data/lib/jekyll/assets/hooks/post_write.rb +0 -3
  47. data/lib/jekyll/assets/tag.rb +0 -148
  48. data/lib/jekyll/assets/tag/parser.rb +0 -129
  49. data/lib/jekyll/assets/tag/proxied_asset.rb +0 -84
  50. data/lib/jekyll/assets/tag/proxies.rb +0 -86
  51. data/lib/jekyll/assets/tag/proxies/magick.rb +0 -101
@@ -0,0 +1,98 @@
1
+ require "forwardable"
2
+
3
+ module Jekyll
4
+ module Assets
5
+ module Liquid
6
+ class Tag
7
+ class ProxiedAsset
8
+ attr_reader :args, :asset, :env
9
+ extend Forwardable
10
+
11
+ def_delegator :@asset, :liquid_tags
12
+ def_delegator :@asset, :content_type
13
+ def_delegator :@asset, :filename
14
+
15
+ def initialize(asset, args, env, tag)
16
+ @env = env
17
+ @asset = asset
18
+ @args = args
19
+ @tag = tag
20
+
21
+ cache_file
22
+ proxy_file
23
+ end
24
+
25
+ # -------------------------------------------------------------------
26
+
27
+ def cached?
28
+ @_cached
29
+ end
30
+
31
+ # -------------------------------------------------------------------
32
+
33
+ def source
34
+ File.binread(filename)
35
+ end
36
+
37
+ # -------------------------------------------------------------------
38
+
39
+ def filename
40
+ env.in_cache_dir(digest_path)
41
+ end
42
+
43
+ # -------------------------------------------------------------------
44
+
45
+ def digest
46
+ Digest::SHA2.hexdigest(args.proxies.to_s)
47
+ end
48
+
49
+ # -------------------------------------------------------------------
50
+ # We always digest a proxied asset so it's uniq based on what
51
+ # proxies you give us, it would be ignorant to treat it otherwise,
52
+ # we also make sure they are URL safe by digesting the args.
53
+ # -------------------------------------------------------------------
54
+
55
+ def logical_path
56
+ digest_path
57
+ end
58
+
59
+ # -------------------------------------------------------------------
60
+
61
+ def digest_path
62
+ name = asset.logical_path; ext = File.extname(name)
63
+ "#{File.basename(name, ext)}-#{digest}#{
64
+ ext
65
+ }"
66
+ end
67
+
68
+ # -------------------------------------------------------------------
69
+
70
+ def write_to(name)
71
+ File.binwrite(name, source)
72
+ end
73
+
74
+ # -------------------------------------------------------------------
75
+
76
+ private
77
+ def proxy_file
78
+ unless cached?
79
+ args.proxies.each do |key, val|
80
+ Proxies.get(key).first.fetch(:class).new(self, val).process
81
+ end
82
+ end
83
+ end
84
+
85
+ # -------------------------------------------------------------------
86
+
87
+ private
88
+ def cache_file
89
+ if File.file?(filename)
90
+ @_cached = true else @_cached = false
91
+ FileUtils.cp asset.filename, filename
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,122 @@
1
+ module Jekyll
2
+ module Assets
3
+ module Liquid
4
+ class Tag
5
+ module Proxies
6
+ def self.add_by_class(_class, name, tag, *args)
7
+ names = [name, name.to_s, name.to_sym]
8
+ tags = [tag].flatten.map { |v| [v.to_s, v, v.to_sym] }
9
+ args = [args].flatten.map { |v| [v.to_s, v, v.to_sym] }
10
+
11
+ all << {
12
+ :name => names.uniq,
13
+ :tags => tags.flatten.uniq,
14
+ :args => args.flatten.uniq,
15
+ :class => _class
16
+ }
17
+ all
18
+ end
19
+
20
+ # -------------------------------------------------------------------
21
+
22
+ def self.add(name, tag, *args, &block)
23
+ add_by_class(*generate_class(name, tag, &block), *args)
24
+ end
25
+
26
+ # -------------------------------------------------------------------
27
+
28
+ def self.keys
29
+ all.select { |val| !val.fetch(:class).is_a?(Symbol) }.map do |v|
30
+ v[:name]
31
+ end. \
32
+ flatten
33
+ end
34
+
35
+ # -------------------------------------------------------------------
36
+
37
+ def self.base_keys
38
+ all.select { |val| val.fetch(:class).is_a?(Symbol) }.map do |v|
39
+ v[:name]
40
+ end. \
41
+ flatten
42
+ end
43
+
44
+ # -------------------------------------------------------------------
45
+
46
+ def self.has?(name, tag = nil, arg = nil)
47
+ get(name, tag, arg).any?
48
+ end
49
+
50
+ # -------------------------------------------------------------------
51
+
52
+ def self.get(name, tag = nil, arg = nil)
53
+ if name && tag && arg
54
+ get_by_name_and_tag_and_arg(
55
+ name, tag, arg
56
+ )
57
+ elsif name && tag
58
+ get_by_name_and_tag(
59
+ name, tag
60
+ )
61
+ else
62
+ all.select do |val|
63
+ val.fetch(:name).include?(name)
64
+ end
65
+ end
66
+ end
67
+
68
+ # -------------------------------------------------------------------
69
+
70
+ def self.get_by_name_and_tag_and_arg(name, tag, arg)
71
+ 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))
76
+ end
77
+ end
78
+
79
+ # -------------------------------------------------------------------
80
+
81
+ def self.get_by_name_and_tag(name, tag)
82
+ all.select do |val|
83
+ (val.fetch(:name).include?(name)) &&
84
+ (val.fetch(:tags).include?(:all) || \
85
+ val.fetch(:tags).include?(tag))
86
+ end
87
+ end
88
+
89
+ # -------------------------------------------------------------------
90
+
91
+ def self.all
92
+ @_all ||= Set.new
93
+ end
94
+
95
+ # -------------------------------------------------------------------
96
+
97
+ private
98
+ def self.generate_class(name, tag, &block)
99
+ _class = const_set(random_name, Class.new)
100
+ _class. class_eval(&block)
101
+ return _class, name, tag
102
+ end
103
+
104
+ # -------------------------------------------------------------------
105
+
106
+ private
107
+ def self.random_name
108
+ (0...12).map { ("a".."z").to_a.values_at(rand(26)) }.join.capitalize
109
+ end
110
+
111
+ # -------------------------------------------------------------------
112
+
113
+ # TODO: Put in a better place.
114
+ add_by_class :internal, :data, :all, ["@uri"]
115
+ add_by_class :internal, :sprockets, :all, [
116
+ "accept", "write_to"
117
+ ]
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -1,22 +1,45 @@
1
1
  module Jekyll
2
2
  module Assets
3
+ class Logger
4
+ Prefix="Jekyll Assets:"
5
+ def log
6
+ @_log ||= Jekyll.logger
7
+ end
3
8
 
4
- # TODO: jekyll/jekyll@upstream add support for blocks as messages...
5
- # NOTE: This is a temporary class, until we can go upstream and fix
6
- # the little known fact that it doesn't accept a block for a message
7
- # it is passing on. Until then we are holding this.
9
+ # -----------------------------------------------------------------------
10
+ # Log Level: 1
11
+ # -----------------------------------------------------------------------
8
12
 
9
- class Logger
10
- def instance
11
- @logger ||= Jekyll.logger
13
+ def warn(msg = nil, &block)
14
+ log.warn(Prefix, (block_given?? block.call : msg))
12
15
  end
13
16
 
14
- %W(warn error info debug).each do |k|
15
- define_method k do |msg = nil, &block|
16
- instance.send(k, "Jekyll Assets:", block ? block.call : msg)
17
- end
17
+ # -----------------------------------------------------------------------
18
+ # Log Level: 1
19
+ # -----------------------------------------------------------------------
20
+
21
+ def error(msg = nil, &block)
22
+ log.error(Prefix, (block_given?? block.call : msg))
18
23
  end
19
24
 
25
+ # -----------------------------------------------------------------------
26
+ # Log Level: 2
27
+ # -----------------------------------------------------------------------
28
+
29
+ def info(msg = nil, &block)
30
+ log.info(Prefix, (block_given?? block.call : msg))
31
+ end
32
+
33
+ # -----------------------------------------------------------------------
34
+ # Log Level: 3
35
+ # -----------------------------------------------------------------------
36
+
37
+ def debug(msg = nil, &block)
38
+ log.debug(Prefix, (block_given?? block.call : msg))
39
+ end
40
+
41
+ # -----------------------------------------------------------------------
42
+
20
43
  def log_level=(*a)
21
44
  raise RuntimeError, "Please set log levels on Jekyll.logger"
22
45
  end
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def fetch_or_store(key, val)
3
+ fetch(key, nil) || store(key, val)
4
+ end
5
+ end
@@ -3,8 +3,8 @@ module Jekyll
3
3
  # TODO: jekyll/jekyll@upstream: This method should really have a hook ya.
4
4
  alias_method :_old_obsolete_files, :obsolete_files
5
5
  def obsolete_files
6
- _old_obsolete_files.delete_if do |v|
7
- v =~ %r!\A#{Regexp.escape(site.in_dest_dir("assets"))}(\/.*)?\Z!
6
+ _old_obsolete_files.delete_if do |path|
7
+ path =~ %r!\A#{Regexp.escape(site.in_dest_dir("assets"))}(\/.*)?\Z!
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,31 @@
1
+ module Kernel
2
+ def has_javascript?
3
+ require "execjs"
4
+ if block_given?
5
+ yield
6
+ end
7
+ rescue LoadError, ExecJS::RuntimeUnavailable
8
+ Jekyll.logger.debug("ExecJS or JS Runtime not available." \
9
+ " Skipping loading of library.")
10
+ end
11
+
12
+ def try_require(file)
13
+ require file
14
+ if block_given?
15
+ yield
16
+ end
17
+ rescue LoadError
18
+ return nil
19
+ end
20
+
21
+ def try_require_if_javascript(file)
22
+ ["execjs", file].map(&method(:require))
23
+ if block_given?
24
+ yield
25
+ end
26
+ rescue LoadError, ExecJS::RuntimeUnavailable
27
+ Jekyll.logger.debug("ExecJS, JS Runtime or `#{file}' not available." \
28
+ " Skipping the loading of libraries.")
29
+ return
30
+ end
31
+ end
@@ -1,13 +1,13 @@
1
1
  module Sprockets
2
2
  class Asset
3
- def data_uri
4
- "data:#{content_type};base64,#{Rack::Utils.escape \
5
- Base64.encode64(to_s)}"
3
+ def liquid_tags
4
+ metadata.fetch_or_store(:liquid_tags, Set.new)
6
5
  end
7
6
 
8
- def liquid_tags
9
- metadata[:liquid_tags] ||= \
10
- Set.new
7
+ # -------------------------------------------------------------------------
8
+
9
+ def data_uri
10
+ "data:#{content_type};base64,#{Rack::Utils.escape(Base64.encode64(to_s))}"
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Assets
3
- VERSION="2.0.0.pre.beta2"
3
+ VERSION="2.0.0.pre.beta3"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ Jekyll::Hooks.register :site, :post_read do |jekyll|
2
+ Jekyll::Assets::Env.new(jekyll)
3
+ end
@@ -0,0 +1,3 @@
1
+ Jekyll::Hooks.register :site, :post_write do |jekyll|
2
+ jekyll.sprockets.write_all
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.beta2
4
+ version: 2.0.0.pre.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-23 00:00:00.000000000 Z
13
+ date: 2015-10-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sprockets
@@ -128,29 +128,40 @@ files:
128
128
  - Rakefile
129
129
  - lib/jekyll-assets.rb
130
130
  - lib/jekyll/assets.rb
131
+ - lib/jekyll/assets/addons/autoprefixer.rb
132
+ - lib/jekyll/assets/addons/bootstrap.rb
133
+ - lib/jekyll/assets/addons/compass.rb
134
+ - lib/jekyll/assets/addons/font_awesome.rb
135
+ - lib/jekyll/assets/addons/js_es6.rb
136
+ - lib/jekyll/assets/addons/proxies/magick.rb
131
137
  - lib/jekyll/assets/cached.rb
132
- - lib/jekyll/assets/configuration.rb
133
- - lib/jekyll/assets/context.rb
138
+ - lib/jekyll/assets/config.rb
134
139
  - lib/jekyll/assets/env.rb
135
- - lib/jekyll/assets/extras/es6.rb
136
- - lib/jekyll/assets/extras/font-awesome.rb
137
- - lib/jekyll/assets/extras/helpers.rb
138
- - lib/jekyll/assets/extras/prefix.rb
139
- - lib/jekyll/assets/filters.rb
140
- - lib/jekyll/assets/helpers.rb
141
140
  - lib/jekyll/assets/hook.rb
142
- - lib/jekyll/assets/hooks/post_read.rb
143
- - lib/jekyll/assets/hooks/post_write.rb
141
+ - lib/jekyll/assets/hooks/cache.rb
142
+ - lib/jekyll/assets/hooks/compression.rb
143
+ - lib/jekyll/assets/hooks/configuration.rb
144
+ - lib/jekyll/assets/hooks/context_patches.rb
145
+ - lib/jekyll/assets/hooks/disable_erb.rb
146
+ - lib/jekyll/assets/hooks/helpers.rb
147
+ - lib/jekyll/assets/hooks/logger.rb
148
+ - lib/jekyll/assets/hooks/sources.rb
149
+ - lib/jekyll/assets/hooks/sprockets.rb
150
+ - lib/jekyll/assets/hooks/version.rb
151
+ - lib/jekyll/assets/liquid/filters.rb
152
+ - lib/jekyll/assets/liquid/tag.rb
153
+ - lib/jekyll/assets/liquid/tag/parser.rb
154
+ - lib/jekyll/assets/liquid/tag/proxied_asset.rb
155
+ - lib/jekyll/assets/liquid/tag/proxies.rb
144
156
  - lib/jekyll/assets/logger.rb
157
+ - lib/jekyll/assets/patches/hash.rb
145
158
  - lib/jekyll/assets/patches/jekyll/cleaner.rb
146
159
  - lib/jekyll/assets/patches/jekyll/site.rb
160
+ - lib/jekyll/assets/patches/kernel.rb
147
161
  - lib/jekyll/assets/patches/sprockets/asset.rb
148
- - lib/jekyll/assets/tag.rb
149
- - lib/jekyll/assets/tag/parser.rb
150
- - lib/jekyll/assets/tag/proxied_asset.rb
151
- - lib/jekyll/assets/tag/proxies.rb
152
- - lib/jekyll/assets/tag/proxies/magick.rb
153
162
  - lib/jekyll/assets/version.rb
163
+ - lib/jekyll/hooks/initialize.rb
164
+ - lib/jekyll/hooks/write_assets.rb
154
165
  homepage: http://github.com/jekyll-assets/jekyll-assets/
155
166
  licenses:
156
167
  - MIT
@@ -1,51 +0,0 @@
1
- module Jekyll
2
- module Assets
3
- module Configuration
4
- DEVELOPMENT = {
5
- "skip_prefix_with_cdn" => false,
6
- "prefix" => "/assets",
7
- "digest" => false,
8
- "assets" => [],
9
-
10
- "compress" => {
11
- "css" => false,
12
- "js" => false
13
- },
14
-
15
- "sources" => [
16
- "_assets/css", "_assets/stylesheets",
17
- "_assets/images", "_assets/img", "_assets/fonts",
18
- "_assets/javascripts", "_assets/js"
19
- ]
20
- }
21
-
22
- PRODUCTION = DEVELOPMENT.merge({
23
- "digest" => true,
24
- "compress" => {
25
- "css" => true,
26
- "js" => true
27
- },
28
- })
29
-
30
- def self.defaults
31
- %W(development test).include?(Jekyll.env) ? \
32
- DEVELOPMENT : PRODUCTION
33
- end
34
-
35
- def self.merge(merge_into, config = self.defaults)
36
- merge_into = merge_into.dup
37
- config.each_with_object(merge_into) do |(k, v), h|
38
- if !h.has_key?(k) || (v.is_a?(Hash) && !h[k])
39
- h[k] = v
40
-
41
- elsif v.is_a?(Hash)
42
- h[k] = merge h[k], \
43
- v
44
- end
45
- end
46
-
47
- merge_into
48
- end
49
- end
50
- end
51
- end