jekyll-replace-img 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a2ee9afa5446ed3f449b43d43c4b10e06613e43
4
- data.tar.gz: 5f3a21c12e0cd755a7bc408b9d6b9104da53531c
3
+ metadata.gz: c439e00bf90addb4b297cde1f71cfaf805369f5b
4
+ data.tar.gz: 0b07dd5a836b0c2a7fab3012bc0a181d2a887875
5
5
  SHA512:
6
- metadata.gz: dbeada102131047cb22f858e294a31327cb6d9c70c5e3849ca28140d063658d20a53bc4e5feac368fbc0c5b50407213a5d1421b97bb70ef982e7085fef6cba24
7
- data.tar.gz: c824ad03fc2b343f7f80cd8d2c8034cfe8b7e0b465260cab3b929902989b4ba6ddb5c46b92adc181b3e2f3545bcb74aeae087070a1ae0447c8bb4561c17a3481
6
+ metadata.gz: 686e3cd36689285c0564a28d8ae860eb0ee9da8fce61387bbb025da21574c411fc45f4327abb764e59f4c0309d6c8db5edf400d696e574039a4af52d6ee3963b
7
+ data.tar.gz: ce695bc93ce79d35b015af3247b6f0806d3ad1bdd99beeb2b4ebae4cf50b4bcf9fce18077b63c142c89ea82d45a20ec0c56648955292d7a6dca54cc04b9a7321
@@ -1,56 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- KEY_CONFIG = "replace_img"
3
+ module JekyllReplaceImg
4
+ KEY_CONFIG = "replace_img"
4
5
 
5
- KEY_RE_IMG = "re_img"
6
- KEY_RE_IGNORE = "re_ignore"
7
- KEY_REPLACEMENT = "replacement"
6
+ KEY_RE_IMG = "re_img"
7
+ KEY_RE_IGNORE = "re_ignore"
8
+ KEY_REPLACEMENT = "replacement"
8
9
 
9
- RE_IMG = "<img\\s*(?<attributes>.*?)\\s*/>"
10
- RE_IGNORE = "data-ignore"
11
- REPLACEMENT = "
12
- <hy-img %<attributes>s>
13
- <noscript><img data-ignore %<attributes>s/></noscript>
14
- </hy-img>"
10
+ RE_IMG = "<img\\s*(?<attributes>.*?)\\s*/>"
11
+ RE_IGNORE = "data-ignore"
12
+ REPLACEMENT = "
13
+ <hy-img %<attributes>s>
14
+ <noscript><img data-ignore %<attributes>s/></noscript>
15
+ </hy-img>"
15
16
 
16
- RE_DATAURL = %r!src\s*=\s*[""]\s*data:!ix.freeze
17
+ RE_DATAURL = %r!src\s*=\s*[""]\s*data:!ix.freeze
17
18
 
18
- re_img, re_ignore, replacement = nil
19
+ re_img, re_ignore, replacement = nil
19
20
 
20
- def get_config(config, key)
21
- config[KEY_CONFIG] && config[KEY_CONFIG][key]
22
- end
23
-
24
- Jekyll::Hooks.register(:site, :after_init) do |site|
25
- re_img = Regexp.new(
26
- get_config(site.config, KEY_RE_IMG) || RE_IMG,
27
- Regexp::EXTENDED | Regexp::IGNORECASE | Regexp::MULTILINE
28
- )
21
+ def self.get_config(config, key)
22
+ config[KEY_CONFIG] && config[KEY_CONFIG][key]
23
+ end
29
24
 
30
- re_ignore = Regexp.new(
31
- get_config(site.config, KEY_RE_IGNORE) || RE_IGNORE,
32
- Regexp::EXTENDED | Regexp::IGNORECASE
33
- )
25
+ Jekyll::Hooks.register(:site, :after_init) do |site|
26
+ re_img = Regexp.new(
27
+ JekyllReplaceImg.get_config(site.config, KEY_RE_IMG) || RE_IMG,
28
+ Regexp::EXTENDED | Regexp::IGNORECASE | Regexp::MULTILINE
29
+ )
34
30
 
35
- replacement = get_config(site.config, KEY_REPLACEMENT) || REPLACEMENT
36
- ENV["JEKYLL_ENV"] == "production" && replacement.gsub!(%r!\n+!, "")
37
- end
31
+ re_ignore = Regexp.new(
32
+ JekyllReplaceImg.get_config(site.config, KEY_RE_IGNORE) || RE_IGNORE,
33
+ Regexp::EXTENDED | Regexp::IGNORECASE
34
+ )
38
35
 
39
- Jekyll::Hooks.register([:pages, :documents], :post_render) do |page|
40
- i = 0
41
- page.output = page.output.gsub(re_img) do |match|
42
- last_match = Regexp.last_match
43
-
44
- subs = { :i => i }
45
- last_match.names.each do |name|
46
- subs[name.intern] = last_match[name]
47
- end
36
+ replacement = JekyllReplaceImg.get_config(site.config, KEY_REPLACEMENT) || REPLACEMENT
37
+ ENV["JEKYLL_ENV"] == "production" && replacement.gsub!(%r!\n+!, "")
38
+ end
48
39
 
49
- if match.index(re_ignore).nil? && match.index(RE_DATAURL).nil?
50
- i += 1
51
- replacement % subs
52
- else
53
- match
40
+ Jekyll::Hooks.register([:pages, :documents], :post_render) do |page|
41
+ i = 0
42
+ page.output = page.output.gsub(re_img) do |match|
43
+ last_match = Regexp.last_match
44
+
45
+ subs = { :i => i }
46
+ last_match.names.each do |name|
47
+ subs[name.intern] = last_match[name]
48
+ end
49
+
50
+ if match.index(re_ignore).nil? && match.index(RE_DATAURL).nil?
51
+ i += 1
52
+ replacement % subs
53
+ else
54
+ match
55
+ end
54
56
  end
55
57
  end
56
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllReplaceImg
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-replace-img
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Klampfer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-04 00:00:00.000000000 Z
11
+ date: 2019-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll