jekyll_flexible_include 2.0.15 → 2.0.19
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 +4 -4
- data/.rubocop.yml +18 -6
- data/CHANGELOG.md +19 -0
- data/README.md +73 -23
- data/jekyll_flexible_include_plugin.gemspec +3 -2
- data/lib/flexible_include/version.rb +1 -1
- data/lib/flexible_include.rb +89 -29
- data/lib/git_util.rb +41 -0
- metadata +23 -8
- /data/spec/{glob_spec.rb → flexible_include_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dda7cdd2a335fc1f4f64b9579c0b0973a3c817baee5cb3dccd45aea688081d4
|
4
|
+
data.tar.gz: 81c206fabbe87b73eaf6381e173fee3ea8dafcc3f79ce91a9a5560d6abcade49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 879ebc1e5250526005f3712b4c12b06fc936c0687e059e7f61401ca7d0cc4f724b0c216245f6fa555db9e3743f975afe40829c7acef8aef5b709c36be62e7bb0
|
7
|
+
data.tar.gz: e68c36ccac83b91af75ac84c24ea6f43da9f757d2cd30473788b40122a65fca461694adc99e0a83cec9329e02ca241b889b3ae44a7a2dc17228bcf03012de615
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require:
|
2
|
-
- rubocop-rspec
|
3
2
|
# - rubocop-jekyll
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
- rubocop-md
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
7
|
|
8
8
|
AllCops:
|
9
9
|
Exclude:
|
@@ -20,7 +20,12 @@ Gemspec/DeprecatedAttributeAssignment:
|
|
20
20
|
Gemspec/RequireMFA:
|
21
21
|
Enabled: false
|
22
22
|
|
23
|
+
Layout/InitialIndentation:
|
24
|
+
Exclude:
|
25
|
+
- README.md
|
26
|
+
|
23
27
|
Layout/HashAlignment:
|
28
|
+
EnforcedColonStyle: table
|
24
29
|
EnforcedHashRocketStyle: table
|
25
30
|
|
26
31
|
Layout/LineLength:
|
@@ -29,6 +34,10 @@ Layout/LineLength:
|
|
29
34
|
Layout/MultilineMethodCallIndentation:
|
30
35
|
Enabled: false
|
31
36
|
|
37
|
+
Lint/RedundantCopDisableDirective:
|
38
|
+
Exclude:
|
39
|
+
- jekyll_flexible_include_plugin.gemspec
|
40
|
+
|
32
41
|
Metrics/AbcSize:
|
33
42
|
Max: 45
|
34
43
|
|
@@ -42,10 +51,10 @@ Metrics/ClassLength:
|
|
42
51
|
- spec/**/*
|
43
52
|
|
44
53
|
Metrics/CyclomaticComplexity:
|
45
|
-
Max:
|
54
|
+
Max: 20
|
46
55
|
|
47
56
|
Metrics/MethodLength:
|
48
|
-
Max:
|
57
|
+
Max: 40
|
49
58
|
|
50
59
|
Metrics/PerceivedComplexity:
|
51
60
|
Max: 15
|
@@ -63,6 +72,9 @@ RSpec/MultipleExpectations:
|
|
63
72
|
Style/CommandLiteral:
|
64
73
|
Enabled: false
|
65
74
|
|
75
|
+
Style/CommentedKeyword:
|
76
|
+
Enabled: false
|
77
|
+
|
66
78
|
Style/Documentation:
|
67
79
|
Enabled: false
|
68
80
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
## 2.0.19 / 2023-04-05
|
2
|
+
* Added attribution support
|
3
|
+
|
4
|
+
## 2.0.18 / 2023-03-24
|
5
|
+
* The following are now parsed property:
|
6
|
+
`die_on_file_error`, `die_on_path_denied`, `die_on_run_error`, `die_on_path_denied`, and `die_on_other_error`.
|
7
|
+
|
8
|
+
## 2.0.17 / 2023-03-22
|
9
|
+
* Added `repo` and `git_ref` parameters, so files can be retrieved from git repositories at a given commit or tag.
|
10
|
+
|
11
|
+
## 2.0.16 / 2023-02-19
|
12
|
+
* Replaced hard-coded CSS in `denied` method with `flexible_error` class in
|
13
|
+
`demo/assets/css/style.css`.
|
14
|
+
* Added `-e` and `-x` options to `demo/_bin/debug`.
|
15
|
+
* Added configuration section `flexible_include` with supported parameters
|
16
|
+
`die_on_file_error`, `die_on_path_denied`, `die_on_run_error`,
|
17
|
+
`die_on_path_denied` and `die_on_other_error`.
|
18
|
+
* Fixed `undefined method 'path'` that occurred when `FLEXIBLE_INCLUDE_PATHS` was specified.
|
19
|
+
|
1
20
|
## 2.0.15 / 2023-02-18
|
2
21
|
* Replaced dependency `key-value-parser` with `jekyll_plugin_support`.
|
3
22
|
* Added `demo` website.
|
data/README.md
CHANGED
@@ -34,46 +34,79 @@ In addition, filenames that require environment expansion because they contain a
|
|
34
34
|
defined when <code>jekyll build</code> executes.
|
35
35
|
|
36
36
|
|
37
|
+
A file from a git repository can also be included.
|
38
|
+
Files can be retrieved from at a given commit or tag.
|
39
|
+
Two new options are provided for this purpose:
|
40
|
+
- `repo` - directory where git repo resides; environment variables are expanded; defaults to current directory.
|
41
|
+
- `git_ref` - Git ref of commit or tag to be examined for the file; defaults to `HEAD`.
|
42
|
+
|
43
|
+
|
44
|
+
### Configuration
|
45
|
+
Configuration parameters can be added to a section in `_config.yml` called `flexible_include`, like this:
|
46
|
+
|
47
|
+
```yaml
|
48
|
+
flexible_include:
|
49
|
+
die_on_file_error: true
|
50
|
+
die_on_path_denied: true
|
51
|
+
die_on_run_error: true
|
52
|
+
die_on_other_error: true
|
53
|
+
```
|
54
|
+
|
55
|
+
The default values for all of these parameters is `false`,
|
56
|
+
except for `die_on_other_error`, which defaults to `true`.
|
57
|
+
|
58
|
+
- If `die_on_file_error` is enabled, then an attempt to include a file that fails will cause Jekyll to die with an error message.
|
59
|
+
|
60
|
+
- If `die_on_path_denied` is enabled (see [Restricting Directory Access](#restricting-directory-access)), then an attempt to include a file that should be blocked will cause Jekyll to die with an error message.
|
61
|
+
|
62
|
+
- If `die_on_run_error` is enabled, then an attempt to run a process that fails will cause Jekyll to die with an error message.
|
63
|
+
|
64
|
+
- If `die_on_other_error` is enabled, then any other exception will cause Jekyll to die with an error message.
|
65
|
+
|
66
|
+
|
37
67
|
### Syntax
|
38
|
-
The following are equivalent:
|
68
|
+
The following are all equivalent, however, the first two are recommended:
|
39
69
|
```html
|
70
|
+
{% flexible_include file="path" [ OPTIONS ] %}
|
71
|
+
{% flexible_include file='path' [ OPTIONS ] %}
|
40
72
|
{% flexible_include path [ OPTIONS ] %}
|
41
73
|
{% flexible_include 'path' [ OPTIONS ] %}
|
42
74
|
{% flexible_include "path" [ OPTIONS ] %}
|
43
75
|
```
|
44
76
|
|
45
|
-
By default, the included file will escape characters <code><</code>,
|
46
|
-
<code>{</code> and <code>}</code> unless the <code>do_not_escape</code> keyword option is specified.
|
47
77
|
Note that the [square brackets] merely indicate optional parameters
|
48
78
|
and are not intended to be written literally.
|
49
79
|
|
50
80
|
|
51
81
|
### Options
|
52
|
-
* `
|
82
|
+
* `attribution` see [`jekyll_plugin_support`](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution)
|
83
|
+
* `do_not_escape` keyword option caused the content to be included without HTML escaping it.
|
84
|
+
By default, the included file will escape characters <code><</code>,
|
85
|
+
<code>{</code> and <code>}</code> unless the <code>do_not_escape</code> keyword option is specified.
|
53
86
|
|
54
87
|
* `highlight='regex pattern here'` wraps content matching the regex pattern within a
|
55
88
|
`<span class='bg_yellow'></span>` tag.
|
56
89
|
Note that the pattern can simply consist of the exact text that you want to highlight.
|
57
90
|
|
58
|
-
* `pre` causes the included file to be wrapped inside a
|
59
|
-
no label is generated.
|
91
|
+
* `pre` is a keyword option that causes the included file to be wrapped inside a
|
92
|
+
<pre></pre> tag; no label is generated.
|
60
93
|
The <pre></pre> tag has an `data-lt-active="false"` attribute, so
|
61
94
|
[LanguageTool](https://forum.languagetool.org/t/avoid-spell-check-on-certain-html-inputs-manually/3944)
|
62
95
|
will not attempt to check the spelling or grammar of the contents.
|
63
96
|
|
64
97
|
The following options imply `pre`:
|
65
|
-
* `dark` applies the `dark` class to the generated <pre></pre> tag.
|
98
|
+
* `dark` keyword option applies the `dark` class to the generated <pre></pre> tag.
|
66
99
|
You can define the `dark` and `darkLabel` classes as desired.
|
67
100
|
[This CSS is a good starting point.](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#pre_css)
|
68
101
|
|
69
|
-
* `download` uses the name of the file as a label,
|
102
|
+
* `download` keyword option uses the name of the file as a label,
|
70
103
|
and displays it above the <pre></pre> tag.
|
71
104
|
Clicking the label causes the file to be downloaded.
|
72
105
|
|
73
|
-
* `
|
106
|
+
* `copyButton` keyword option draws an icon at the top right of the <pre></pre>
|
74
107
|
tag that causes the included contents to be copied to the clipboard.
|
75
108
|
|
76
|
-
* `label` specifies that an automatically generated label be placed above the contents.
|
109
|
+
* `label` keyword option specifies that an automatically generated label be placed above the contents.
|
77
110
|
There is no need to specify this option if `download` or `copy_button` options are provided.
|
78
111
|
|
79
112
|
* `label="blah blah"` specifies a label for the contents; this value overrides the default label.
|
@@ -130,7 +163,7 @@ and a red error message will be logged on the console that says something like:
|
|
130
163
|
|
131
164
|
## Installation
|
132
165
|
1. Add the following to `Gemfile`, inside the `jekyll_plugins` group:
|
133
|
-
```
|
166
|
+
```ruby
|
134
167
|
group :jekyll_plugins do
|
135
168
|
gem 'jekyll_flexible_include', '~> 2.0.15'
|
136
169
|
end
|
@@ -172,13 +205,13 @@ and a red error message will be logged on the console that says something like:
|
|
172
205
|
{% flexible_include 'folder/within/jekyll/site/bar.js' %}
|
173
206
|
{% flexible_include '/etc/passwd' %}
|
174
207
|
{% flexible_include '~/.ssh/config' %}
|
175
|
-
{% flexible_include '!jekyll' %}
|
208
|
+
{% flexible_include '!jekyll help' %}
|
176
209
|
{% flexible_include '$HOME/.bash_aliases' %}
|
177
210
|
```
|
178
211
|
|
179
212
|
2. Include a JSON file (without escaping characters).
|
180
213
|
```
|
181
|
-
{% flexible_include '~/folder/under/home/directory/foo.html'
|
214
|
+
{% flexible_include do_not_escape file='~/folder/under/home/directory/foo.html' %}
|
182
215
|
```
|
183
216
|
|
184
217
|
## Additional Information
|
@@ -210,7 +243,7 @@ Following is a workaround.
|
|
210
243
|
## Known Issues
|
211
244
|
If the plugin does not work:
|
212
245
|
|
213
|
-
1. Ensure `_config.yml` doesn't have `safe: true
|
246
|
+
1. Ensure `_config.yml` doesn't have `safe: true` set.
|
214
247
|
That prevents all plugins from working.
|
215
248
|
|
216
249
|
2. If you have version older than v2.x.x,
|
@@ -246,19 +279,36 @@ jekyll_flexible_include (2.0.4)
|
|
246
279
|
```
|
247
280
|
|
248
281
|
|
249
|
-
## Demo
|
282
|
+
## Demo Website
|
250
283
|
A test/demo website is provided in the `demo` directory.
|
251
284
|
You can run it under a debugger, or let it run free.
|
252
285
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
286
|
+
The `demo/_bin/debug` script can set various parameters for the demo.
|
287
|
+
View the help information with the `-h` option:
|
288
|
+
```shell
|
289
|
+
$ demo/_bin/debug -h
|
290
|
+
|
291
|
+
debug - Run the demo Jekyll website.
|
292
|
+
|
293
|
+
By default the demo Jekyll website runs without restriction under ruby-debug-ide and debase.
|
294
|
+
View it at http://localhost:4444
|
295
|
+
|
296
|
+
Options:
|
297
|
+
-e Restrict the allowable directories to read from to the following regexes:
|
298
|
+
jekyll_flexible_include_plugin/.*
|
299
|
+
/dev/.*
|
300
|
+
/proc/.*
|
301
|
+
/run/.*
|
302
|
+
|
303
|
+
-h Show this error message
|
304
|
+
|
305
|
+
-r Run freely, without a debugger
|
306
|
+
|
307
|
+
-x Disable the ability to execute arbitrary commands
|
308
|
+
```
|
258
309
|
|
259
|
-
View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
260
310
|
|
261
|
-
###
|
311
|
+
### Debugging the Demo
|
262
312
|
To run under a debugger, for example Visual Studio Code:
|
263
313
|
1. Set breakpoints.
|
264
314
|
|
@@ -269,7 +319,7 @@ To run under a debugger, for example Visual Studio Code:
|
|
269
319
|
|
270
320
|
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch configuration called `Attach rdebug-ide`.
|
271
321
|
|
272
|
-
4. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
322
|
+
4. View the generated website at [`http://localhost:4444`](http://localhost:4444).
|
273
323
|
|
274
324
|
|
275
325
|
### Build and Push to RubyGems
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
14
14
|
END_OF_DESC
|
15
15
|
spec.email = ['mslinn@mslinn.com']
|
16
16
|
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
17
|
-
spec.homepage = 'https://www.mslinn.com/
|
17
|
+
spec.homepage = 'https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#flexibleInclude'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
spec.metadata = {
|
20
20
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
35
35
|
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
|
36
36
|
spec.version = JekyllFlexibleIncludePluginVersion::VERSION
|
37
37
|
|
38
|
-
spec.add_dependency 'jekyll_plugin_support', '~> 0.
|
38
|
+
spec.add_dependency 'jekyll_plugin_support', '~> 0.6.0'
|
39
|
+
spec.add_dependency 'rugged'
|
39
40
|
end
|
data/lib/flexible_include.rb
CHANGED
@@ -58,29 +58,21 @@ module FlexibleClassMethods
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
FlexibleIncludeError = Class.new(Liquid::Error)
|
62
62
|
|
63
|
-
class FlexibleInclude < JekyllSupport::JekyllTag
|
63
|
+
class FlexibleInclude < JekyllSupport::JekyllTag # rubocop: disable Metrics/ClassLength
|
64
64
|
include JekyllFlexibleIncludePluginVersion
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
FlexibleIncludeError = Class.new(Liquid::Error)
|
71
|
-
|
72
|
-
def render_impl
|
73
|
-
self.class.security_check
|
74
|
-
parse_args
|
66
|
+
def render_impl # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
67
|
+
setup
|
75
68
|
path = JekyllPluginHelper.expand_env(@filename)
|
76
|
-
|
77
69
|
case path
|
78
70
|
when /\A\// # Absolute path
|
79
|
-
return denied("Access to
|
71
|
+
return denied("Access to <code>#{path}</code> denied by <code>FLEXIBLE_INCLUDE_PATHS</code> value.") unless self.class.access_allowed(path)
|
80
72
|
|
81
73
|
@logger.debug { "Absolute path=#{path}, @filename=#{@filename}" }
|
82
74
|
when /\A~/ # Relative path to user's home directory
|
83
|
-
return denied("Access to
|
75
|
+
return denied("Access to <code>#{path}</code> denied by <code>FLEXIBLE_INCLUDE_PATHS</code> value.") unless self.class.access_allowed(path)
|
84
76
|
|
85
77
|
@logger.debug { "User home start @filename=#{@filename}, path=#{path}" }
|
86
78
|
@filename = @filename.delete_prefix '~/'
|
@@ -99,19 +91,49 @@ class FlexibleInclude < JekyllSupport::JekyllTag
|
|
99
91
|
@logger.debug { "Relative end @filename=#{@filename}, path=#{path}" }
|
100
92
|
end
|
101
93
|
render_completion(path, contents)
|
102
|
-
|
103
|
-
|
94
|
+
rescue Errno::EACCES => e
|
95
|
+
msg = format_error_message e.message
|
96
|
+
@logger.error msg
|
97
|
+
raise FlexibleIncludeError, msg, [] if @die_on_file_error
|
98
|
+
|
99
|
+
"<span class='flexible_error'>FlexibleIncludeError: #{msg}</span>"
|
100
|
+
rescue Errno::ENOENT => e
|
101
|
+
msg = format_error_message e.message
|
102
|
+
@logger.error msg
|
103
|
+
raise FlexibleIncludeError, msg, [] if @die_on_path_denied
|
104
|
+
|
105
|
+
"<span class='flexible_error'>FlexibleIncludeError: #{msg}</span>"
|
106
|
+
rescue FlexibleIncludeError => e
|
107
|
+
@logger.error e.message
|
108
|
+
raise e
|
109
|
+
rescue StandardError => e
|
110
|
+
msg = format_error_message e.message
|
111
|
+
@logger.error msg
|
112
|
+
raise FlexibleIncludeError, msg, [] if @die_on_other_error
|
113
|
+
|
114
|
+
"<span class='flexible_error'>FlexibleIncludeError: #{msg}</span>"
|
104
115
|
end
|
105
116
|
|
106
117
|
private
|
107
118
|
|
119
|
+
class << self
|
120
|
+
include FlexibleClassMethods
|
121
|
+
end
|
122
|
+
|
108
123
|
def denied(msg)
|
109
|
-
|
110
|
-
"
|
124
|
+
msg_no_html = remove_html_tags(msg)
|
125
|
+
@logger.error("#{@page['path']} - #{msg_no_html}")
|
126
|
+
raise FlexibleIncludeError, "#{@page['path']} - #{msg_no_html.red}", [] if @die_on_path_denied
|
127
|
+
|
128
|
+
"<p class='flexible_error'>#{msg}</p>"
|
129
|
+
end
|
130
|
+
|
131
|
+
def format_error_message(message)
|
132
|
+
"#{message} on line #{@line_number} (after front matter) of #{@page['path']}}"
|
111
133
|
end
|
112
134
|
|
113
135
|
def highlight(content, pattern)
|
114
|
-
content.gsub(Regexp
|
136
|
+
content.gsub(Regexp.new(pattern), "<span class='bg_yellow'>\\0</span>")
|
115
137
|
end
|
116
138
|
|
117
139
|
def parse_args
|
@@ -138,28 +160,66 @@ class FlexibleInclude < JekyllSupport::JekyllTag
|
|
138
160
|
@logger.debug("@filename=#{@filename}")
|
139
161
|
end
|
140
162
|
|
141
|
-
|
142
|
-
File.read(file)
|
143
|
-
end
|
144
|
-
|
163
|
+
# Not used, delete
|
145
164
|
def realpath_prefixed_with?(path, dir)
|
146
165
|
File.exist?(path) && File.realpath(path).start_with?(dir)
|
147
|
-
rescue StandardError
|
148
|
-
|
166
|
+
rescue StandardError => _e
|
167
|
+
raise FlexibleIncludeError, remove_html_tags(e.message).red, [] if @die_on_file_error
|
168
|
+
end
|
169
|
+
|
170
|
+
def remove_html_tags(string)
|
171
|
+
string.gsub(/<[^>]*>/, '')
|
149
172
|
end
|
150
173
|
|
151
174
|
def render_completion(path, contents)
|
152
|
-
contents ||=
|
175
|
+
contents ||= File.read(path)
|
153
176
|
contents.strip! if @strip
|
154
177
|
contents2 = @do_not_escape ? contents : FlexibleClassMethods.escape_html(contents)
|
155
178
|
contents2 = highlight(contents2, @highlight_pattern) if @highlight_pattern
|
156
179
|
contents2 = FlexibleInclude.number_content(contents2) if @number_lines
|
157
|
-
@pre ? wrap_in_pre(path, contents2) : contents2
|
180
|
+
result = @pre ? wrap_in_pre(path, contents2) : contents2
|
181
|
+
<<~END_OUTPUT
|
182
|
+
#{result}
|
183
|
+
#{@helper.attribute if @helper.attribution}
|
184
|
+
END_OUTPUT
|
158
185
|
end
|
159
186
|
|
160
187
|
def run(cmd)
|
161
|
-
|
188
|
+
if cmd.empty?
|
189
|
+
msg = format_error_message 'FlexibleIncludeError: Empty command string'
|
190
|
+
@do_not_escape = true
|
191
|
+
return "<span class='flexible_error'>#{msg}</span>" unless @die_on_other_error
|
192
|
+
|
193
|
+
raise FlexibleIncludeError, msg, []
|
194
|
+
end
|
195
|
+
|
196
|
+
@logger.debug { "Executing #{cmd}" }
|
162
197
|
%x[#{cmd}].chomp
|
198
|
+
rescue FlexibleIncludeError => e
|
199
|
+
raise e
|
200
|
+
rescue StandardError => e
|
201
|
+
msg = format_error_message "#{e.class}: #{e.message.strip}"
|
202
|
+
@logger.error msg
|
203
|
+
@do_not_escape = true
|
204
|
+
return "<span class='flexible_error'>#{msg}</span>" unless @die_on_run_error
|
205
|
+
|
206
|
+
e.set_backtrace []
|
207
|
+
raise e
|
208
|
+
end
|
209
|
+
|
210
|
+
def setup
|
211
|
+
@helper.gem_file __FILE__ # Enables attribution
|
212
|
+
self.class.security_check
|
213
|
+
|
214
|
+
config = @config[JekyllFlexibleIncludeName::PLUGIN_NAME]
|
215
|
+
if config
|
216
|
+
@die_on_file_error = config['die_on_file_error'] == true
|
217
|
+
@die_on_other_error = config['die_on_other_error'] == true
|
218
|
+
@die_on_path_denied = config['die_on_path_denied'] == true
|
219
|
+
@die_on_run_error = config['die_on_run_error'] == true
|
220
|
+
end
|
221
|
+
|
222
|
+
parse_args
|
163
223
|
end
|
164
224
|
|
165
225
|
PREFIX = "<button class='copyBtn' data-clipboard-target=".freeze
|
@@ -181,7 +241,7 @@ class FlexibleInclude < JekyllSupport::JekyllTag
|
|
181
241
|
dark_label = ' darkLabel' if @dark
|
182
242
|
<<~END_PRE
|
183
243
|
<div class="codeLabel#{dark_label}">#{label_or_href}</div>
|
184
|
-
<pre data-lt-active="false" class="maxOneScreenHigh copyContainer#{@dark}" id="#{pre_id}">#{copy_button}#{content}</pre>
|
244
|
+
<pre data-lt-active="false" class="pre_tag maxOneScreenHigh copyContainer#{@dark}" id="#{pre_id}">#{copy_button}#{content}</pre>
|
185
245
|
END_PRE
|
186
246
|
end
|
187
247
|
|
data/lib/git_util.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
|
3
|
+
class GitFileReader
|
4
|
+
def initialize(repo_dir = '.')
|
5
|
+
@repo = Rugged::Repository.new repo_dir
|
6
|
+
end
|
7
|
+
|
8
|
+
def blob_at(ref, path)
|
9
|
+
commit = @repo.rev_parse ref # Rugged::Commit
|
10
|
+
@repo.blob_at(commit.oid, path) # Rugged::Blob
|
11
|
+
end
|
12
|
+
|
13
|
+
def commit_for_ref(ref)
|
14
|
+
reference = @repo.ref ref # Rugged::Reference
|
15
|
+
abort "Error: #{ref} is an invalid ref" if reference.nil?
|
16
|
+
|
17
|
+
reference_direct = reference.type == :symbolic ? reference.target : reference
|
18
|
+
@commit = reference_direct.target # Rugged::Commit
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return content of desired file
|
23
|
+
def contents(filename)
|
24
|
+
abort('Error: @commit is undefined; invoke commit_for_ref before invoking contents') if @commit.nil?
|
25
|
+
|
26
|
+
tree = @commit.tree # Rugged::Tree
|
27
|
+
entry = tree.get_entry filename # hash
|
28
|
+
abort("Error: #{filename} is not present in commit #{commit.oid}") if entry.nil?
|
29
|
+
|
30
|
+
sha = entry[:oid] # String
|
31
|
+
object = @repo.read sha # Rugged::ObdObject; this is a blob
|
32
|
+
object.data # String
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if $PROGRAM_NAME == __FILE__
|
37
|
+
puts GitFileReader.new('.').blob_at('HEAD~2', 'README.md').content
|
38
|
+
# puts GitFileReader.new('.').commit_for_ref('HEAD^').contents('README.md')
|
39
|
+
# puts GitFileReader.new('.').commit_for_ref('HEAD').contents('README.md')
|
40
|
+
# puts GitFileReader.new('.').commit_for_ref('refs/heads/master').contents('README.md')
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_flexible_include
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jekyll_plugin_support
|
@@ -18,14 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 0.6.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rugged
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
29
43
|
description: |
|
30
44
|
Jekyll's built-in include tag only supports including files within the _includes folder.
|
31
45
|
This plugin supports 4 types of includes: absolute filenames,
|
@@ -45,17 +59,18 @@ files:
|
|
45
59
|
- jekyll_flexible_include_plugin.gemspec
|
46
60
|
- lib/flexible_include.rb
|
47
61
|
- lib/flexible_include/version.rb
|
48
|
-
-
|
62
|
+
- lib/git_util.rb
|
63
|
+
- spec/flexible_include_spec.rb
|
49
64
|
- spec/spec_helper.rb
|
50
65
|
- spec/status_persistence.txt
|
51
|
-
homepage: https://www.mslinn.com/
|
66
|
+
homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#flexibleInclude
|
52
67
|
licenses:
|
53
68
|
- MIT
|
54
69
|
metadata:
|
55
70
|
allowed_push_host: https://rubygems.org
|
56
71
|
bug_tracker_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/issues
|
57
72
|
changelog_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md
|
58
|
-
homepage_uri: https://www.mslinn.com/
|
73
|
+
homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#flexibleInclude
|
59
74
|
source_code_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
|
60
75
|
post_install_message: |2+
|
61
76
|
|
@@ -81,7 +96,7 @@ specification_version: 4
|
|
81
96
|
summary: Jekyll plugin supports various ways to include content into the generated
|
82
97
|
site.
|
83
98
|
test_files:
|
84
|
-
- spec/
|
99
|
+
- spec/flexible_include_spec.rb
|
85
100
|
- spec/spec_helper.rb
|
86
101
|
- spec/status_persistence.txt
|
87
102
|
...
|
File without changes
|