middleman-mdocs 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/middleman-mdocs/file_renderer_cache.rb +1 -1
- data/lib/middleman-mdocs/resource.rb +65 -21
- data/lib/middleman-mdocs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbfbd40e49f58b11ba5a574c16976c4c13d74bffbc931a9600470ec8ea54cbe9
|
4
|
+
data.tar.gz: 409e96bc9d7e9023f15fc23b2d79bb7870387018bec1d2ec96142010a1bc266f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2547991a43fea03ad9c614548926bfe060d4bc46cc6908dbba07180238b9e97b64ac84184f8f841b346b0ab792fddd18d9262d2f12a6f625ef86a853e4013d07
|
7
|
+
data.tar.gz: 937f5865c60c4155ea4be1f7702a3bd44d1c8177ebd9ee35adfefaf9462f7283e4829f4f5a94f5db65268389bca155272de56807b25fe949e6cf668939d52443
|
data/Gemfile.lock
CHANGED
@@ -7,7 +7,7 @@ module ::Middleman
|
|
7
7
|
ORIGINAL_RENDER = Engine.fetch_from(self).decorated_methods_for(:instance_methods, :render)[0].method.instance_variable_get('@method')
|
8
8
|
|
9
9
|
def render(locs, opts, context, &block)
|
10
|
-
return ORIGINAL_RENDER.bind(self).call(locs, opts, context, &block) if locs[:rack]
|
10
|
+
return ORIGINAL_RENDER.bind(self).call(locs, opts, context, &block) # if locs[:rack]
|
11
11
|
|
12
12
|
cache_key = Digest::MD5.hexdigest("#{locs.to_h.to_json}_#{opts.to_h.to_json}")
|
13
13
|
|
@@ -21,11 +21,25 @@ module MiddlemanMdocs
|
|
21
21
|
def html?
|
22
22
|
@html ||= destination_path.end_with?('.html')
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def ready?
|
26
26
|
mdocs.ready?
|
27
27
|
end
|
28
28
|
|
29
|
+
def touch
|
30
|
+
@updated = SecureRandom.hex
|
31
|
+
end
|
32
|
+
|
33
|
+
def data
|
34
|
+
$data_cache ||= {}
|
35
|
+
$data_cache[page_id] ||= super
|
36
|
+
end
|
37
|
+
|
38
|
+
def metadata
|
39
|
+
$metadata_cache ||= {}
|
40
|
+
$metadata_cache[destination_path] ||= super
|
41
|
+
end
|
42
|
+
|
29
43
|
def copy_from(other)
|
30
44
|
resource = self
|
31
45
|
unless @patched
|
@@ -70,12 +84,8 @@ module MiddlemanMdocs
|
|
70
84
|
(mdocs.dependencies(self).map(&:timestamp) + [File.mtime(File.realdirpath(source_file)), File.mtime(source_file)]).max
|
71
85
|
end
|
72
86
|
|
73
|
-
def cache_key
|
74
|
-
"#{page_id}/#{timestamp}/"
|
75
|
-
end
|
76
|
-
|
77
87
|
def title
|
78
|
-
with_cache(:title
|
88
|
+
with_cache(:title) do
|
79
89
|
data[:title] || metadata[:title] || toc&.children&.first&.raw_text
|
80
90
|
end
|
81
91
|
end
|
@@ -87,11 +97,11 @@ module MiddlemanMdocs
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def text
|
90
|
-
force_render if !metadata[:ignore] && html?
|
100
|
+
force_render(:text) if !metadata[:ignore] && html?
|
91
101
|
end
|
92
102
|
|
93
103
|
def tags
|
94
|
-
with_cache(:tags
|
104
|
+
with_cache(:tags) do
|
95
105
|
guard_recursive('tags', page_id, []) do |_key|
|
96
106
|
text
|
97
107
|
end
|
@@ -101,14 +111,14 @@ module MiddlemanMdocs
|
|
101
111
|
end
|
102
112
|
|
103
113
|
def keywords
|
104
|
-
with_cache(:keywords
|
114
|
+
with_cache(:keywords) do
|
105
115
|
options[:keywords] =
|
106
116
|
::MiddlemanMdocs::Resource.normalize_keywords(tags, options[:keywords], data[:keywords], metadata[:keywords])
|
107
117
|
end
|
108
118
|
end
|
109
119
|
|
110
120
|
def toc
|
111
|
-
with_cache(:toc
|
121
|
+
with_cache(:toc) do
|
112
122
|
if metadata[:ignore] || !html?
|
113
123
|
nil
|
114
124
|
else
|
@@ -131,7 +141,7 @@ module MiddlemanMdocs
|
|
131
141
|
added = ::MiddlemanMdocs::Resource.normalize_tags(args)
|
132
142
|
return if (added - (options[:tags] || [])).empty?
|
133
143
|
|
134
|
-
|
144
|
+
cache_reset(:tags)
|
135
145
|
options[:tags] = ::MiddlemanMdocs::Resource.normalize_tags(options[:tags], data[:tags], metadata[:tags], added)
|
136
146
|
end
|
137
147
|
|
@@ -141,7 +151,7 @@ module MiddlemanMdocs
|
|
141
151
|
added = ::MiddlemanMdocs::Resource.normalize_keywords(args)
|
142
152
|
return if (added - (options[:keywords] || [])).empty?
|
143
153
|
|
144
|
-
|
154
|
+
cache_reset(:keywords)
|
145
155
|
options[:keywords] =
|
146
156
|
::MiddlemanMdocs::Resource.normalize_keywords(options[:tags], options[:keywords], data[:keywords], metadata[:keywords],
|
147
157
|
added)
|
@@ -167,32 +177,66 @@ module MiddlemanMdocs
|
|
167
177
|
super.force_encoding(Encoding.default_external)
|
168
178
|
end
|
169
179
|
|
170
|
-
def force_render
|
171
|
-
render({ layout: false }, { current_path: path, force_current_page: self })
|
180
|
+
def force_render key = :force
|
181
|
+
render({ layout: false, key: key}, { current_path: path, force_current_page: self })
|
172
182
|
end
|
173
183
|
|
174
184
|
def render(opts = {}, locs = {})
|
175
|
-
return super # cache now work on FileRenderer level
|
176
|
-
|
177
|
-
#old cache impl
|
178
185
|
return super if nocache? || locs.has_key?('rack') || locs.has_key?(:rack)
|
179
|
-
|
186
|
+
|
180
187
|
with_cache(Digest::MD5.hexdigest(opts.to_json + locs.to_json) + 'render') do
|
181
188
|
# puts "REFRESH: #{binary?} #{page_id}: #{opts.to_json + locs.to_json}"
|
182
189
|
super
|
183
190
|
end
|
184
191
|
end
|
185
192
|
|
193
|
+
def cache_key(*key)
|
194
|
+
"#{page_id}/#{timestamp}/#{key.map(&:to_s).sort.join('_')}"
|
195
|
+
end
|
196
|
+
|
186
197
|
private
|
187
198
|
|
199
|
+
PARTIAL_RX = ['partial', 'include', 'render', 'merge'].map do |token|
|
200
|
+
/\b#{token}\b/
|
201
|
+
end
|
202
|
+
|
188
203
|
def nocache?
|
189
|
-
|
204
|
+
tmpl = with_cache(:noacahe, expires_in: 1.minute) do
|
205
|
+
file_descriptor.try(:read).then do |content|
|
206
|
+
false if content.nil?
|
207
|
+
PARTIAL_RX.any? do |rx|
|
208
|
+
content.match(rx)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
#r = binary? || metadata[:ignore] || metadata[:nocache] || data[:nocache] || tmpl
|
214
|
+
r = binary? || metadata[:nocache] || data[:nocache] || tmpl
|
215
|
+
|
216
|
+
# if r
|
217
|
+
# puts "NOCACHE#{page_id}: #{r}"
|
218
|
+
# puts "b:#{binary?}"
|
219
|
+
# #puts "i:#{metadata[:ignore]}"
|
220
|
+
# puts "c:#{metadata[:nocache]}"
|
221
|
+
# puts "d:#{data[:nocache]}"
|
222
|
+
# puts "t:#{tmpl}"
|
223
|
+
# end
|
224
|
+
|
225
|
+
r
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
def cache_reset(*key)
|
231
|
+
extension.cache.delete([cache_key(key)])
|
190
232
|
end
|
191
233
|
|
192
|
-
def with_cache(*key, &block)
|
193
|
-
extension.cache.fetch([cache_key
|
234
|
+
def with_cache(*key, **opts, &block)
|
235
|
+
extension.cache.fetch([cache_key(key)], **opts, &block)
|
194
236
|
end
|
195
237
|
|
238
|
+
|
239
|
+
|
196
240
|
def custom_deep_merge!(left, right)
|
197
241
|
left.merge!(right) do |_key, this_val, other_val|
|
198
242
|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-mdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoylenko Yuri
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-11-
|
12
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.1.4
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Extension for Middleman
|