jekyll_flexible_include 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +39 -0
- data/.rubocop.yml +31 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +22 -0
- data/README.md +82 -0
- data/Rakefile +4 -0
- data/jekyll_flexible_include_plugin.gemspec +51 -0
- data/lib/flexible_include/version.rb +5 -0
- data/lib/flexible_include.rb +192 -0
- data/sig/jekyll_flexible_include_plugin.rbs +4 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5c1b70f6c4d2af7c842a903f5fed045b3a94f4e774d202ce4c46f1b95c0bc36
|
4
|
+
data.tar.gz: 06d010e24a73c1de5ab88aa32482af9b34aedecdb5965884fb41eada3304417b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00cb719cdc78b8b2ef6540e3591cf69b49ad02b2088627f6cc9997f612211a3de6ce359264c7dedf5be31ba6903cf6ae08308a5331078f46a665f160d540dc0e
|
7
|
+
data.tar.gz: 4de33e76a9cf52af682f1f01cc4b362ee6175ecf2484962ef6acb797b8367322a81da9f0a6e9ed332aa18aef0d604c97ba71c91ac60277c1e54c351171ae11c9
|
data/.editorconfig
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# This file is for unifying the coding style for different editors and IDEs
|
2
|
+
# editorconfig.org
|
3
|
+
|
4
|
+
# https://editorconfig.org/
|
5
|
+
root = true
|
6
|
+
|
7
|
+
[*]
|
8
|
+
charset = utf-8
|
9
|
+
indent_style = space
|
10
|
+
indent_size = 2
|
11
|
+
tab_width = 2
|
12
|
+
end_of_line = lf
|
13
|
+
trim_trailing_whitespace = true
|
14
|
+
insert_final_newline = true
|
15
|
+
|
16
|
+
[*.{java,jsp}]
|
17
|
+
indent_size = 4
|
18
|
+
tab_width = 4
|
19
|
+
insert_final_newline = false
|
20
|
+
|
21
|
+
[{*.{awk,bat,c,cpp,d,h,l,mk,re,skl,w32,y},Makefile*}]
|
22
|
+
indent_size = 4
|
23
|
+
indent_style = tab
|
24
|
+
|
25
|
+
[*.{dtd,html,inc,php,phpt,rng,wsdl,xml,xsd,xsl}]
|
26
|
+
indent_size = 4
|
27
|
+
indent_style = space
|
28
|
+
|
29
|
+
[*.md]
|
30
|
+
indent_style = space
|
31
|
+
max_line_length = 80
|
32
|
+
|
33
|
+
[COMMIT_EDITMSG]
|
34
|
+
indent_size = 4
|
35
|
+
indent_style = space
|
36
|
+
max_line_length = 80
|
37
|
+
|
38
|
+
[*.patch]
|
39
|
+
trim_trailing_whitespace = false
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require: rubocop-jekyll
|
2
|
+
inherit_gem:
|
3
|
+
rubocop-jekyll: .rubocop.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- vendor/**/*
|
8
|
+
- Gemfile*
|
9
|
+
NewCops: enable
|
10
|
+
TargetRubyVersion: 2.6
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 150
|
14
|
+
|
15
|
+
Layout/MultilineMethodCallIndentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/PercentLiteralDelimiters:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/RegexpLiteral:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/StringLiterals:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/StringLiteralsInInterpolation:
|
31
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# HEAD
|
2
|
+
|
3
|
+
## 2.0.0 / 2022-03-11
|
4
|
+
* Made into a Ruby gem and published on RubyGems.org
|
5
|
+
* `bin/attach` script added for debugging
|
6
|
+
* Rubocop standards added
|
7
|
+
* Proper versioning and CHANGELOG.md added
|
8
|
+
|
9
|
+
## 1.1.1 / 2021-05-01
|
10
|
+
* Handles spaces in filenames properly.
|
11
|
+
|
12
|
+
## 1.1.0 / 2020-04-27
|
13
|
+
* Added `do_not_escape` optional parameter.
|
14
|
+
|
15
|
+
## 1.0.0 / 2020-11-28
|
16
|
+
* Mike Slinn took over the project
|
17
|
+
* Now supports relative includes
|
18
|
+
|
19
|
+
## 2020-11-28
|
20
|
+
* Renamed include_absolute to flexible_include
|
21
|
+
|
22
|
+
## 2020-08-23
|
23
|
+
* Now supports absolute paths
|
24
|
+
|
25
|
+
## 2022-03-11
|
26
|
+
* Project began
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jekyll_flexible_include (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
method_source (1.0.0)
|
13
|
+
parallel (1.21.0)
|
14
|
+
parser (3.1.1.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
pry (0.14.1)
|
17
|
+
coderay (~> 1.1)
|
18
|
+
method_source (~> 1.0)
|
19
|
+
rainbow (3.1.1)
|
20
|
+
rake (13.0.6)
|
21
|
+
regexp_parser (2.2.1)
|
22
|
+
rexml (3.2.5)
|
23
|
+
rspec (3.11.0)
|
24
|
+
rspec-core (~> 3.11.0)
|
25
|
+
rspec-expectations (~> 3.11.0)
|
26
|
+
rspec-mocks (~> 3.11.0)
|
27
|
+
rspec-core (3.11.0)
|
28
|
+
rspec-support (~> 3.11.0)
|
29
|
+
rspec-expectations (3.11.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.11.0)
|
32
|
+
rspec-mocks (3.11.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.11.0)
|
35
|
+
rspec-support (3.11.0)
|
36
|
+
rubocop (1.18.4)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.0.0.0)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml
|
42
|
+
rubocop-ast (>= 1.8.0, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.16.0)
|
46
|
+
parser (>= 3.1.1.0)
|
47
|
+
rubocop-jekyll (0.12.0)
|
48
|
+
rubocop (~> 1.18.0)
|
49
|
+
rubocop-performance (~> 1.2)
|
50
|
+
rubocop-performance (1.13.3)
|
51
|
+
rubocop (>= 1.7.0, < 2.0)
|
52
|
+
rubocop-ast (>= 0.4.0)
|
53
|
+
ruby-progressbar (1.11.0)
|
54
|
+
unicode-display_width (2.1.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
x86_64-linux
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bundler
|
61
|
+
jekyll_flexible_include!
|
62
|
+
pry
|
63
|
+
rake (~> 13.0)
|
64
|
+
rspec
|
65
|
+
rubocop
|
66
|
+
rubocop-jekyll
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.3.7
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tan Nhu, Maarten Brakkee
|
4
|
+
Copyright (c) 2022 Mike Slinn
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Jekyll `flexible_include` Plugin
|
2
|
+
|
3
|
+
`Flexible_include` is a Jekyll plugin that includes the contents of a file or the result of a process into a generated page. `Flexible_include` is useful because Jekyll's built-in `include` tag only supports the including of files residing within the `_includes/` subfolder of a Jekyll project, and because `flexible_include` offers additional ways of including content.
|
4
|
+
|
5
|
+
Originally called `include_absolute`, this plugin has been renamed to `flexible_include` because it no longer just includes absolute file names. This plugin supports 4 types of includes:
|
6
|
+
|
7
|
+
### Include Types
|
8
|
+
|
9
|
+
1. Absolute filenames (recognized by filename paths that start with `/`).
|
10
|
+
2. Filenames relative to the top-level directory of the Jekyll web site (relative paths **do not** start with `.` or `/`).
|
11
|
+
3. Filenames relative to the user home directory (recognized by filename paths starting with `~/`).
|
12
|
+
4. Executable filenames on the `PATH` (recognized by filename paths that begin with `!`).
|
13
|
+
|
14
|
+
|
15
|
+
In addition, filenames that require environment expansion because they contain a <code>$</code> character are
|
16
|
+
expanded according to the environment variables defined when <code>jekyll build</code> executes.
|
17
|
+
|
18
|
+
### Syntax:
|
19
|
+
```
|
20
|
+
{% flexible_include path [ do_not_escape='true' ] %}
|
21
|
+
```
|
22
|
+
|
23
|
+
The included file will escape characters <code><</code>, <code>{</code> and <code>}</code> unless <code>do_not_escape</code>
|
24
|
+
is specified with a value other than <code>false</code>.
|
25
|
+
Note that the [square brackets] merely indicate an optional parameter and are not intended to be literally written.
|
26
|
+
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add the following to `Gemfile`, inside the `jekyll_plugins` group:
|
31
|
+
```
|
32
|
+
group :jekyll_plugins do
|
33
|
+
gem 'jekyll_flexible_include', '~> 2.0.0'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Examples
|
38
|
+
|
39
|
+
1. Include files without parameters; all four types of includes are shown.
|
40
|
+
```
|
41
|
+
{% flexible_include '../../folder/outside/jekyll/site/foo.html' %}
|
42
|
+
{% flexible_include 'folder/within/jekyll/site/bar.js' %}
|
43
|
+
{% flexible_include '/etc/passwd' %}
|
44
|
+
{% flexible_include '~/.ssh/config' %}
|
45
|
+
{% flexible_include '!jekyll' %}
|
46
|
+
{% flexible_include '$HOME/.bash_aliases' %}
|
47
|
+
```
|
48
|
+
|
49
|
+
2. Include a JSON file (without escaping characters).
|
50
|
+
```
|
51
|
+
{% flexible_include '~/folder/under/home/directory/foo.html' do_not_escape='true' %}
|
52
|
+
```
|
53
|
+
|
54
|
+
## GitHub Pages
|
55
|
+
GitHub Pages only allows [these plugins](https://pages.github.com/versions/).
|
56
|
+
That means `flexible_include` will not work on GitHub Pages.
|
57
|
+
Following is a workaround.
|
58
|
+
1. Let's assume your git repository that you want to publish as GitHub Pages is called `mysite`.
|
59
|
+
This repository cannot be the source of your GitHub Pages because you are using the `flexible_include` plugin.
|
60
|
+
2. Make a new git repository to hold the generated website. Let's call this git repository `generated_site`.
|
61
|
+
3. Generate `mysite` locally as usual.
|
62
|
+
4. Copy the generated HTML in the `mysite/_site/` directory to `generated_site`.
|
63
|
+
5. Run `git commit` on `generated_site`.
|
64
|
+
6. Tell GitHub that you want the `generated_site` repository to hold your GitHub pages.
|
65
|
+
7. A moment later, your website will now be visible as GitHub Pages, with the included content, just as you saw it locally.
|
66
|
+
|
67
|
+
|
68
|
+
## Known Issues
|
69
|
+
If the plugin does not work:
|
70
|
+
1. Ensure `_config.yml` doesn't have `safe: true`. That prevents all plugins from working.
|
71
|
+
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork the project
|
76
|
+
2. Create a descriptively named feature branch
|
77
|
+
3. Add your feature
|
78
|
+
4. Submit a pull request
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
[MIT](./LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/flexible_include/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll_flexible_include"
|
7
|
+
spec.version = JekyllFlexibleIncludePlugin::VERSION
|
8
|
+
spec.authors = ["Mike Slinn"]
|
9
|
+
spec.email = ["mslinn@mslinn.com"]
|
10
|
+
|
11
|
+
spec.summary = "Jekyll plugin supports various ways to include content into the generated site."
|
12
|
+
spec.description = <<~END_OF_DESC
|
13
|
+
Jekyll's built-in include tag only supports including files within the _includes folder.
|
14
|
+
This plugin supports 4 types of includes:
|
15
|
+
|
16
|
+
- Absolute filenames (recognized by filename paths that start with /).
|
17
|
+
|
18
|
+
- Filenames relative to the top-level directory of the Jekyll web site (relative paths do not start with . or /).
|
19
|
+
|
20
|
+
- Filenames relative to the user home directory (recognized by filename paths starting with ~/).
|
21
|
+
|
22
|
+
- Executable filenames on the PATH (recognized by filename paths that begin with !).
|
23
|
+
END_OF_DESC
|
24
|
+
spec.homepage = "https://github.com/mslinn/jekyll_flexible_include_plugin"
|
25
|
+
spec.license = "MIT"
|
26
|
+
spec.required_ruby_version = ">= 2.6.0"
|
27
|
+
|
28
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
29
|
+
|
30
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
31
|
+
spec.metadata["source_code_uri"] = "https://github.com/mslinn/jekyll_flexible_include_plugin"
|
32
|
+
spec.metadata["changelog_uri"] = "https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md"
|
33
|
+
|
34
|
+
# Specify which files should be added to the gem when it is released.
|
35
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
36
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
37
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
38
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
spec.bindir = "exe"
|
42
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
43
|
+
spec.require_paths = ["lib"]
|
44
|
+
|
45
|
+
spec.add_development_dependency 'bundler'
|
46
|
+
spec.add_development_dependency 'pry'
|
47
|
+
spec.add_development_dependency 'rake'
|
48
|
+
spec.add_development_dependency 'rspec'
|
49
|
+
spec.add_development_dependency 'rubocop'
|
50
|
+
spec.add_development_dependency 'rubocop-jekyll'
|
51
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "flexible_include/version"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Tags
|
7
|
+
class FlexibleIncludeError < StandardError
|
8
|
+
attr_accessor :path
|
9
|
+
|
10
|
+
def initialize(msg, path)
|
11
|
+
super(msg)
|
12
|
+
@path = path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class FlexibleInclude < Liquid::Tag
|
17
|
+
VALID_SYNTAX = %r!
|
18
|
+
([\w-]+)\s*=\s*
|
19
|
+
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))
|
20
|
+
!x
|
21
|
+
VARIABLE_SYNTAX = %r!
|
22
|
+
(?<variable>[^{]*(\{\{\s*[\w\-\.]+\s*(\|.*)?\}\}[^\s{}]*)+)
|
23
|
+
(?<params>.*)
|
24
|
+
!mx
|
25
|
+
|
26
|
+
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!
|
27
|
+
VALID_FILENAME_CHARS = %r!^[\w/\.-]+$!
|
28
|
+
|
29
|
+
def initialize(tag_name, markup, tokens)
|
30
|
+
super
|
31
|
+
matched = markup.strip.match(VARIABLE_SYNTAX)
|
32
|
+
if matched
|
33
|
+
@file = matched["variable"].strip
|
34
|
+
@params = matched["params"].strip
|
35
|
+
else
|
36
|
+
@file, @params = markup.strip.split(%r!\s+!, 2)
|
37
|
+
end
|
38
|
+
validate_params if @params
|
39
|
+
@tag_name = tag_name
|
40
|
+
end
|
41
|
+
|
42
|
+
def syntax_example
|
43
|
+
"{% #{@tag_name} 'file.ext' optional_param_1='value' optional_param_n='value' %}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_params(context)
|
47
|
+
params = {}
|
48
|
+
markup = @params
|
49
|
+
|
50
|
+
while (match = VALID_SYNTAX.match(markup))
|
51
|
+
markup = markup[match.end(0)..-1]
|
52
|
+
|
53
|
+
value = if match[2]
|
54
|
+
match[2].gsub(%r!\\"!, '"')
|
55
|
+
elsif match[3]
|
56
|
+
match[3].gsub(%r!\\'!, "'")
|
57
|
+
elsif match[4]
|
58
|
+
context[match[4]]
|
59
|
+
end
|
60
|
+
|
61
|
+
params[match[1]] = value
|
62
|
+
end
|
63
|
+
params
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_file_name(file)
|
67
|
+
# TODO allow filenames relative to home directory
|
68
|
+
if file.match VALID_FILENAME_CHARS
|
69
|
+
raise ArgumentError, <<~MSG
|
70
|
+
Invalid syntax for the flexible_ include tag. The included file contains invalid characters or sequences:
|
71
|
+
|
72
|
+
#{file}
|
73
|
+
|
74
|
+
Valid syntax:
|
75
|
+
|
76
|
+
#{syntax_example}
|
77
|
+
|
78
|
+
MSG
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def validate_params
|
83
|
+
unless @params.match FULL_VALID_SYNTAX
|
84
|
+
raise ArgumentError, <<~MSG
|
85
|
+
Invalid syntax for the flexible_include tag:
|
86
|
+
|
87
|
+
#{@params}
|
88
|
+
|
89
|
+
Valid syntax:
|
90
|
+
|
91
|
+
#{syntax_example}
|
92
|
+
|
93
|
+
MSG
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Grab file read opts in the context
|
98
|
+
def file_read_opts(context)
|
99
|
+
context.registers[:site].file_read_opts
|
100
|
+
end
|
101
|
+
|
102
|
+
# Render the variable if required
|
103
|
+
def render_variable(context)
|
104
|
+
if @file.match VARIABLE_SYNTAX
|
105
|
+
partial = context.registers[:site]
|
106
|
+
.liquid_renderer
|
107
|
+
.file("(variable)")
|
108
|
+
.parse(@file)
|
109
|
+
partial.render!(context)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def render(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
114
|
+
file = render_variable(context) || @file
|
115
|
+
# strip leading and trailing quotes
|
116
|
+
file = file.gsub!(/\A'|'\Z/, '')
|
117
|
+
# validate_file_name(file) # TODO uncomment and fix validate_file_name
|
118
|
+
path = file
|
119
|
+
if /^\//.match(file) # Is the file absolute?
|
120
|
+
# puts "********** render path=#{path}, file=#{file} *************"
|
121
|
+
elsif /~/.match(file) # Is the file relative to user's home directory?
|
122
|
+
# puts "********** render original file=#{file}, path=#{path} *************"
|
123
|
+
file.slice! "~/"
|
124
|
+
path = File.join(ENV['HOME'], file)
|
125
|
+
# puts "********** render path=#{path}, file=#{file} *************"
|
126
|
+
elsif /\!/.match(file) # Is the file on the PATH?
|
127
|
+
# puts "********** render original file=#{file}, path=#{path} *************"
|
128
|
+
file.slice! "!"
|
129
|
+
path = File.which(file)
|
130
|
+
# puts "********** render path=#{path}, file=#{file} *************"
|
131
|
+
else # The file is relative
|
132
|
+
source = File.expand_path(context.registers[:site].config['source']).freeze # website root directory
|
133
|
+
path = File.join(source, file) # Fully qualified path of include file
|
134
|
+
# puts "********** render file=#{file}, path=#{path}, source=#{source} *************"
|
135
|
+
end
|
136
|
+
return unless path
|
137
|
+
|
138
|
+
begin
|
139
|
+
escaped_contents = read_file(path, context).gsub("{", "{").gsub("}", "}").gsub("<", "<")
|
140
|
+
# puts escaped_contents
|
141
|
+
partial = Liquid::Template.parse(escaped_contents)
|
142
|
+
rescue StandardError => e
|
143
|
+
abort "flexible_include.rb: #{e.message}"
|
144
|
+
end
|
145
|
+
|
146
|
+
context.stack do
|
147
|
+
context["include"] = parse_params(context) if @params
|
148
|
+
begin
|
149
|
+
partial.render!(context)
|
150
|
+
rescue Liquid::Error => e
|
151
|
+
e.template_name = path
|
152
|
+
e.markup_context = "included " if e.markup_context.nil?
|
153
|
+
raise e
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def valid_include_file?(path, dir, safe)
|
159
|
+
!outside_site_source?(path, dir, safe) && File.file?(path)
|
160
|
+
end
|
161
|
+
|
162
|
+
def outside_site_source?(path, dir, safe)
|
163
|
+
safe && !realpath_prefixed_with?(path, dir)
|
164
|
+
end
|
165
|
+
|
166
|
+
def realpath_prefixed_with?(path, dir)
|
167
|
+
File.exist?(path) && File.realpath(path).start_with?(dir)
|
168
|
+
rescue StandardError
|
169
|
+
false
|
170
|
+
end
|
171
|
+
|
172
|
+
# This method allows to modify the file content by inheriting from the class.
|
173
|
+
def read_file(file, context)
|
174
|
+
File.read(file, **file_read_opts(context))
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def could_not_locate_message(file, includes_dirs, safe)
|
180
|
+
message = "Could not locate the included file '#{file}' in any of "\
|
181
|
+
"#{includes_dirs}. Ensure it exists in one of those directories and"
|
182
|
+
message + if safe
|
183
|
+
" is not a symlink as those are not allowed in safe mode."
|
184
|
+
else
|
185
|
+
", if it is a symlink, does not point outside your site source."
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
Liquid::Template.register_tag("flexible_include", Jekyll::Tags::FlexibleInclude)
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_flexible_include
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Slinn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-jekyll
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: |
|
98
|
+
Jekyll's built-in include tag only supports including files within the _includes folder.
|
99
|
+
This plugin supports 4 types of includes:
|
100
|
+
|
101
|
+
- Absolute filenames (recognized by filename paths that start with /).
|
102
|
+
|
103
|
+
- Filenames relative to the top-level directory of the Jekyll web site (relative paths do not start with . or /).
|
104
|
+
|
105
|
+
- Filenames relative to the user home directory (recognized by filename paths starting with ~/).
|
106
|
+
|
107
|
+
- Executable filenames on the PATH (recognized by filename paths that begin with !).
|
108
|
+
email:
|
109
|
+
- mslinn@mslinn.com
|
110
|
+
executables: []
|
111
|
+
extensions: []
|
112
|
+
extra_rdoc_files: []
|
113
|
+
files:
|
114
|
+
- ".editorconfig"
|
115
|
+
- ".rubocop.yml"
|
116
|
+
- CHANGELOG.md
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- jekyll_flexible_include_plugin.gemspec
|
123
|
+
- lib/flexible_include.rb
|
124
|
+
- lib/flexible_include/version.rb
|
125
|
+
- sig/jekyll_flexible_include_plugin.rbs
|
126
|
+
homepage: https://github.com/mslinn/jekyll_flexible_include_plugin
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata:
|
130
|
+
allowed_push_host: https://rubygems.org/
|
131
|
+
homepage_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
|
132
|
+
source_code_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
|
133
|
+
changelog_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 2.6.0
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubygems_version: 3.2.5
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Jekyll plugin supports various ways to include content into the generated
|
153
|
+
site.
|
154
|
+
test_files: []
|