jekyll-assets 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +13 -9
  3. data/README.md +36 -10
  4. data/Rakefile +40 -0
  5. data/lib/jekyll/assets.rb +13 -10
  6. data/lib/jekyll/assets/addons.rb +7 -6
  7. data/lib/jekyll/assets/addons/processors/liquid.rb +31 -0
  8. data/lib/jekyll/assets/addons/proxies/magick.rb +10 -8
  9. data/lib/jekyll/assets/config.rb +11 -8
  10. data/lib/jekyll/assets/env.rb +33 -17
  11. data/lib/jekyll/assets/hook.rb +17 -18
  12. data/lib/jekyll/assets/hooks.rb +13 -14
  13. data/lib/jekyll/assets/hooks/context_patches.rb +2 -2
  14. data/lib/jekyll/assets/hooks/helpers.rb +1 -1
  15. data/lib/jekyll/assets/hooks/jekyll/{asset_drops.rb → drops.rb} +1 -1
  16. data/lib/jekyll/assets/hooks/jekyll/setup.rb +13 -0
  17. data/lib/jekyll/assets/hooks/jekyll/{write_assets.rb → write.rb} +0 -0
  18. data/lib/jekyll/assets/hooks/sources.rb +2 -1
  19. data/lib/jekyll/assets/liquid.rb +3 -3
  20. data/lib/jekyll/assets/liquid/drop.rb +3 -3
  21. data/lib/jekyll/assets/liquid/filters.rb +5 -12
  22. data/lib/jekyll/assets/liquid/tag.rb +31 -37
  23. data/lib/jekyll/assets/liquid/tag/defaults.rb +2 -3
  24. data/lib/jekyll/assets/liquid/tag/defaults/image.rb +5 -5
  25. data/lib/jekyll/assets/liquid/tag/parser.rb +47 -55
  26. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +6 -10
  27. data/lib/jekyll/assets/liquid/tag/proxies.rb +19 -32
  28. data/lib/jekyll/assets/logger.rb +7 -6
  29. data/lib/jekyll/assets/patches.rb +4 -4
  30. data/lib/jekyll/assets/patches/kernel.rb +1 -1
  31. data/lib/jekyll/assets/version.rb +1 -1
  32. metadata +14 -14
  33. data/lib/jekyll/assets/hooks/jekyll/ignore.rb +0 -9
  34. data/lib/jekyll/assets/hooks/jekyll/initialize.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b81ac4f22eb832b198919b11d617d421819b1d31
4
- data.tar.gz: d1d771556d778ede73e0c9067c1dc578a63f0b7b
3
+ metadata.gz: 5ea6db7ce6d3db7e9638ea43bc6b16ef66bda4c4
4
+ data.tar.gz: 0b4949e68651598f61d1fbf8589999b95984b941
5
5
  SHA512:
6
- metadata.gz: 3e9718a9d8169ca570ed7f6ac60dda3c1b76c7491d88960eead9a0efe5167271aa3ca0bde980d7e2ad81cca2b25ff341077ebd321a8e37d687981d26c9532622
7
- data.tar.gz: 39f73f170484aab78684abf3bb4b408bb53c877ada4465db38684fae7e26f23d3418ce0348d2d2e482b46feff417cad0e05171a919a8faebacdb02cbb114034b
6
+ metadata.gz: b2bffef1cdd4b4f3c61979fa5cd097dcd89f13158cdb47d21c38d8e459338551e80a4809c6d2dcd43102a846d0310f4b9c8cb5d05087a2085433ace7b6b326f5
7
+ data.tar.gz: e85a0acdc8a0b8842045f6702a9a6f7cabac5e49144b0ea01738727488ef011f977a384e1452a18ad5372b0e56778dc0b44b22df95f906ca7639d4dabe62310b
data/Gemfile CHANGED
@@ -3,14 +3,18 @@ gemspec
3
3
 
4
4
  gem "rake"
5
5
  group :development do
6
- gem "therubyracer", :platforms => :mri
7
- gem "pry"
6
+ gem "therubyracer", :platforms => :mri, :require => false
7
+ gem "pry", :require => false
8
8
  end
9
9
 
10
- gem "uglifier"
11
- gem "sprockets-es6", "~> 0.6"
12
- gem "autoprefixer-rails", "~> 6.0"
13
- gem "font-awesome-sass", "~> 4.4.0"
14
- gem "bootstrap-sass", "~> 3.3"
15
- gem "mini_magick", "~> 4.2"
16
- gem "compass-core"
10
+ group :test do
11
+ gem "codeclimate-test-reporter", :require => false
12
+ end
13
+
14
+ gem "uglifier", :require => false
15
+ gem "sprockets-es6", "~> 0.6", :require => false
16
+ gem "autoprefixer-rails", "~> 6.0", :require => false
17
+ gem "font-awesome-sass", "~> 4.4.0", :require => false
18
+ gem "bootstrap-sass", "~> 3.3", :require => false
19
+ gem "mini_magick", "~> 4.2", :require => false
20
+ gem "compass-core", :require => false
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  [![](https://travis-ci.org/jekyll/jekyll-assets.png?branch=master)][travis]
2
- [![](https://coveralls.io/repos/jekyll/jekyll-assets/badge.png?branch=master)][coveralls]
2
+ [![](https://codeclimate.com/github/jekyll/jekyll-assets/badges/coverage.svg)][coverage]
3
3
  [![](https://codeclimate.com/github/jekyll/jekyll-assets/badges/gpa.svg)][code-climate] [![](https://gemnasium.com/jekyll/jekyll-assets.svg)][gemnasium]
4
4
 
5
5
  [gemnasium]: https://gemnasium.com/jekyll/jekyll-assets
6
6
  [code-climate]: https://codeclimate.com/github/jekyll/jekyll-assets
7
- [coveralls]: https://coveralls.io/r/jekyll/jekyll-assets
7
+ [coverage]: https://codeclimate.com/github/jekyll/jekyll-assets/coverage
8
8
  [travis]: https://travis-ci.org/jekyll/jekyll-assets
9
9
 
10
10
  # Jekyll 3 Assets
@@ -57,10 +57,16 @@ assets:
57
57
  - _assets/img
58
58
  - _assets/js
59
59
  features:
60
- automatic_image_size: true | false | default: true
61
- automatic_image_alt : true | false | default: true
60
+ automatic_img_size: true | false | default: true
61
+ automatic_img_alt : true | false | default: true
62
62
  ```
63
63
 
64
+ ### Cache Folder
65
+
66
+ If you plan to change the `cache` folder, please make sure to add that
67
+ folder to your `exclude` list in Jekyll or you will generate over and over
68
+ and over again, `.` folders are not ignored by default.
69
+
64
70
  ### Sources
65
71
 
66
72
  The listed resources in the example are all defaults. It should be noted
@@ -77,6 +83,8 @@ folder as the sole source (base folder.)***
77
83
  * Disable digesting by default in development.
78
84
  * Digest by default in production
79
85
 
86
+ ***You can force digesting with `digest: true` in your `_config.yml`***
87
+
80
88
  ### Compression
81
89
 
82
90
  * Requires sass and uglify.
@@ -84,7 +92,7 @@ folder as the sole source (base folder.)***
84
92
  * Enable by default in production.
85
93
 
86
94
 
87
- ### Bower (web components support.)
95
+ ### Bower Components
88
96
 
89
97
  Modify your `.bowerrc` file and add:
90
98
 
@@ -98,7 +106,9 @@ And then add `_assets/bower` to your sources list and Sprockets will do the
98
106
  the rest for you... you can even `//= require bower_asset.js`. We will even
99
107
  compress them for you per normal if Sprockets supports it and allows us to.
100
108
 
101
- ***You can force digesting with `digest: true` in your `_config.yml`***
109
+ ***You do not need to modify your `.bowerrc` file, you can optionally just
110
+ add it to your sources list and it will work that way too! As long as it's in
111
+ your Jekyll folder.***
102
112
 
103
113
  ## Tags
104
114
 
@@ -136,11 +146,14 @@ rules for our tags as a specification.
136
146
  * `sprockets:accept:<value>`
137
147
  * `sprockets:write_to:<value>`
138
148
 
139
- ## Liquid Variables in Arguments
149
+ ## Liquid Variables
150
+
151
+ We support liquid arguments for tag values (but not tag keys), and we also
152
+ support Liquid pre-processing (with your Jekyll context) sass/less/css files
153
+ you need do nothing special for the preprocessing an entire file, it's
154
+ always done.
140
155
 
141
- You can use Liquid variables inside of your arguments, but you must quote
142
- them to get them to work, this can be a partial argument quote a full argument
143
- quote or otherwise, it just must be quoted or escaped.
156
+ An example of using Liquid in your tags:
144
157
 
145
158
  ```liquid
146
159
  {% img '{{ image_path }}' %}
@@ -148,6 +161,19 @@ quote or otherwise, it just must be quoted or escaped.
148
161
  {% img {{\ image_path\ }} %}
149
162
  ```
150
163
 
164
+ An example of using Liquid in your SCSS:
165
+
166
+ ```scss
167
+ .bg {
168
+ background: url(asset_path("{{ site.background_image }}"));
169
+ }
170
+ ```
171
+
172
+ You have full access to your entire Jekyll context from any liquid
173
+ processing we do, so you can do whatever you like and be as dynamic as you
174
+ like, including full loops and conditional Liquid based CSS since we
175
+ pre-process your text files.
176
+
151
177
  ## Getting a list of your assets and basic info from Liquid
152
178
 
153
179
  We provide all *your* assets as a hash of Liquid Drops so you can get basic
data/Rakefile CHANGED
@@ -1,3 +1,43 @@
1
1
  require "rspec/core/rake_task"
2
2
  RSpec::Core::RakeTask.new(:spec)
3
3
  task :default => [:spec]
4
+
5
+ task :analysis do
6
+ require "open3"
7
+ begin require "jekyll/utils/ansi"
8
+ rescue LoadError
9
+ require_relative "spec/support/ansi"
10
+ end
11
+
12
+ cmd = [
13
+ "docker", "run", "--rm", "--env=CODE_PATH=#{Dir.pwd}", \
14
+ "--volume='#{Dir.pwd}:/code'", "--volume=/var/run/docker.sock:/var/run/docker.sock", \
15
+ "--volume=/tmp/cc:/tmp/cc", "-i", "codeclimate/codeclimate", "analyze"
16
+ ]
17
+
18
+ ansi = Jekyll::Utils::Ansi
19
+ file = File.open(".analysis", "w+")
20
+ Open3.popen3(cmd.shelljoin) do |_, out, err, _|
21
+ while data = out.gets
22
+ file.write data
23
+ if data =~ /\A==/
24
+ $stdout.print ansi.yellow(data)
25
+
26
+ elsif data !~ %r!\A[0-9\-]+!
27
+ $stdout.puts data
28
+
29
+ else
30
+ h, d = data.split(":", 2)
31
+ $stdout.print ansi.cyan(h)
32
+ $stdout.print ":", d
33
+ end
34
+ end
35
+
36
+ while data = err.gets
37
+ file.write data
38
+ $stderr.print ansi.red(data)
39
+ end
40
+ end
41
+
42
+ file.close
43
+ end
@@ -2,20 +2,23 @@
2
2
  # Copyright: 2012-2015 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
+ autoload :Tilt, "tilt"
5
6
  require "sprockets"
6
7
  require "jekyll"
7
8
 
9
+ require "jekyll/assets/patches"
10
+ require "jekyll/assets/version"
11
+
8
12
  module Jekyll
9
13
  module Assets
10
- require_relative "assets/version"
11
- require_relative "assets/patches"
12
- require_relative "assets/cached"
13
- require_relative "assets/config"
14
- require_relative "assets/env"
15
- require_relative "assets/hook"
16
- require_relative "assets/logger"
17
- require_relative "assets/hooks"
18
- require_relative "assets/liquid"
19
- require_relative "assets/addons"
14
+ autoload :Hook, "jekyll/assets/hook"
15
+ autoload :Cached, "jekyll/assets/cached"
16
+ autoload :Config, "jekyll/assets/config"
17
+ autoload :Logger, "jekyll/assets/logger"
18
+ autoload :Liquid, "jekyll/assets/liquid"
19
+ autoload :Env, "jekyll/assets/env"
20
+
21
+ require "jekyll/assets/hooks"
22
+ require "jekyll/assets/addons"
20
23
  end
21
24
  end
@@ -2,9 +2,10 @@
2
2
  # Copyright: 2012-2015 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
- require_relative "addons/compass"
6
- require_relative "addons/bootstrap"
7
- require_relative "addons/autoprefixer"
8
- require_relative "addons/proxies/magick"
9
- require_relative "addons/font_awesome"
10
- require_relative "addons/js_es6"
5
+ require "jekyll/assets/addons/compass"
6
+ require "jekyll/assets/addons/bootstrap"
7
+ require "jekyll/assets/addons/autoprefixer"
8
+ require "jekyll/assets/addons/processors/liquid"
9
+ require "jekyll/assets/addons/proxies/magick"
10
+ require "jekyll/assets/addons/font_awesome"
11
+ require "jekyll/assets/addons/js_es6"
@@ -0,0 +1,31 @@
1
+ module Jekyll
2
+ module Assets
3
+ module Addons
4
+ module Processors
5
+ class Liquid < Tilt::Template
6
+ PROCESSING_FOR = %W(text/css text/sass text/less application/javascript
7
+ text/scss text/coffeescript text/javascript).freeze
8
+ def prepare
9
+ #
10
+ end
11
+
12
+ # Render the file with the sites current context, anything you
13
+ # can do in a normal liquid file with Jekyll, you can do here inc,
14
+ # accessing the entirety of your posts and pages, though I don't
15
+ # know why you would want to, and I ain't judging you.
16
+
17
+ def evaluate(scope, _, jekyll = scope.environment.jekyll, &_block)
18
+ jekyll.liquid_renderer.file(@file).parse(data).render!(jekyll.site_payload, :registers => {
19
+ :site => jekyll
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ # There might be a few missing, if there is please do let me know.
29
+ Jekyll::Assets::Addons::Processors::Liquid::PROCESSING_FOR.each do |val|
30
+ Sprockets.register_preprocessor val, Jekyll::Assets::Addons::Processors::Liquid
31
+ end
@@ -9,7 +9,9 @@ try_require "mini_magick" do
9
9
  @two-fourths @three-fourths)
10
10
 
11
11
  Jekyll::Assets::Env.liquid_proxies.add :magick, :img, *(args + presets) do
12
- Presets, Args = presets, args
12
+ PRESETS = presets
13
+ ARGS = args
14
+
13
15
  class DoubleResizeError < RuntimeError
14
16
  def initialize
15
17
  "Both resize and @*x provided, this is not supported."
@@ -54,14 +56,14 @@ try_require "mini_magick" do
54
56
 
55
57
  private
56
58
  def preset?
57
- (@opts.keys - Args.map(&:to_sym)).any?
59
+ (@opts.keys - ARGS.map(&:to_sym)).any?
58
60
  end
59
61
 
60
62
  #
61
63
 
62
64
  private
63
65
  def magick_quality(img)
64
- if @opts.has_key?(:quality)
66
+ if @opts.key?(:quality)
65
67
  then img.quality @opts[:quality]
66
68
  end
67
69
  end
@@ -70,8 +72,8 @@ try_require "mini_magick" do
70
72
 
71
73
  private
72
74
  def magick_resize(img)
73
- raise DoubleResizeError if @opts.has_key?(:resize) && preset?
74
- if @opts.has_key?(:resize)
75
+ raise DoubleResizeError if @opts.key?(:resize) && preset?
76
+ if @opts.key?(:resize)
75
77
  then img.resize @opts[:resize]
76
78
  end
77
79
  end
@@ -80,7 +82,7 @@ try_require "mini_magick" do
80
82
 
81
83
  private
82
84
  def magick_rotate(img)
83
- if @opts.has_key?(:rotate)
85
+ if @opts.key?(:rotate)
84
86
  then img.rotate @opts[:rotate]
85
87
  end
86
88
  end
@@ -89,7 +91,7 @@ try_require "mini_magick" do
89
91
 
90
92
  private
91
93
  def magick_flip(img)
92
- if @opts.has_key?(:flip)
94
+ if @opts.key?(:flip)
93
95
  then img.flip @opts[:flip]
94
96
  end
95
97
  end
@@ -98,7 +100,7 @@ try_require "mini_magick" do
98
100
 
99
101
  private
100
102
  def magick_crop(img)
101
- if @opts.has_key?(:crop)
103
+ if @opts.key?(:crop)
102
104
  then img.crop @opts[:crop]
103
105
  end
104
106
  end
@@ -9,7 +9,7 @@ module Jekyll
9
9
  _assets/css _assets/stylesheets
10
10
  _assets/images _assets/img _assets/fonts
11
11
  _assets/javascripts _assets/js
12
- )
12
+ ).freeze
13
13
 
14
14
  Development = {
15
15
  "skip_baseurl_with_cdn" => false,
@@ -27,7 +27,7 @@ module Jekyll
27
27
  "automatic_img_alt" => true,
28
28
  "automatic_img_size" => true
29
29
  }
30
- }
30
+ }.freeze
31
31
 
32
32
  #
33
33
 
@@ -36,16 +36,19 @@ module Jekyll
36
36
  "compress" => {
37
37
  "css" => true,
38
38
  "js" => true
39
- },
40
- })
39
+ }
40
+ }).freeze
41
41
 
42
42
  #
43
43
 
44
44
  def self.merge_sources(jekyll, config)
45
- return if config["sources"] && config["sources"].grep(/\A\s*_assets\/?\s*\Z/).size > 0
46
- config["sources"] = (DefaultSources + (config["sources"] ||= [])).map do |val|
45
+ config["sources"] ||= []
46
+ return if config["sources"].grep(/\A\s*_assets\/?\s*\Z/).size > 0
47
+ sources = DefaultSources + config["sources"].to_a
48
+
49
+ config["sources"] = Set.new(sources.map do |val|
47
50
  jekyll.in_source_dir(val)
48
- end
51
+ end)
49
52
  end
50
53
 
51
54
  #
@@ -57,7 +60,7 @@ module Jekyll
57
60
  #
58
61
 
59
62
  def self.merge(new_hash, old_hash = defaults)
60
- old_hash.merge(new_hash) do |key, old_val, new_val|
63
+ old_hash.merge(new_hash) do |_, old_val, new_val|
61
64
  old_val.is_a?(Hash) && new_val.is_a?(Hash) ? merge(new_val, old_val) : new_val
62
65
  end
63
66
  end
@@ -10,12 +10,21 @@ module Jekyll
10
10
  class << self
11
11
  attr_accessor :past
12
12
  def liquid_proxies
13
- return Liquid::Tag::Proxies
13
+ Liquid::Tag::Proxies
14
14
  end
15
15
  end
16
16
 
17
17
  #
18
18
 
19
+ def excludes
20
+ excludes = Set.new
21
+ excludes << strip_path(in_cache_dir)
22
+ jekyll.sprockets.asset_config["sources"].each { |path| excludes << strip_path(path) }
23
+ excludes
24
+ end
25
+
26
+ #
27
+
19
28
  def all_unparsed_assets
20
29
  @unparsed_assets ||= logical_paths.select do |(_, val)|
21
30
  val.start_with?(jekyll.in_source_dir)
@@ -25,9 +34,8 @@ module Jekyll
25
34
  #
26
35
 
27
36
  def to_liquid_payload
28
- jekyll.sprockets.all_unparsed_assets.inject({}) do |hsh, (key, val)|
29
- hsh[key] = Jekyll::Assets::Liquid::Drop.new(val, jekyll)
30
- hsh
37
+ jekyll.sprockets.all_unparsed_assets.each_with_object({}) do |(key, val), hash|
38
+ hash[key] = Jekyll::Assets::Liquid::Drop.new(val, jekyll)
31
39
  end
32
40
  end
33
41
 
@@ -35,19 +43,19 @@ module Jekyll
35
43
 
36
44
  def initialize(path, jekyll = nil)
37
45
  jekyll, path = path, nil if path.is_a?(Jekyll::Site)
38
- @used, @jekyll = Set.new, jekyll
46
+ @jekyll = jekyll
47
+ @used = Set.new
39
48
 
40
49
  path ? super(path) : super()
41
50
  Hook.trigger :env, :init do |hook|
42
- hook.arity > 0 || 0 > hook.arity ? hook.call(self) : \
43
- instance_eval(&hook)
51
+ hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(&hook)
44
52
  end
45
53
  end
46
54
 
47
55
  #
48
56
 
49
57
  def liquid_proxies
50
- return self.class.liquid_proxies
58
+ self.class.liquid_proxies
51
59
  end
52
60
 
53
61
  # Make sure a path falls withint our cache dir.
@@ -76,7 +84,7 @@ module Jekyll
76
84
  #
77
85
 
78
86
  def cdn?
79
- !dev? && asset_config.has_key?("cdn") && \
87
+ !dev? && asset_config.key?("cdn") && \
80
88
  asset_config["cdn"]
81
89
  end
82
90
 
@@ -101,8 +109,8 @@ module Jekyll
101
109
  #
102
110
 
103
111
  def compress?(what)
104
- !!asset_config["compress"]. \
105
- fetch(what, false)
112
+ !!asset_config["compress"] \
113
+ .fetch(what, false)
106
114
  end
107
115
 
108
116
  #
@@ -122,14 +130,15 @@ module Jekyll
122
130
  # the baseurl and asset prefix. All of these can be adjusted.
123
131
 
124
132
  def prefix_path(path = nil)
125
- _baseurl = baseurl
126
133
  cdn = asset_config["cdn"]
127
- _path = []
134
+ base_url = baseurl
135
+
136
+ path_ = []
137
+ path_ << base_url unless base_url.empty?
138
+ path_ << path unless path.nil?
128
139
 
129
- _path << _baseurl unless _baseurl.empty?
130
- _path << path unless path.nil?
131
- cdn? && cdn ? File.join(cdn, *_path).chomp("/") : \
132
- File.join(*_path).chomp("/")
140
+ url = cdn && cdn?? File.join(cdn, *path_) : File.join(*path_)
141
+ url.chomp("/")
133
142
  end
134
143
 
135
144
  #
@@ -151,6 +160,13 @@ module Jekyll
151
160
 
152
161
  #
153
162
 
163
+ private
164
+ def strip_path(path)
165
+ path.sub(jekyll.in_source_dir("/"), "")
166
+ end
167
+
168
+ #
169
+
154
170
  private
155
171
  def as_path(v)
156
172
  path = digest?? v.digest_path : v.logical_path