jekyll-assets 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 125f0a58023e5e41de8eb1fbfb21d52d81cc43ec
4
- data.tar.gz: 9214d2bf1839b62ea94ec23c3803ab768b019304
3
+ metadata.gz: cd81b41822b8b54ab4cc4d1a78ae99bff7a322b3
4
+ data.tar.gz: edeadf3fc3490d45c86f8d1147cc632ad5f40367
5
5
  SHA512:
6
- metadata.gz: 6d5c1ab77cc292c5630a0cc3e0d518451c5da307ea4ddb83905bdae472d43585caaf3b5f01d6c5f60e363d585490e2ff2b676122b47ce750eb04979cbae1d833
7
- data.tar.gz: a6648f8282532c1ab4b64ef7be5809ac89dad5558cb1826ba8260011b14232c28b97a73bda4d052204f6d831c267351183d6dd91da1da22425b5819a2f838504
6
+ metadata.gz: 9a1f4e0ad128cffc1733260886fbe06439b65e38eda2ef66fef350f25262387c39d546b5de4b8a15e6ea0a812050e82ec2bc1814fd0fb6b1be031440aee1332c
7
+ data.tar.gz: 02ee95d9b922f750887a49095e6e56ea1c129f9dc29bc7493ca659a5dd95b33089ec3a0f84e1b8e1dae6ab7e44a6a4e26be5a5e3ad1aa5e9868bfebe309d048d
data/README.md CHANGED
@@ -237,6 +237,37 @@ assets:
237
237
  [amazon-s3]: http://aws.amazon.com/s3
238
238
 
239
239
 
240
+ ### Images size (dimension) auto-guessing
241
+
242
+ The image helper accepts options param (in square brackets) with `autosize`
243
+ switch. If given, then image dimension will be calculated and
244
+ apropriate attributes set:
245
+
246
+ ``` html
247
+ {% image logo.png alt="Logo" [autosize] %}
248
+
249
+ <!-- assuming logo.png is 50x50, the above will render -->
250
+
251
+ <img src="/assets/logo-68b329da9893e34099c7d8ad5cb9c940.png" alt="Logo"
252
+ width="50" height="50">
253
+ ```
254
+
255
+ You can also globally enable `autosize` in config (see `autosize` config option
256
+ below). In this case, `image` tag will alway render dimension attributes unless
257
+ you specify `no-autosize` switch. Assume you have `autosize` option enabled in
258
+ config, then:
259
+
260
+ ``` html
261
+ {% image logo.png [no-autosize] %}
262
+ {% image logo.png %}
263
+
264
+ <!-- assuming logo.png is 50x50, the above will render -->
265
+
266
+ <img src="/assets/logo-68b329da9893e34099c7d8ad5cb9c940.png">
267
+ <img src="/assets/logo-68b329da9893e34099c7d8ad5cb9c940.png"
268
+ width="50" height="50">
269
+ ```
270
+
240
271
  ### Custom Compressors
241
272
 
242
273
  Sprockets comes with good set of preconfigured compressors, but imagine you are
@@ -550,6 +581,12 @@ assets:
550
581
  #
551
582
  css_compressor: ~
552
583
  #
584
+ # Globally enables adding image width and height attributes to image tags.
585
+ # Does nothing if either width or height attribute already set.
586
+ # Disabled by default.
587
+ #
588
+ autosize: false
589
+ #
553
590
  # Sets cachebusting policy for generated assets.
554
591
  #
555
592
  # Possible variants:
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "jekyll", "~> 2.0"
26
- spec.add_dependency "sprockets", "~> 2.10"
25
+ spec.add_dependency "jekyll", "~> 2.0"
26
+ spec.add_dependency "sass", "~> 3.2"
27
+ spec.add_dependency "fastimage", "~> 1.6"
28
+ spec.add_dependency "sprockets", "~> 2.10"
27
29
  spec.add_dependency "sprockets-sass"
28
30
  spec.add_dependency "sprockets-helpers"
29
- spec.add_dependency "sass", "~> 3.2"
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 1.6"
32
33
  end
@@ -5,17 +5,18 @@ module Jekyll
5
5
  module AssetsPlugin
6
6
  class Configuration
7
7
  DEFAULTS = {
8
- :dirname => "assets",
9
- :sources => %w(_assets/javascripts
10
- _assets/stylesheets
11
- _assets/images),
12
- :js_compressor => nil,
13
- :css_compressor => nil,
14
- :cachebust => :hard,
15
- :cache => false,
16
- :gzip => %w(text/css application/javascript),
17
- :debug => false,
18
- :version => 1
8
+ :dirname => "assets",
9
+ :sources => %w(_assets/javascripts
10
+ _assets/stylesheets
11
+ _assets/images),
12
+ :js_compressor => nil,
13
+ :css_compressor => nil,
14
+ :autosize => false,
15
+ :cachebust => :hard,
16
+ :cache => false,
17
+ :gzip => %w(text/css application/javascript),
18
+ :debug => false,
19
+ :version => 1
19
20
  }.freeze
20
21
 
21
22
  def initialize(config = {})
@@ -1,24 +1,34 @@
1
+ # 3rd-party
2
+ require "fastimage"
3
+
1
4
  module Jekyll
2
5
  module AssetsPlugin
3
6
  class Renderer
4
7
  STYLESHEET = '<link rel="stylesheet" href="%{path}"%{attrs}>'
5
8
  JAVASCRIPT = '<script src="%{path}"%{attrs}></script>'
6
9
  IMAGE = '<img src="%{path}"%{attrs}>'
10
+ IMAGESIZE = 'width="%d" height="%d"'
7
11
 
8
12
  URI_RE = %r{^(?:[^:]+:)?//(?:[^./]+\.)+[^./]+/}
9
- PARAMS_RE = / (?: "(?<path>[^"]+)" | '(?<path>[^']+)' | (?<path>[^ ]+) )
10
- (?<attrs>.*)
13
+ PARAMS_RE = / ^
14
+ \s*
15
+ (?: "(?<path>[^"]+)" | '(?<path>[^']+)' | (?<path>[^ ]+) )
16
+ (?<attrs>.*?)
17
+ (?: \[(?<options>.*)\] )?
18
+ \s*
19
+ $
11
20
  /x
12
21
 
13
- attr_reader :site, :path, :attrs
22
+ attr_reader :site, :path, :attrs, :options
14
23
 
15
24
  def initialize(context, params)
16
25
  @site = context.registers[:site]
17
26
 
18
27
  match = params.strip.match PARAMS_RE
19
28
 
20
- @path = match["path"]
21
- @attrs = match["attrs"]
29
+ @path = match["path"]
30
+ @attrs = match["attrs"]
31
+ @options = match["options"].to_s.split(",")
22
32
  end
23
33
 
24
34
  def render_asset
@@ -40,6 +50,7 @@ module Jekyll
40
50
  end
41
51
 
42
52
  def render_image
53
+ autosize!
43
54
  render_tag IMAGE
44
55
  end
45
56
 
@@ -58,6 +69,26 @@ module Jekyll
58
69
  tags.join "\n"
59
70
  end
60
71
 
72
+ def autosize!
73
+ return unless autosize?
74
+
75
+ if remote?
76
+ width, height = FastImage.size(path)
77
+ else
78
+ width, height = FastImage.size(site.assets[path].pathname)
79
+ end
80
+
81
+ @attrs = %(#{@attrs} width="#{width}" height="#{height}").strip
82
+ end
83
+
84
+ def autosize?
85
+ if site.assets_config.autosize
86
+ !options.include? "no-autosize"
87
+ else
88
+ options.include? "autosize"
89
+ end
90
+ end
91
+
61
92
  def remote?
62
93
  path =~ URI_RE
63
94
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.11.0"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
@@ -34,6 +34,11 @@ RSpec.describe Jekyll::AssetsPlugin::Configuration do
34
34
  it { is_expected.to be_nil }
35
35
  end
36
36
 
37
+ context "autosize" do
38
+ subject { config.autosize }
39
+ it { is_expected.to be false }
40
+ end
41
+
37
42
  context "gzip" do
38
43
  subject { config.gzip }
39
44
  it { is_expected.to match_array %w(text/css application/javascript) }
@@ -41,7 +46,7 @@ RSpec.describe Jekyll::AssetsPlugin::Configuration do
41
46
 
42
47
  context "cache_assets?" do
43
48
  subject { config.cache_assets? }
44
- it { is_expected.to eq false }
49
+ it { is_expected.to be false }
45
50
  end
46
51
 
47
52
  context "cache_path" do
@@ -51,7 +56,7 @@ RSpec.describe Jekyll::AssetsPlugin::Configuration do
51
56
 
52
57
  context "debug" do
53
58
  subject { config.debug }
54
- it { is_expected.to eq false }
59
+ it { is_expected.to be false }
55
60
  end
56
61
 
57
62
  end
@@ -94,6 +94,20 @@ RSpec.describe Jekyll::AssetsPlugin::Renderer do
94
94
  end
95
95
  end
96
96
 
97
+ describe "#options" do
98
+ subject { renderer.options }
99
+
100
+ context "with no options given" do
101
+ it { is_expected.to be_an Array }
102
+ it { is_expected.to be_empty }
103
+ end
104
+
105
+ context "with options given" do
106
+ let(:params) { "app [foo,bar]" }
107
+ it { is_expected.to eq %w(foo bar) }
108
+ end
109
+ end
110
+
97
111
  describe "#render_javascript" do
98
112
  subject { renderer.render_javascript }
99
113
 
@@ -197,6 +211,31 @@ RSpec.describe Jekyll::AssetsPlugin::Renderer do
197
211
  it { is_expected.to include "data-test=true" }
198
212
  end
199
213
  end
214
+
215
+ context "with [autosize] helper option" do
216
+ let(:params) { "noise.png [autosize]" }
217
+ it { is_expected.to include 'width="100" height="100"' }
218
+ end
219
+
220
+ context "with [no-autosize] helper option" do
221
+ let(:params) { "noise.png [no-autosize]" }
222
+ it { is_expected.to_not include 'width="100" height="100"' }
223
+ end
224
+
225
+ context "with autosize enabled in config" do
226
+ let(:assets_config) { Hash[:autosize, true] }
227
+ it { is_expected.to include 'width="100" height="100"' }
228
+
229
+ context "and [autosize] helper option given" do
230
+ let(:params) { "noise.png [autosize]" }
231
+ it { is_expected.to include 'width="100" height="100"' }
232
+ end
233
+
234
+ context "and [no-autosize] helper option given" do
235
+ let(:params) { "noise.png [no-autosize]" }
236
+ it { is_expected.to_not include 'width="100" height="100"' }
237
+ end
238
+ end
200
239
  end
201
240
 
202
241
  describe "#render_asset" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksey V Zapparov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-09 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -25,35 +25,49 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sprockets
28
+ name: sass
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.10'
33
+ version: '3.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.10'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sprockets-sass
42
+ name: fastimage
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
- name: sprockets-helpers
56
+ name: sprockets
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets-sass
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: sass
84
+ name: sprockets-helpers
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '3.2'
89
+ version: '0'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '3.2'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +215,7 @@ rubyforge_project:
201
215
  rubygems_version: 2.4.1
202
216
  signing_key:
203
217
  specification_version: 4
204
- summary: jekyll-assets-0.11.0
218
+ summary: jekyll-assets-0.12.0
205
219
  test_files:
206
220
  - spec/fixtures/.gitignore
207
221
  - spec/fixtures/_assets/alert.js
@@ -242,4 +256,3 @@ test_files:
242
256
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
243
257
  - spec/spec_helper.rb
244
258
  - spec/support/fixtures_helpers.rb
245
- has_rdoc: