no-style-please2-plugins 0.10.0 → 0.11.1

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 +61 -17
  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: afe6e6995a5c47069cd2b21d4e48a1cf29afab98905f355f227e1241cb30ee4b
4
+ data.tar.gz: 2c09e5836ff991484ad4ed9bd62e3c3b48e1be398bd77c66f17687bcdc854f13
5
5
  SHA512:
6
- metadata.gz: d58cd20a98fa8d47b20e7d9a3e924a5c12a7a8eda34fe778efc7b1b56786e2a41856c88d1e2164a8ed0106020310d85113c35182c7de6f3374e98f66a7fdb602
7
- data.tar.gz: 27aedd26b1c4a59e93da490e58f97a1a58746e41f44b5cc01948909b9044ce897a2e3b234187d304bc8390fdf6b70909844b21434bd423edb7d9b7315de2f1f3
6
+ metadata.gz: faa96fe0004c5b9a525f5feb106aaf68ad788e2659a0aaea1d3662ac3b0b177a957215e6e37adab275f2e532f9f7b53eef05be249d92ef83a2c9cefd8ae1ee44
7
+ data.tar.gz: 29a9c97558cce0c387fda8a94163ffe5cb75e9d171e65424e7dcf74c25d6df2d90593e09613ab24a5d0749187141cd0a764609990b51ca12a3cddac9801d699a
data/lib/ext.rb CHANGED
@@ -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,31 +183,75 @@ 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)
194
220
  end
195
- filePath = File.expand_path(filePath)
196
- puts "--------- include raw:\n #{filePath}"
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(/^['"]|['"]$/, '')
233
+ end
234
+
235
+
197
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
206
-
207
- end
208
-
209
- def render(context)
210
- return @filecontent
211
255
  end
212
256
  end
213
257
 
@@ -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.1"
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.1
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-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll