middleman-img_loading_attribute 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 69dda6ebf2d580dd1f1566cdaff55e758d3665c62d1a8463cb2994905f7f0ef4
4
- data.tar.gz: 206f2cc38298f32ef684806178e3ae7146557f07818600bf32808fcbb8b34437
3
+ metadata.gz: b46196a12d807e6c73c452f1dbf7d30908812da618887a8f91850aa8b10acfe1
4
+ data.tar.gz: a7a1b6b95869837b24be3707f930f3473c37cb1f7e482d7a8a0f63f00d586862
5
5
  SHA512:
6
- metadata.gz: 63153f125e1ddf6509fedf197cfae09ab033dee1ff6677986d4a7fb03099c91a8a69816ae9a478677eebd0dd493d324142bd455073de74d2cfe1d241c9930ea4
7
- data.tar.gz: f327ba939d0a3bb840f912dbdd32d80068674e8bae272784a8f65ce2f4742118d3196040dd0e5715f39c6c0460a6f0ad80af14122e019b3fc2c9a09ee200063f
6
+ metadata.gz: '0737929e356fb843a5925701cd1794f8de59638e9ad8ec36198cfb74659b81c83c7b3ab7f3c421301750373e08441e3a5d166dd93606a6079196387d62bd7df0'
7
+ data.tar.gz: c9789e0e0f46fbe4a355efb663c84619f0f6fc1ace1e5c13111814cdc7af81a7bb62aa6543e2ef35c84cfeda292eb0dcedce3354298c7ae2594bf8a485a9d627
@@ -1,3 +1,8 @@
1
+ # v0.3.0 (2019-11-29)
2
+ Stop to edit attribute of the `<img>` on inner of `<pre>` or `<code>` or `<blockquote>`
3
+
4
+ https://github.com/unasuke/middleman-img_loading_attribute/pull/1
5
+
1
6
  # v0.2.0 (2019-11-09)
2
7
  Cosmetic changes only.
3
8
  Has no breaking changes.
@@ -4,5 +4,5 @@ Feature: Set loading="auto"
4
4
  When I cd to "build"
5
5
  Then the file "index.html" should contain:
6
6
  """
7
- <img loading="auto"
7
+ loading="auto"
8
8
  """
@@ -4,5 +4,5 @@ Feature: Set loading="eager"
4
4
  When I cd to "build"
5
5
  Then the file "index.html" should contain:
6
6
  """
7
- <img loading="eager" src="/images/1x1.png"
7
+ loading="eager"
8
8
  """
@@ -4,5 +4,5 @@ Feature: Set loading="lazy" with asset_hash
4
4
  When I cd to "build"
5
5
  Then the file "index.html" should contain:
6
6
  """
7
- <img loading="lazy" src="/images/1x1-0ec63b14.png"
7
+ loading="lazy"
8
8
  """
@@ -0,0 +1,8 @@
1
+ Feature: Didn't Set loading="lazy"
2
+ Scenario: Should add 'pre'
3
+ Given a successfully built app at "pre-app"
4
+ When I cd to "build"
5
+ Then the file "index.html" should not contain:
6
+ """
7
+ loading="lazy"
8
+ """
@@ -0,0 +1,4 @@
1
+ activate :asset_hash
2
+ activate :img_loading_attribute do |c|
3
+ c.loading = 'lazy'
4
+ end
@@ -0,0 +1,3 @@
1
+ <pre>
2
+ <%= image_tag '1x1.png' %>
3
+ </pre>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test App</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -1,5 +1,6 @@
1
1
  # Require core library
2
2
  require 'middleman-core'
3
+ require 'nokogiri'
3
4
 
4
5
  class Middleman::ImgLoadingAttribute < ::Middleman::Extension
5
6
  option :loading, 'auto', 'A value of "loading" attribute in <img> tag'
@@ -22,10 +23,14 @@ class Middleman::ImgLoadingAttribute < ::Middleman::Extension
22
23
  def after_build(builder)
23
24
  files = Dir.glob(File.join(app.config[:build_dir], "**", "*.html"))
24
25
  files.each do |file|
25
- contents = File.read(file)
26
- replaced = contents.gsub(%r[<img], "<img loading=\"#{options[:loading]}\"")
26
+ doc = Nokogiri::HTML(File.read(file))
27
+ doc.css('img').each do |elem|
28
+ next if elem.path.include?('pre') || elem.path.include?('code') || elem.path.include?('blockquote')
29
+
30
+ elem['loading'] = options[:loading]
31
+ end
27
32
  File.open(file, 'w') do |f|
28
- f.write replaced
33
+ f.write doc.to_html
29
34
  end
30
35
  end
31
36
  end
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "middleman-img_loading_attribute"
5
- s.version = "0.2.0"
5
+ s.version = "0.3.0"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Yusuke Nakamura"]
8
8
  s.email = ['yusuke1994525@gmail.com']
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  # The version of middleman-core your extension depends on
20
20
  s.add_runtime_dependency("middleman-core")
21
21
  s.add_runtime_dependency("middleman-cli")
22
+ s.add_runtime_dependency("nokogiri")
22
23
 
23
24
  # Additional dependencies
24
25
  # s.add_runtime_dependency("gem-name", "gem-version")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-img_loading_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Specify "loading" attribute value to generated HTML from middleman
42
56
  email:
43
57
  - yusuke1994525@gmail.com
@@ -59,6 +73,7 @@ files:
59
73
  - features/auto.feature
60
74
  - features/eager.feature
61
75
  - features/lazy.feature
76
+ - features/pre.feature
62
77
  - features/step_definitions/builder_steps.rb
63
78
  - features/support/env.rb
64
79
  - fixtures/auto-app/config.rb
@@ -72,6 +87,10 @@ files:
72
87
  - fixtures/lazy-app/source/images/1x1.png
73
88
  - fixtures/lazy-app/source/index.html.erb
74
89
  - fixtures/lazy-app/source/layout.erb
90
+ - fixtures/pre-app/config.rb
91
+ - fixtures/pre-app/source/images/1x1.png
92
+ - fixtures/pre-app/source/index.html.erb
93
+ - fixtures/pre-app/source/layout.erb
75
94
  - lib/middleman-img_loading_attribute.rb
76
95
  - lib/middleman-img_loading_attribute/extension.rb
77
96
  - middleman-img_loading_attribute.gemspec
@@ -102,5 +121,6 @@ test_files:
102
121
  - features/auto.feature
103
122
  - features/eager.feature
104
123
  - features/lazy.feature
124
+ - features/pre.feature
105
125
  - features/step_definitions/builder_steps.rb
106
126
  - features/support/env.rb