jekyll-imgwh 1.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 +7 -0
- data/lib/jekyll-imgwh/version.rb +8 -0
- data/lib/jekyll-imgwh.rb +89 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a4ffd44d7ca00b66da675ce9f136af19dabf345fd9c6f0b5504a7d228ca38ee1
|
4
|
+
data.tar.gz: d1e4fb2243f60657f07e70dcbe92ecf930be8f15011996eabd46a2fa42c56bf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf960c6b1726bf31cf2eb79278f78485901aa3de3732faf8ec11c6bc832162c751730dba8e256150c41a7022406c29bff6d820a350deac560dac410b07bea1c1
|
7
|
+
data.tar.gz: a34dc356c0051b9760fad109095e61b63064a39f4f135a39ec772c8dca26cf177f1572bda52412795fc4d7f4621321acc9596bf5960ea5d8a3cf2d78f451fe42
|
data/lib/jekyll-imgwh.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "fastimage"
|
5
|
+
require "jekyll"
|
6
|
+
require "jekyll-imgwh/version"
|
7
|
+
|
8
|
+
module Jekyll
|
9
|
+
module Imgwh
|
10
|
+
class Tag < Liquid::Tag
|
11
|
+
def initialize(tag_name, content, tokens)
|
12
|
+
super
|
13
|
+
|
14
|
+
@content = content.strip
|
15
|
+
|
16
|
+
if (m = @content.match(%r/^(["'])((?:\1\1|(?!\1).)+)\1(?:\s+(.+))?$/))
|
17
|
+
@quote, @src, @rest = m.captures
|
18
|
+
@src = @src.gsub("#{@quote}#{@quote}", @quote)
|
19
|
+
|
20
|
+
elsif (m = @content.match(%r/^(?!["'])((?:(?!\{\{)\S|\{\{.+?\}\})+)(?:\s+(.+))?$/))
|
21
|
+
@quote = ""
|
22
|
+
@src, @rest = m.captures
|
23
|
+
|
24
|
+
else
|
25
|
+
raise SyntaxError, "#{NAME}: invalid #{tag_name} tag: '#{@content}'"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def debug(message)
|
30
|
+
Jekyll.logger.debug "#{NAME}:", message
|
31
|
+
end
|
32
|
+
|
33
|
+
def render(context)
|
34
|
+
debug "---"
|
35
|
+
debug "content: '#{@content}'"
|
36
|
+
debug "src: '#{@src}'"
|
37
|
+
debug "rest: '#{@rest}'"
|
38
|
+
|
39
|
+
src = Liquid::Template.parse(@src).render(context)
|
40
|
+
debug "src rendered: '#{src}'"
|
41
|
+
img = "<img src=#{@quote}#{src}#{@quote}"
|
42
|
+
|
43
|
+
path = resolve_path(src, context)
|
44
|
+
size = FastImage.size(path)
|
45
|
+
raise LoadError, "#{NAME}: could not get size of image '#{path}'" unless size
|
46
|
+
|
47
|
+
debug "image size: #{size}"
|
48
|
+
img << " width=#{@quote}#{size[0]}#{@quote} height=#{@quote}#{size[1]}#{@quote}"
|
49
|
+
|
50
|
+
rest = Liquid::Template.parse(@rest).render(context)
|
51
|
+
debug "rest rendered: '#{rest}'"
|
52
|
+
img << " #{rest}" unless rest.empty?
|
53
|
+
|
54
|
+
img << ">"
|
55
|
+
end
|
56
|
+
|
57
|
+
def resolve_path(src, context)
|
58
|
+
path = CGI.unescape(src.sub(%r!\?.*!, ""))
|
59
|
+
|
60
|
+
local_path = resolve_local_path(path, context)
|
61
|
+
return local_path if File.file?(local_path)
|
62
|
+
|
63
|
+
themed_path = resolve_themed_path(path, context) if path.start_with?("/")
|
64
|
+
raise LoadError, "#{NAME}: '#{local_path}' could not be found" unless themed_path
|
65
|
+
|
66
|
+
return themed_path if File.file?(themed_path)
|
67
|
+
|
68
|
+
raise LoadError, "#{NAME}: none of '#{local_path}', '#{themed_path}' could be found"
|
69
|
+
end
|
70
|
+
|
71
|
+
def resolve_local_path(path, context)
|
72
|
+
path = File.join(context.registers[:page]["dir"], path) unless path.start_with?("/")
|
73
|
+
local_path = File.join(context.registers[:site].source, path)
|
74
|
+
debug "image path: '#{local_path}'"
|
75
|
+
|
76
|
+
local_path
|
77
|
+
end
|
78
|
+
|
79
|
+
def resolve_themed_path(path, context)
|
80
|
+
themed_path = context.registers[:site].in_theme_dir(path)
|
81
|
+
debug "themed image path: '#{themed_path}'"
|
82
|
+
|
83
|
+
themed_path
|
84
|
+
end
|
85
|
+
|
86
|
+
Liquid::Template.register_tag Jekyll.configuration.dig(NAME, "tag_name") || "img", self
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-imgwh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikalai Ananenka
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-04-22 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: fastimage
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.4'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.4'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: jekyll
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '4.0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rspec
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rubocop
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.57'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.57'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rubocop-jekyll
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.14.0
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.14.0
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rubocop-rspec
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: ruby-lsp
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.9'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.9'
|
110
|
+
description: 'Jekyll tag for HTML <img> element which verifies that image exists and
|
111
|
+
automatically fills width and height attributes.
|
112
|
+
|
113
|
+
'
|
114
|
+
email:
|
115
|
+
- ojuuji@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- lib/jekyll-imgwh.rb
|
121
|
+
- lib/jekyll-imgwh/version.rb
|
122
|
+
homepage: https://github.com/ojuuji/jekyll-imgwh
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2.7'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubygems_version: 3.6.2
|
141
|
+
specification_version: 4
|
142
|
+
summary: Jekyll tag for HTML <img> element with auto filled size attributes
|
143
|
+
test_files: []
|