no-style-please2-plugins 0.10.0 → 0.11.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ext.rb +133 -15
  3. data/lib/version/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f82e1c6a05044ef732806e52e77c0fc951f0deb1b90160d6e877e7da2470a14a
4
- data.tar.gz: f20c7c46f7bc1ddb8faef3b8d8465d35db325c6fae51d283228c5268b95ec731
3
+ metadata.gz: b4019f862d9afa74d95a4bcacd0f2c401eaf5e6317f62104582838f65c9b39b7
4
+ data.tar.gz: e0fd447728fc26818fc8a78a12a99c4566ffb332cd05aa392aa5f61e75958854
5
5
  SHA512:
6
- metadata.gz: d58cd20a98fa8d47b20e7d9a3e924a5c12a7a8eda34fe778efc7b1b56786e2a41856c88d1e2164a8ed0106020310d85113c35182c7de6f3374e98f66a7fdb602
7
- data.tar.gz: 27aedd26b1c4a59e93da490e58f97a1a58746e41f44b5cc01948909b9044ce897a2e3b234187d304bc8390fdf6b70909844b21434bd423edb7d9b7315de2f1f3
6
+ metadata.gz: b61c348fa5d6269cf1a2563846a381dd7aebc1b0b73577a7f6b5f9779e7c1fb209ebec001c22f28a84a84f06ff554c0ac80828708266db59706def47c990db5a
7
+ data.tar.gz: 0edd0b4a9dbb59130998f7061de8f834645b0609dd4795e79609c9a311acc28533a2295c1522beafd95f996491195df7a33d8a18acace67df32245d89473559e
data/lib/ext.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "jekyll"
2
2
  require "liquid"
3
3
  require "fileutils"
4
-
4
+ require 'base64'
5
5
  module Jekyll
6
6
  class RenderTimeTag < Liquid::Tag
7
7
 
@@ -127,7 +127,7 @@ module Jekyll
127
127
 
128
128
  def initialize(tag_name, text, tokens)
129
129
  rootPath0 = $g_config['include_file_path'] || 'assets'
130
- filePath0 = "#{rootPath0}/#{text}".strip!()
130
+ filePath0 = "#{rootPath0}/#{text}".strip()
131
131
  begin
132
132
  file = File.open(filePath0)
133
133
  @filecontent = file.read()
@@ -152,9 +152,9 @@ module Jekyll
152
152
 
153
153
  rootPath = $g_config['code_root_path'] || 'static'
154
154
  if text.start_with?("/")
155
- filePath = "#{text}"[1..-1].strip!()
155
+ filePath = "#{text}"[1..-1].strip()
156
156
  else
157
- filePath = "#{rootPath}/#{text}".strip!()
157
+ filePath = "#{rootPath}/#{text}".strip()
158
158
  end
159
159
  filePath = File.expand_path(filePath)
160
160
  puts "--------- include code: #{filePath}"
@@ -183,34 +183,150 @@ EOF
183
183
 
184
184
 
185
185
  class IncludeRaw < Liquid::Tag
186
- @filecontent = ""
187
- def initialize(tag_name, text, tokens)
188
-
186
+ Syntax = /\s*file\s*=\s*(\S+)/
187
+
188
+
189
+ def getPath(text,context)
189
190
  rootPath = $g_config['code_root_path'] || 'static'
190
191
  if text.start_with?("/")
191
- filePath = "#{text}"[1..-1].strip!()
192
+ filePath = "#{text}"[1..-1].strip()
193
+ filePath = File.expand_path(filePath)
194
+ elsif text.start_with?("@")
195
+ # _include/
196
+ filePath = "#{text}"[1..-1].strip()
197
+
198
+
199
+ site = context.registers[:site]
200
+ user_include_path = File.join(site.source, "_includes", filePath)
201
+
202
+ site = Jekyll.sites.first # 或你自己已有的 site
203
+ theme = site.theme
204
+
205
+ themeroot = theme.root # 就是当前主题的根目录
206
+ plugin_include_file = File.join(themeroot, "_includes/" + filePath)
207
+
208
+ if File.exist?(user_include_path)
209
+ filePath = user_include_path
210
+ elsif File.exist?(plugin_include_file)
211
+ filePath = plugin_include_file
212
+ else
213
+ filePath = user_include_path
214
+ end
215
+
216
+
192
217
  else
193
- filePath = "#{rootPath}/#{text}".strip!()
218
+ filePath = "#{rootPath}/#{text}".strip()
219
+ filePath = File.expand_path(filePath)
220
+ end
221
+ return filePath
222
+ end
223
+ def initialize(tag_name, text, tokens)
224
+
225
+ @file = ""
226
+ @dynamicFile = ""
227
+
228
+ if text =~ Syntax
229
+ dynfile = Regexp.last_match(1)
230
+ @dynamicFile = dynfile.gsub(/^['"]|['"]$/, '')
231
+ else
232
+ @filename = text.gsub(/^['"]|['"]$/, '')
194
233
  end
195
- filePath = File.expand_path(filePath)
196
- puts "--------- include raw:\n #{filePath}"
197
234
 
235
+
236
+
237
+ end
238
+
239
+ def render(context)
240
+ filePath = @filename
241
+ if @dynamicFile.length > 1
242
+ filePath = context[@dynamicFile]
243
+ end
244
+ filePath = getPath(filePath,context)
245
+
246
+ puts "include_raw :#{filePath} failed #{@dynamicFile}"
198
247
  begin
199
248
  file = File.open(filePath)
200
- @filecontent = file.read()
249
+ return file.read()
201
250
  rescue => exception
202
251
  puts exception
203
- @filecontent = "load file:#{filePath} failed"
252
+ return "Load file:#{filePath} failed #{@dynamicFile}"
204
253
 
205
254
  end
255
+ end
256
+ end
257
+
258
+
259
+ class FileBase64 < Liquid::Tag
260
+ Syntax = /\s*file\s*=\s*(\S+)/
261
+
262
+
263
+ def getPath(text,context)
264
+ rootPath = $g_config['code_root_path'] || 'static'
265
+ if text.start_with?("/")
266
+ filePath = "#{text}"[1..-1].strip()
267
+ filePath = File.expand_path(filePath)
268
+ elsif text.start_with?("@")
269
+ # _include/
270
+ filePath = "#{text}"[1..-1].strip()
271
+
272
+
273
+ site = context.registers[:site]
274
+ user_include_path = File.join(site.source, "_includes", filePath)
275
+
276
+ site = Jekyll.sites.first # 或你自己已有的 site
277
+ theme = site.theme
278
+
279
+ themeroot = theme.root # 就是当前主题的根目录
280
+ plugin_include_file = File.join(themeroot, "_includes/" + filePath)
281
+
282
+ if File.exist?(user_include_path)
283
+ filePath = user_include_path
284
+ elsif File.exist?(plugin_include_file)
285
+ filePath = plugin_include_file
286
+ else
287
+ filePath = user_include_path
288
+ end
289
+
290
+
291
+ else
292
+ filePath = "#{rootPath}/#{text}".strip()
293
+ filePath = File.expand_path(filePath)
294
+ end
295
+ return filePath
296
+ end
297
+ def initialize(tag_name, text, tokens)
298
+
299
+ @file = ""
300
+ @dynamicFile = ""
301
+
302
+ if text =~ Syntax
303
+ dynfile = Regexp.last_match(1)
304
+ @dynamicFile = dynfile.gsub(/^['"]|['"]$/, '')
305
+ else
306
+ @filename = text.gsub(/^['"]|['"]$/, '')
307
+ end
308
+
309
+
206
310
 
207
311
  end
208
312
 
209
313
  def render(context)
210
- return @filecontent
314
+ filePath = @filename
315
+ if @dynamicFile.length > 1
316
+ filePath = context[@dynamicFile]
317
+ end
318
+ filePath = getPath(filePath,context)
319
+
320
+ begin
321
+ file = File.open(filePath)
322
+ return Base64.strict_encode64 file.read()
323
+ rescue => exception
324
+ puts exception
325
+ return "Base64 file:#{filePath} failed #{@dynamicFile}"
326
+
327
+ end
211
328
  end
212
329
  end
213
-
214
330
 
215
331
 
216
332
 
@@ -219,6 +335,8 @@ EOF
219
335
  Liquid::Template.register_tag('asset_img', Jekyll::AssetImg)
220
336
  Liquid::Template.register_tag('include_code', Jekyll::IncludeCode)
221
337
  Liquid::Template.register_tag('include_raw', Jekyll::IncludeRaw)
338
+ Liquid::Template.register_tag('file_base64', Jekyll::FileBase64)
339
+
222
340
 
223
341
 
224
342
  Liquid::Template.register_tag('post_link', Jekyll::PostLink)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoStylePlease2
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no-style-please2-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitock
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-25 00:00:00.000000000 Z
11
+ date: 2025-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll