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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,23 +0,0 @@
1
- module Jekyll
2
- module Assets
3
- class Context
4
- def initialize(context)
5
- patch context
6
- end
7
-
8
- def patch(what)
9
- what.class_eval do
10
- alias_method :_old_asset_path, :asset_path
11
- def asset_path(asset, opts = {})
12
- out = _old_asset_path asset
13
- return unless out
14
-
15
- environment.parent.used.add(environment.find_asset \
16
- resolve(asset))
17
- out
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1 +0,0 @@
1
- Jekyll::Assets::Helpers.try_require "font-awesome-sass"
@@ -1,6 +0,0 @@
1
- Jekyll::Assets::Hook.register :env, :post_init do |e|
2
- Sprockets::Helpers.configure do |c|
3
- c.prefix = e.prefix_path
4
- c.digest = e.digest?
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- Jekyll::Assets::Helpers.try_require_if_javascript? "autoprefixer-rails" do
2
- Jekyll::Assets::Hook.register :env, :post_init do |e|
3
- AutoprefixerRails.install(e)
4
- end
5
- end
@@ -1,17 +0,0 @@
1
- module Jekyll
2
- module Assets
3
- module Filters
4
- %W(js css img image javascript stylesheet style asset_path).each do |v|
5
- define_method v do |path, args = ""|
6
- Tag.send(:new, v, "#{path} #{args}", "").render(
7
- @context
8
- )
9
- end
10
- end
11
- end
12
- end
13
- end
14
-
15
- Liquid::Template.register_filter(
16
- Jekyll::Assets::Filters
17
- )
@@ -1,37 +0,0 @@
1
- module Jekyll
2
- module Assets
3
- module Helpers
4
- class << self
5
- def has_javascript?
6
- require "execjs"
7
- if block_given?
8
- yield
9
- end
10
- rescue LoadError, ExecJS::RuntimeUnavailable
11
- Jekyll.logger.debug("ExecJS or JS Runtime not available." \
12
- " Skipping loading of library.")
13
- end
14
-
15
- def try_require(file)
16
- require file
17
- if block_given?
18
- yield
19
- end
20
- rescue LoadError
21
- return nil
22
- end
23
-
24
- def try_require_if_javascript?(file)
25
- ["execjs", file].map(&method(:require))
26
- if block_given?
27
- yield
28
- end
29
- rescue LoadError, ExecJS::RuntimeUnavailable
30
- Jekyll.logger.debug("ExecJS, JS Runtime or `#{file}' not available." \
31
- " Skipping the loading of libraries.")
32
- return
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,3 +0,0 @@
1
- Jekyll::Hooks.register :site, :post_read do |s|
2
- Jekyll::Assets::Env.new(s)
3
- end
@@ -1,3 +0,0 @@
1
- Jekyll::Hooks.register :site, :post_write do |s|
2
- s.sprockets.write_all
3
- end
@@ -1,148 +0,0 @@
1
- module Jekyll
2
- module Assets
3
-
4
- # TODO: Somewhere in here we need to designate the proxy as an asset
5
- # so that the env does not need to be aware of anything.
6
-
7
- class Tag < Liquid::Tag
8
- require_relative "tag/proxied_asset"
9
- require_relative "tag/parser"
10
- attr_reader :args
11
-
12
- class AssetNotFoundError < StandardError
13
- def initialize(asset)
14
- super "Could not find the asset `#{asset}'"
15
- end
16
- end
17
-
18
- TAGS = {
19
- "css" => %Q{<link type="text/css" rel="stylesheet" href="%s"%s>},
20
- "js" => %Q{<script type="text/javascript" src="%s"%s></script>},
21
- "img" => %Q{<img src="%s"%s>}
22
- }
23
-
24
- ALIAS = {
25
- "image" => "img",
26
- "stylesheet" => "css",
27
- "javascript" => "js",
28
- "style" => "css"
29
- }
30
-
31
- def initialize(tag, args, tokens)
32
- @tokens = tokens
33
- @tag = from_alias(tag)
34
- @args = Parser.new(args, @tag)
35
- @og_tag = tag
36
- super
37
- end
38
-
39
- # NOTE: We only attach to the regenerator if you are using digested
40
- # assets, otherwise we forego any association with it so that we keep
41
- # your builds ultra fast, this is ideal in dev. Disable digests and
42
- # let us process independent so the entire site isn't regenerated
43
- # because of a single asset change.
44
-
45
- def render(context)
46
- site = context.registers[:site]
47
- page = context.registers.fetch(:page, {}).fetch("path", nil)
48
- sprockets = site.sprockets
49
-
50
- asset = find_asset(sprockets)
51
- add_as_jekyll_dependency(site, sprockets, page, asset)
52
- process_tag(sprockets, asset)
53
- rescue => e
54
- capture_and_out_error \
55
- site, e
56
- end
57
-
58
- private
59
- def from_alias(tag)
60
- ALIAS[tag] || \
61
- tag
62
- end
63
-
64
- private
65
- def process_tag(sprockets, asset)
66
- set_img_alt asset if @tag == "img"
67
- out = get_path sprockets, asset
68
- sprockets.used.add(asset)
69
-
70
- if @tag == "asset_path"
71
- return out
72
-
73
- elsif @tag == "asset" || @tag == "asset_source"
74
- return asset.to_s
75
-
76
- elsif @args[:data][:uri]
77
- return TAGS[@tag] % [
78
- asset.data_uri, @args.to_html
79
- ]
80
-
81
- else
82
- return TAGS[@tag] % [
83
- out, @args.to_html
84
- ]
85
- end
86
- end
87
-
88
- private
89
- def get_path(sprockets, asset)
90
- sprockets.prefix_path(
91
- sprockets.digest?? asset.digest_path : asset.logical_path
92
- )
93
- end
94
-
95
- private
96
- def set_img_alt(asset)
97
- if !@args[:html]["alt"]
98
- return @args[:html]["alt"] = asset.logical_path
99
- end
100
- end
101
-
102
- private
103
- def add_as_jekyll_dependency(site, sprockets, page, asset)
104
- if page && sprockets.digest?
105
- site.regenerator.add_dependency(
106
- site.in_source_dir(page), site.in_source_dir(asset.logical_path)
107
- )
108
- end
109
- end
110
-
111
- private
112
- def find_asset(sprockets)
113
- if !(out = sprockets.find_asset(@args[:file], @args[:sprockets]))
114
- raise AssetNotFoundError, @args[:file]
115
- else
116
- out.liquid_tags << self
117
- if !@args.has_proxies?
118
- out else ProxiedAsset.new(
119
- out, @args, sprockets, self
120
- )
121
- end
122
- end
123
- end
124
-
125
- # There is no guarantee that Jekyll will pass on the error for
126
- # some reason (unless you are just booting up) so we capture that error
127
- # and always output it, it can lead to some double errors but
128
- # I would rather there be a double error than no error.
129
-
130
- private
131
- def capture_and_out_error(site, error)
132
- if error.is_a?(Sass::SyntaxError)
133
- file = error.sass_filename.gsub(/#{Regexp.escape(site.source)}\//, "")
134
- Jekyll.logger.error(%Q{Error in #{file}:#{error.sass_line} #{error}})
135
- else
136
- Jekyll.logger.error \
137
- "", error.to_s
138
- end
139
-
140
- raise error
141
- end
142
- end
143
- end
144
- end
145
-
146
- %W(js css img image javascript stylesheet style asset_path asset_source asset).each do |t|
147
- Liquid::Template.register_tag t, Jekyll::Assets::Tag
148
- end
@@ -1,129 +0,0 @@
1
- require_relative "proxies"
2
- require "forwardable"
3
-
4
- module Jekyll
5
- module Assets
6
-
7
- # Examples:
8
- # - {% tag value argument:value %}
9
- # - {% tag value "argument:value" %}
10
- # - {% tag value argument:"I have spaces" %}
11
- # - {% tag value argument:value\:with\:colon %}
12
- # - {% tag value argument:"I can even escape \\: here too!" %}
13
- # - {% tag value proxy:key:value %}
14
-
15
- class Tag
16
- class Parser
17
- attr_reader :args, :raw_args
18
- extend Forwardable
19
-
20
- def_delegator :@args, :to_h
21
- def_delegator :@args, :has_key?
22
- def_delegator :@args, :fetch
23
- def_delegator :@args, :[]
24
-
25
- ACCEPT = {
26
- "css" => "text/css", "js" => "application/javascript"
27
- }
28
-
29
- class UnescapedColonError < StandardError
30
- def initialize
31
- super "Unescaped double colon argument."
32
- end
33
- end
34
-
35
- class UnknownProxyError < StandardError
36
- def initialize
37
- super "Unknown proxy argument."
38
- end
39
- end
40
-
41
- def initialize(args, tag)
42
- @raw_args, @tags = args, tag
43
- @tag = tag
44
- parse_raw
45
- set_accept
46
- end
47
-
48
- def to_html
49
- @args[:html].map do |k, v|
50
- %Q{ #{k}="#{v}"}
51
- end. \
52
- join
53
- end
54
-
55
- def proxies
56
- keys = (args.keys - Proxies.base_keys - [:file, :html])
57
- args.select do |k, v|
58
- keys.include?(k)
59
- end
60
- end
61
-
62
- def has_proxies?
63
- proxies.any?
64
- end
65
-
66
- private
67
- def parse_raw
68
- @args = from_shellwords.each_with_index.inject(dhash) do |h, (k, i)|
69
- if i == 0 then h[:file] = k
70
- elsif k =~ /:/ && (k = k.split(/(?<!\\):/)) then parse_col h, k
71
- else h[:html][k] = true
72
- end
73
-
74
- h
75
- end
76
- end
77
-
78
- private
79
- def parse_col(h, k)
80
- k[-1] = k[-1].gsub(/\\:/, ":")
81
- if k.size == 3 then as_proxy h, k
82
- elsif k.size == 2 then as_bool_or_html h, k
83
- else raise UnescapedColonError
84
- end
85
- end
86
-
87
- private
88
- def as_bool_or_html(h, k)
89
- key, sub_key = k
90
- if Proxies.has?(key, @tag, "@#{sub_key}")
91
- h[key.to_sym][sub_key.to_sym] = true
92
- else
93
- h[:html][key] = k[1]
94
- end
95
- end
96
-
97
- private
98
- def as_proxy(h, k)
99
- key, sub_key, value = k
100
- if Proxies.has?(key, @tag, sub_key)
101
- h[key.to_sym][sub_key.to_sym] = \
102
- value
103
- elsif Proxies.has?(key)
104
- raise UnknownProxyError
105
- end
106
- end
107
-
108
- private
109
- def set_accept
110
- if (accept = ACCEPT[@tag]) && !args[:sprockets][:accept]
111
- @args[:sprockets][:accept] = accept
112
- end
113
- end
114
-
115
- private
116
- def dhash
117
- Hash.new do |h, k|
118
- h[k] = {}
119
- end
120
- end
121
-
122
- private
123
- def from_shellwords
124
- Shellwords.shellwords(@raw_args)
125
- end
126
- end
127
- end
128
- end
129
- end
@@ -1,84 +0,0 @@
1
- require "forwardable"
2
-
3
- module Jekyll
4
- module Assets
5
- class Tag
6
- class ProxiedAsset
7
- attr_reader :args, :asset, :env
8
- extend Forwardable
9
-
10
- def_delegator :@asset, :liquid_tags
11
- def_delegator :@asset, :content_type
12
- def_delegator :@asset, :filename
13
-
14
- def initialize(asset, args, env, tag)
15
- @env = env
16
- @asset = asset
17
- @args = args
18
- @tag = tag
19
- cache_file
20
- proxy_file
21
- end
22
-
23
- def cached?
24
- @_cached
25
- end
26
-
27
- def source
28
- File.binread(
29
- filename
30
- )
31
- end
32
-
33
- def filename
34
- env.in_cache_dir(
35
- digest_path
36
- )
37
- end
38
-
39
- def digest
40
- Digest::SHA2.hexdigest(
41
- args.proxies.to_s
42
- )
43
- end
44
-
45
- # We always digest a proxied asset so it's uniq based on what
46
- # proxies you give us, it would be ignorant to treat it otherwise,
47
- # we also make sure they are URL safe by digesting the args.
48
-
49
- def logical_path
50
- digest_path
51
- end
52
-
53
- def digest_path
54
- name = asset.logical_path
55
- ext = File.extname(name)
56
- "#{File.basename(name, ext)}-#{digest}#{ext}"
57
- end
58
-
59
- def write_to(name)
60
- File.binwrite(
61
- name, source
62
- )
63
- end
64
-
65
- private
66
- def proxy_file
67
- unless cached?
68
- args.proxies.each do |k, v|
69
- Proxies.get(k).first[:cls].new(self, v).process
70
- end
71
- end
72
- end
73
-
74
- private
75
- def cache_file
76
- if File.file?(filename)
77
- @_cached = true else @_cached = false
78
- FileUtils.cp asset.filename, filename
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end