jekyll_flexible_include 2.0.2 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45d4ee5a84b021c967aaafa2e1894537041e4770c0604a76f02d8d9e03fc3c9e
4
- data.tar.gz: 9f6337ca74f362b8a3870eb347f988ebc21ceaf73e3073c4bdd42c0bd2818cde
3
+ metadata.gz: 7728aa7304d9fef053bb7b6f0e5adb59938a13711764f5ec1615497d54e23845
4
+ data.tar.gz: 1ef45a4764e136856e80e9a874cfa6e30ac1a9bc2523a10a024fa79bafc1b3d5
5
5
  SHA512:
6
- metadata.gz: 5dbdeef00337d13e4a2db94c80e25a324e2bf731886ead64678b3e579a2fb2b568fa9b3c2e68cafa00e21a2bc72fe47d2463e0f046df58f96285f76de0cc78e0
7
- data.tar.gz: dae0c2b23c91458111599ee0db43dad4dc863dc14f6d52ba48e919bff0132d3b3eae160f748fffa7aabe5f82a82f0702113fad71bc6c7a2c16d2ad5f0f8a8180
6
+ metadata.gz: 33c164b768d259e680458b14fab226d7fe038685a8dc98b459140a812628c8e9978e200e1ea3da414be678ebaca5f73e3b42957f26879162d6ce9c874f5346d2
7
+ data.tar.gz: 43b56da5e19d31a4aa51c87ba21d284c57f1f242a2f25f16bf71d3524ad620df09ba98faf18b234992073ddb2b09fbe89a912a6a15877d9ce1b71608eaa6ea33
data/.rubocop.yml CHANGED
@@ -9,6 +9,9 @@ AllCops:
9
9
  NewCops: enable
10
10
  TargetRubyVersion: 2.6
11
11
 
12
+ # Gemspec/RequireMFA:
13
+ # Enabled: false
14
+
12
15
  Layout/LineLength:
13
16
  Max: 150
14
17
 
@@ -18,6 +21,9 @@ Layout/MultilineMethodCallIndentation:
18
21
  Metrics/BlockLength:
19
22
  Enabled: false
20
23
 
24
+ Style/CommandLiteral:
25
+ Enabled: false
26
+
21
27
  Style/PercentLiteralDelimiters:
22
28
  Enabled: false
23
29
 
data/CHANGELOG.md CHANGED
@@ -1,14 +1,19 @@
1
- ## 2.0.2 / 2022-03-11
2
- * This version should actually work, crossing fingers
1
+ ## 2.0.5 / 2022-04-11
2
+ * Now using <code>Shellwords</code> and <code>KeyValueParser</code> instead of a homegrown parser.
3
+ * Refactored helper methods to jekyll_tag_helper.rb
4
+ * Looks up values for liquid variable references from several scopes.
5
+ * Suppresses stack dump when an error occurs.
6
+ * Deleted a lot of old cruft.
7
+ * Added pre, label and copy_button optional parameters
8
+
9
+ ## 2.0.4 / 2022-04-05
10
+ * Updated to `jekyll_plugin_logger` v2.1.0
3
11
 
4
- ## 2.0.1 / 2022-03-11
5
- * Struggling with poorly documented gem naming conventions, this release is broken, do not use
6
12
  ## 2.0.0 / 2022-03-11
7
13
  * Made into a Ruby gem and published on RubyGems.org as [jekyll_flexible_include](https://rubygems.org/gems/jekyll_flexible_include).
8
14
  * `bin/attach` script added for debugging
9
15
  * Rubocop standards added
10
16
  * Proper versioning and CHANGELOG.md added
11
- * This release is broken, do not use
12
17
 
13
18
  ## 1.1.1 / 2021-05-01
14
19
  * Handles spaces in filenames properly.
data/README.md CHANGED
@@ -4,7 +4,12 @@ Jekyll `flexible_include` Plugin
4
4
 
5
5
  `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.
6
6
 
7
- 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:
7
+ Originally called `include_absolute`, this plugin has been renamed to `flexible_include` because it no longer just includes absolute file names.
8
+
9
+ This plugin is available as a [Ruby gem](https://rubygems.org/gems/jekyll_flexible_include).
10
+ More information is available on my website about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
11
+
12
+ This plugin supports 4 types of includes:
8
13
 
9
14
  ### Include Types
10
15
 
@@ -17,14 +22,31 @@ Originally called `include_absolute`, this plugin has been renamed to `flexible
17
22
  In addition, filenames that require environment expansion because they contain a <code>$</code> character are
18
23
  expanded according to the environment variables defined when <code>jekyll build</code> executes.
19
24
 
20
- ### Syntax:
25
+ ### Syntax
26
+ The following are equivalent:
21
27
  ```
22
- {% flexible_include path [ do_not_escape='true' ] %}
28
+ {% flexible_include path [ OPTIONS ] %}
29
+ {% flexible_include 'path' [ OPTIONS ] %}
30
+ {% flexible_include "path" [ OPTIONS ] %}
23
31
  ```
24
32
 
25
- The included file will escape characters <code>&lt;</code>, <code>{</code> and <code>}</code> unless <code>do_not_escape</code>
26
- is specified with a value other than <code>false</code>.
27
- Note that the [square brackets] merely indicate an optional parameter and are not intended to be literally written.
33
+ By default, the included file will escape characters <code>&lt;</code>, <code>{</code> and <code>}</code>
34
+ unless <code>do_not_escape</code> is specified.
35
+ Note that the [square brackets] merely indicate optional parameters and are not intended to be written literally.
36
+
37
+ ### Options
38
+ * `do_not_escape` includes the content without HTML escaping it.
39
+ * `pre` causes the included file to be wrapped inside a &lt;pre>&lt;/pre> tag, no label is generated.
40
+
41
+ The following options imply `pre`:
42
+ * `download` uses the name of the file as a label, and displays it above the &lt;pre>&lt;/pre> tag. Clicking the label causes the file to be downloaded.
43
+ * `copy_button` draws an icon at the top right of the &lt;pre>&lt;/pre> tag that causes the included contents to be copied to the clipboard.
44
+ * `label` specifies that an automatically generated label be placed above the contents. There is no need to specify this option if `download` or `copy_button` options are provided.
45
+ * `label="blah blah"` specifies a label for the contents; this value overrides the default label. The value can be enclosed in single or double quotes.
46
+
47
+
48
+ ### Additional Information
49
+ More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
28
50
 
29
51
 
30
52
  ## Installation
@@ -36,9 +58,24 @@ group :jekyll_plugins do
36
58
  end
37
59
  ```
38
60
 
61
+ Also add it to `_config.yml`:
62
+ ```yaml
63
+ plugins:
64
+ - flexible_include
65
+ ```
66
+
67
+ And then execute:
68
+
69
+ $ bundle install
70
+
71
+ Or install it yourself as:
72
+
73
+ $ gem install jekyll_flexible_include
74
+
75
+
39
76
  ## Examples
40
77
 
41
- 1. Include files without parameters; all four types of includes are shown.
78
+ 1. Include files, escaping any HTML markup so it appears as written; all four types of includes are shown.
42
79
  ```
43
80
  {% flexible_include '../../folder/outside/jekyll/site/foo.html' %}
44
81
  {% flexible_include 'folder/within/jekyll/site/bar.js' %}
@@ -50,9 +87,14 @@ end
50
87
 
51
88
  2. Include a JSON file (without escaping characters).
52
89
  ```
53
- {% flexible_include '~/folder/under/home/directory/foo.html' do_not_escape='true' %}
90
+ {% flexible_include '~/folder/under/home/directory/foo.html' do_not_escape %}
54
91
  ```
55
92
 
93
+ ## Additional Information
94
+ More information is available on
95
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
96
+
97
+
56
98
  ## GitHub Pages
57
99
  GitHub Pages only allows [these plugins](https://pages.github.com/versions/).
58
100
  That means `flexible_include` will not work on GitHub Pages.
@@ -75,9 +117,48 @@ If the plugin does not work:
75
117
 
76
118
  ## Development
77
119
 
78
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
120
+ After checking out the repo, run `bin/setup` to install dependencies.
121
+
122
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
123
+
124
+ ### Build and Install Locally
125
+ To build and install this gem onto your local machine, run:
126
+ ```shell
127
+ $ rake install:local
128
+ ```
129
+
130
+ The following also does the same thing:
131
+ ```shell
132
+ $ bundle exec rake install
133
+ ```
134
+
135
+ Examine the newly built gem:
136
+ ```shell
137
+ $ gem info jekyll_flexible_include
138
+
139
+ *** LOCAL GEMS ***
140
+
141
+ jekyll_flexible_include (2.0.4)
142
+ Authors: Mike Slinn, Tan Nhu, Maarten Brakkee
143
+ Homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude
144
+ License: MIT
145
+ Installed at (2.0.4): /home/mslinn/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0
146
+
147
+ Jekyll plugin supports various ways to include content into the
148
+ generated site.
149
+ ```
150
+
79
151
 
80
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
152
+ ### Build and Push to RubyGems
153
+ To release a new version,
154
+ 1. Update the version number in `version.rb`.
155
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
156
+ 3. Run the following:
157
+ ```shell
158
+ $ bundle exec rake release
159
+ ```
160
+ The above creates a git tag for the version, commits the created tag,
161
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
81
162
 
82
163
 
83
164
  ## Contributing
@@ -89,4 +170,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
89
170
 
90
171
  ## License
91
172
 
92
- [MIT](./LICENSE)
173
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/flexible_include/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ github = "https://github.com/mslinn/jekyll_flexible_include_plugin"
7
+
8
+ spec.authors = ["Mike Slinn", "Tan Nhu", "Maarten Brakkee"]
9
+ spec.bindir = "exe"
10
+ spec.description = <<~END_OF_DESC
11
+ Jekyll's built-in include tag only supports including files within the _includes folder.
12
+ This plugin supports 4 types of includes: absolute filenames,
13
+ filenames relative to the top-level directory of the Jekyll web site,
14
+ filenames relative to the user home directory,
15
+ and executable filenames on the PATH.
16
+ END_OF_DESC
17
+ spec.email = ["mslinn@mslinn.com"]
18
+ spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
19
+ spec.homepage = "https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude"
20
+ spec.license = "MIT"
21
+ spec.metadata = {
22
+ "allowed_push_host" => "https://rubygems.org",
23
+ "bug_tracker_uri" => "#{github}/issues",
24
+ "changelog_uri" => "#{github}/CHANGELOG.md",
25
+ "homepage_uri" => spec.homepage,
26
+ "source_code_uri" => github,
27
+ }
28
+ spec.name = "jekyll_flexible_include"
29
+ spec.post_install_message = <<~END_MESSAGE
30
+
31
+ Thanks for installing #{spec.name}!
32
+
33
+ END_MESSAGE
34
+ spec.require_paths = ["lib"]
35
+ spec.required_ruby_version = ">= 2.6.0"
36
+ spec.summary = "Jekyll plugin supports various ways to include content into the generated site."
37
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
38
+ spec.version = JekyllFlexibleIncludePluginVersion::VERSION
39
+
40
+ spec.add_dependency "jekyll", ">= 3.5.0"
41
+ spec.add_dependency "jekyll_plugin_logger", '~> 2.1.0'
42
+
43
+ spec.add_development_dependency "debase"
44
+ # spec.add_development_dependency "rubocop-jekyll"
45
+ # spec.add_development_dependency "rubocop-rake"
46
+ # spec.add_development_dependency "rubocop-rspec"
47
+ spec.add_development_dependency "ruby-debug-ide"
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllFlexibleIncludePluginVersion
4
+ VERSION = "2.0.5"
5
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "jekyll_plugin_logger"
5
+ require "securerandom"
6
+ require_relative "flexible_include/version"
7
+ require_relative "jekyll_tag_helper"
8
+
9
+ module JekyllFlexibleIncludeName
10
+ PLUGIN_NAME = "flexible_include"
11
+ end
12
+
13
+ class FlexibleInclude < Liquid::Tag
14
+ FlexibleIncludeError = Class.new(Liquid::Error)
15
+
16
+ # @param tag_name [String] the name of the tag, which we already know.
17
+ # @param markup [String] the arguments from the tag, as a single string.
18
+ # @param parse_context [Liquid::ParseContext] hash that stores Liquid options.
19
+ # By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
20
+ # a boolean parameter that determines if error messages should display the line number the error occurred.
21
+ # This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
22
+ # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
23
+ def initialize(tag_name, markup, _parse_context)
24
+ super
25
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
26
+ @helper = JekyllTagHelper.new(tag_name, markup, @logger)
27
+ end
28
+
29
+ # @param liquid_context [Liquid::Context]
30
+ def render(liquid_context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
31
+ @helper.liquid_context = liquid_context
32
+ @do_not_escape = @helper.parameter_specified? "do_not_escape"
33
+ @download = @helper.parameter_specified? "download"
34
+ @label = @helper.parameter_specified? "label"
35
+ @label_specified = @label
36
+ @copy_button = @helper.parameter_specified? "copyButton"
37
+ @pre = @copy_button || @download || @label_specified || @helper.parameter_specified?("pre") # Download or label implies pre
38
+ filename = @helper.params.first # Do this after all options have been checked for
39
+ @label ||= filename
40
+
41
+ # If a label was specified, use it, otherwise concatenate any dangling parameters and use that as the label
42
+ @label ||= @helper.params[1..].join(" ")
43
+
44
+ @logger.debug("filename=#{filename}")
45
+
46
+ path = JekyllTagHelper.expand_env(filename)
47
+ case path
48
+ when /\A\// # Absolute path
49
+ @logger.debug { "Absolute path=#{path}, filename=#{filename}" }
50
+ when /\A~/ # Relative path to user's home directory
51
+ @logger.debug { "User home start filename=#{filename}, path=#{path}" }
52
+ filename.slice! "~/"
53
+ path = File.join(ENV['HOME'], filename)
54
+ @logger.debug { "User home end filename=#{filename}, path=#{path}" }
55
+ when /\A!/ # Run command and return response
56
+ filename = JekyllTagHelper.remove_quotes(@helper.argv.first)
57
+ filename.slice! "!"
58
+ contents = run(filename)
59
+ else # Relative path
60
+ site = liquid_context.registers[:site]
61
+ source = File.expand_path(site.config['source']) # website root directory
62
+ path = File.join(source, filename) # Fully qualified path of include file from relative path
63
+ @relative = true
64
+ @logger.debug { "Relative end filename=#{filename}, path=#{path}" }
65
+ end
66
+ render_completion(path, contents)
67
+ # rescue StandardError => e
68
+ # raise FlexibleIncludeError, e.message.red, [] # Suppress stack trace
69
+ end
70
+
71
+ private
72
+
73
+ def read_file(file)
74
+ File.read(file)
75
+ end
76
+
77
+ def realpath_prefixed_with?(path, dir)
78
+ File.exist?(path) && File.realpath(path).start_with?(dir)
79
+ rescue StandardError
80
+ false
81
+ end
82
+
83
+ def render_completion(path, contents)
84
+ contents ||= read_file(path)
85
+ contents2 = @do_not_escape ? contents : JekyllTagHelper.escape_html(contents)
86
+ @pre ? wrap_in_pre(path, contents2) : contents2
87
+ end
88
+
89
+ def run(cmd)
90
+ @logger.debug { "Executing filename=#{cmd}" }
91
+ %x[#{cmd}].chomp
92
+ end
93
+
94
+ PREFIX = "<button class='copyBtn' data-clipboard-target="
95
+ SUFFIX = "title='Copy to clipboard'><img src='/assets/images/clippy.svg' alt='Copy to clipboard' style='width: 13px'></button>"
96
+
97
+ def wrap_in_pre(path, content)
98
+ basename = File.basename(path)
99
+ label_or_href = if @download
100
+ label = @label_specified ? @label : basename
101
+ <<~END_HREF
102
+ <a href='data:text/plain;charset=UTF-8,#{basename}' download='#{basename}'
103
+ title='Click on the file name to download the file'>#{label}</a>
104
+ END_HREF
105
+ else
106
+ @label_specified ? @label : basename
107
+ end
108
+ pre_id = "id#{SecureRandom.hex 6}"
109
+ copy_button = @copy_button ? "#{PREFIX}'##{pre_id}'#{SUFFIX}" : ""
110
+ <<~END_PRE
111
+ <div class="codeLabel">#{label_or_href}</div>
112
+ <pre data-lt-active="false" class="maxOneScreenHigh copyContainer" id="#{pre_id}">#{copy_button}#{content}</pre>
113
+ END_PRE
114
+ end
115
+ end
116
+
117
+ PluginMetaLogger.instance.info { "Loaded #{JekyllFlexibleIncludeName::PLUGIN_NAME} v#{JekyllFlexibleIncludePluginVersion::VERSION} plugin." }
118
+ Liquid::Template.register_tag('flexible_include', FlexibleInclude)
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+
5
+ class JekyllTagHelper
6
+ attr_reader :argv, :liquid_context, :logger, :params, :tag_name
7
+
8
+ def self.escape_html(string)
9
+ string.gsub("{", "&#123;").gsub("}", "&#125;").gsub("<", "&lt;")
10
+ end
11
+
12
+ # Expand environment variable references
13
+ def self.expand_env(str)
14
+ str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) { ENV[Regexp.last_match(1)] }
15
+ end
16
+
17
+ # strip leading and trailing quotes if present
18
+ def self.remove_quotes(string)
19
+ string.strip.gsub(/\A'|\A"|'\Z|"\Z/, '').strip if string
20
+ end
21
+
22
+ def initialize(tag_name, markup, logger)
23
+ @tag_name = tag_name
24
+ @argv = Shellwords.split(markup)
25
+ @keys_values = KeyValueParser.new.parse(@argv) # Hash[Symbol, String|Boolean]
26
+ @logger = logger
27
+ @logger.debug { "@keys_values='#{@keys_values}'" }
28
+ end
29
+
30
+ def delete_parameter(name)
31
+ @params.delete(name)
32
+ @argv.delete_if { |x| x.start_with? name }
33
+ @keys_values.delete(name.to_sym)
34
+ end
35
+
36
+ # @return if parameter was specified, returns value and removes it from the available tokens
37
+ def parameter_specified?(name)
38
+ value = @keys_values[name.to_sym]
39
+ delete_parameter(name)
40
+ value
41
+ end
42
+
43
+ PREDEFINED_SCOPE_KEYS = [:include, :page].freeze
44
+
45
+ # Finds variables defined in an invoking include, or maybe somewhere else
46
+ # @return variable value or nil
47
+ def dereference_include_variable(name)
48
+ @liquid_context.scopes.each do |scope|
49
+ next if PREDEFINED_SCOPE_KEYS.include? scope.keys.first
50
+
51
+ value = scope[name]
52
+ return value if value
53
+ end
54
+ nil
55
+ end
56
+
57
+ # @return value of variable, or the empty string
58
+ def dereference_variable(name)
59
+ @liquid_context[name] || # Finds variables named like 'include.my_variable', found in @liquid_context.scopes.first
60
+ @page[name] || # Finds variables named like 'page.my_variable'
61
+ dereference_include_variable(name) ||
62
+ ""
63
+ end
64
+
65
+ # Sets @params by replacing any Liquid variable names with their values
66
+ def liquid_context=(context)
67
+ @liquid_context = context
68
+ @params = @keys_values.map { |k, _v| lookup_variable(k) }
69
+ end
70
+
71
+ def lookup_variable(symbol)
72
+ string = symbol.to_s
73
+ return string unless string.start_with?("{{") && string.end_with?("}}")
74
+
75
+ dereference_variable(string.delete_prefix("{{").delete_suffix("}}"))
76
+ end
77
+
78
+ def page
79
+ @liquid_context.registers[:page]
80
+ end
81
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_flexible_include
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
+ - Tan Nhu
9
+ - Maarten Brakkee
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2022-03-13 00:00:00.000000000 Z
13
+ date: 2022-04-13 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: jekyll
@@ -25,19 +27,19 @@ dependencies:
25
27
  - !ruby/object:Gem::Version
26
28
  version: 3.5.0
27
29
  - !ruby/object:Gem::Dependency
28
- name: bundler
30
+ name: jekyll_plugin_logger
29
31
  requirement: !ruby/object:Gem::Requirement
30
32
  requirements:
31
- - - ">="
33
+ - - "~>"
32
34
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
+ version: 2.1.0
36
+ type: :runtime
35
37
  prerelease: false
36
38
  version_requirements: !ruby/object:Gem::Requirement
37
39
  requirements:
38
- - - ">="
40
+ - - "~>"
39
41
  - !ruby/object:Gem::Version
40
- version: '0'
42
+ version: 2.1.0
41
43
  - !ruby/object:Gem::Dependency
42
44
  name: debase
43
45
  requirement: !ruby/object:Gem::Requirement
@@ -52,104 +54,6 @@ dependencies:
52
54
  - - ">="
53
55
  - !ruby/object:Gem::Version
54
56
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: jekyll
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: pry
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: rake
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
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-jekyll
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop-rake
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
57
  - !ruby/object:Gem::Dependency
154
58
  name: ruby-debug-ide
155
59
  requirement: !ruby/object:Gem::Requirement
@@ -170,34 +74,33 @@ description: |
170
74
  filenames relative to the top-level directory of the Jekyll web site,
171
75
  filenames relative to the user home directory,
172
76
  and executable filenames on the PATH.
173
- email: mslinn@mslinn.com
77
+ email:
78
+ - mslinn@mslinn.com
174
79
  executables: []
175
80
  extensions: []
176
81
  extra_rdoc_files: []
177
82
  files:
178
- - ".editorconfig"
179
83
  - ".rubocop.yml"
180
- - ".vscode/launch.json"
181
- - ".vscode/settings.json"
182
84
  - CHANGELOG.md
183
- - Gemfile
184
- - Gemfile.lock
185
- - LICENSE
186
85
  - README.md
187
86
  - Rakefile
188
- - jekyll_flexible_include.gemspec
189
- - lib/jekyll_flexible_include.rb
190
- - lib/jekyll_flexible_include/version.rb
191
- - sig/jekyll_flexible_include.rbs
192
- homepage: https://github.com/mslinn/jekyll_flexible_include_plugin
87
+ - jekyll_flexible_include_plugin.gemspec
88
+ - lib/flexible_include.rb
89
+ - lib/flexible_include/version.rb
90
+ - lib/jekyll_tag_helper.rb
91
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude
193
92
  licenses:
194
93
  - MIT
195
94
  metadata:
196
- allowed_push_host: https://rubygems.org/
197
- homepage_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
198
- source_code_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
95
+ allowed_push_host: https://rubygems.org
96
+ bug_tracker_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/issues
199
97
  changelog_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md
200
- post_install_message: Thanks for installing jekyll_flexible_include!
98
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude
99
+ source_code_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
100
+ post_install_message: |2+
101
+
102
+ Thanks for installing jekyll_flexible_include!
103
+
201
104
  rdoc_options: []
202
105
  require_paths:
203
106
  - lib
@@ -212,9 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
115
  - !ruby/object:Gem::Version
213
116
  version: '0'
214
117
  requirements: []
215
- rubygems_version: 3.2.5
118
+ rubygems_version: 3.1.4
216
119
  signing_key:
217
120
  specification_version: 4
218
- summary: This Jekyll plugin supports various ways to include content into the generated
121
+ summary: Jekyll plugin supports various ways to include content into the generated
219
122
  site.
220
123
  test_files: []
data/.editorconfig DELETED
@@ -1,39 +0,0 @@
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/.vscode/launch.json DELETED
@@ -1,75 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "cwd": "${workspaceRoot}",
9
- "name": "Attach rdebug-ide",
10
- "request": "attach",
11
- "remoteHost": "localhost",
12
- "remotePort": "1234",
13
- "remoteWorkspaceRoot": "/",
14
- "restart": true,
15
- "showDebuggerOutput": true,
16
- "type": "Ruby",
17
- },
18
- {
19
- "cwd": "${workspaceRoot}",
20
- "debuggerPort": "1234",
21
- "name": "Debug Jekyll",
22
- "program": "/usr/local/bin/jekyll",
23
- "args": [
24
- "serve",
25
- "--livereload_port", "35721",
26
- "--force_polling",
27
- "--host", "0.0.0.0",
28
- "--port", "4001",
29
- "--future",
30
- "--incremental",
31
- "--livereload",
32
- "--drafts",
33
- "--unpublished"
34
- ],
35
- "request": "launch",
36
- "restart": true,
37
- "showDebuggerOutput": true,
38
- "stopOnEntry": true,
39
- "type": "Ruby",
40
- },
41
- {
42
- "name": "Debug Local Ruby",
43
- "type": "Ruby",
44
- "request": "launch",
45
- "program": "${workspaceRoot}/main.rb"
46
- },
47
- {
48
- "args": [
49
- "-I",
50
- "${workspaceRoot}",
51
- "${file}"
52
- ],
53
- "cwd": "${workspaceRoot}",
54
- "name": "RSpec - active spec file only",
55
- "program": "/home/mslinn/.gems/bin/rspec",
56
- "showDebuggerOutput": false,
57
- "request": "launch",
58
- "type": "Ruby",
59
- "useBundler": true,
60
- },
61
- {
62
- "args": [
63
- "-I",
64
- "${workspaceRoot}"
65
- ],
66
- "cwd": "${workspaceRoot}",
67
- "name": "RSpec - all",
68
- "program": "/home/mslinn/.gems/bin/rspec",
69
- "request": "launch",
70
- "showDebuggerOutput": false,
71
- "type": "Ruby",
72
- "useBundler": true,
73
- }
74
- ]
75
- }
@@ -1,4 +0,0 @@
1
- {
2
- "ruby.rubocop.configFilePath": ".rubocop.yml",
3
- "ruby.rubocop.useBundler": true
4
- }
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in jekyll_flexible_include.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
data/Gemfile.lock DELETED
@@ -1,131 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll_flexible_include (2.0.2)
5
- jekyll (>= 3.5.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.8.0)
11
- public_suffix (>= 2.0.2, < 5.0)
12
- ast (2.4.2)
13
- coderay (1.1.3)
14
- colorator (1.1.0)
15
- concurrent-ruby (1.1.9)
16
- debase (0.2.4.1)
17
- debase-ruby_core_source (>= 0.10.2)
18
- debase-ruby_core_source (0.10.14)
19
- diff-lcs (1.5.0)
20
- em-websocket (0.5.3)
21
- eventmachine (>= 0.12.9)
22
- http_parser.rb (~> 0)
23
- eventmachine (1.2.7)
24
- ffi (1.15.5)
25
- forwardable-extended (2.6.0)
26
- http_parser.rb (0.8.0)
27
- i18n (0.9.5)
28
- concurrent-ruby (~> 1.0)
29
- jekyll (3.9.1)
30
- addressable (~> 2.4)
31
- colorator (~> 1.0)
32
- em-websocket (~> 0.5)
33
- i18n (~> 0.7)
34
- jekyll-sass-converter (~> 1.0)
35
- jekyll-watch (~> 2.0)
36
- kramdown (>= 1.17, < 3)
37
- liquid (~> 4.0)
38
- mercenary (~> 0.3.3)
39
- pathutil (~> 0.9)
40
- rouge (>= 1.7, < 4)
41
- safe_yaml (~> 1.0)
42
- jekyll-sass-converter (1.5.2)
43
- sass (~> 3.4)
44
- jekyll-watch (2.2.1)
45
- listen (~> 3.0)
46
- kramdown (2.3.1)
47
- rexml
48
- liquid (4.0.3)
49
- listen (3.7.1)
50
- rb-fsevent (~> 0.10, >= 0.10.3)
51
- rb-inotify (~> 0.9, >= 0.9.10)
52
- mercenary (0.3.6)
53
- method_source (1.0.0)
54
- parallel (1.21.0)
55
- parser (3.1.1.0)
56
- ast (~> 2.4.1)
57
- pathutil (0.16.2)
58
- forwardable-extended (~> 2.6)
59
- pry (0.14.1)
60
- coderay (~> 1.1)
61
- method_source (~> 1.0)
62
- public_suffix (4.0.6)
63
- rainbow (3.1.1)
64
- rake (13.0.6)
65
- rb-fsevent (0.11.1)
66
- rb-inotify (0.10.1)
67
- ffi (~> 1.0)
68
- regexp_parser (2.2.1)
69
- rexml (3.2.5)
70
- rouge (3.28.0)
71
- rspec (3.11.0)
72
- rspec-core (~> 3.11.0)
73
- rspec-expectations (~> 3.11.0)
74
- rspec-mocks (~> 3.11.0)
75
- rspec-core (3.11.0)
76
- rspec-support (~> 3.11.0)
77
- rspec-expectations (3.11.0)
78
- diff-lcs (>= 1.2.0, < 2.0)
79
- rspec-support (~> 3.11.0)
80
- rspec-mocks (3.11.0)
81
- diff-lcs (>= 1.2.0, < 2.0)
82
- rspec-support (~> 3.11.0)
83
- rspec-support (3.11.0)
84
- rubocop (1.18.4)
85
- parallel (~> 1.10)
86
- parser (>= 3.0.0.0)
87
- rainbow (>= 2.2.2, < 4.0)
88
- regexp_parser (>= 1.8, < 3.0)
89
- rexml
90
- rubocop-ast (>= 1.8.0, < 2.0)
91
- ruby-progressbar (~> 1.7)
92
- unicode-display_width (>= 1.4.0, < 3.0)
93
- rubocop-ast (1.16.0)
94
- parser (>= 3.1.1.0)
95
- rubocop-jekyll (0.12.0)
96
- rubocop (~> 1.18.0)
97
- rubocop-performance (~> 1.2)
98
- rubocop-performance (1.13.3)
99
- rubocop (>= 1.7.0, < 2.0)
100
- rubocop-ast (>= 0.4.0)
101
- rubocop-rake (0.6.0)
102
- rubocop (~> 1.0)
103
- ruby-debug-ide (0.7.3)
104
- rake (>= 0.8.1)
105
- ruby-progressbar (1.11.0)
106
- safe_yaml (1.0.5)
107
- sass (3.7.4)
108
- sass-listen (~> 4.0.0)
109
- sass-listen (4.0.0)
110
- rb-fsevent (~> 0.9, >= 0.9.4)
111
- rb-inotify (~> 0.9, >= 0.9.7)
112
- unicode-display_width (2.1.0)
113
-
114
- PLATFORMS
115
- x86_64-linux
116
-
117
- DEPENDENCIES
118
- bundler
119
- debase
120
- jekyll
121
- jekyll_flexible_include!
122
- pry
123
- rake (~> 13.0)
124
- rspec
125
- rubocop
126
- rubocop-jekyll
127
- rubocop-rake
128
- ruby-debug-ide
129
-
130
- BUNDLED WITH
131
- 2.3.7
data/LICENSE DELETED
@@ -1,22 +0,0 @@
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.
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/jekyll_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 = "This 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: absolute filenames,
15
- filenames relative to the top-level directory of the Jekyll web site,
16
- filenames relative to the user home directory,
17
- and executable filenames on the PATH.
18
- END_OF_DESC
19
- spec.homepage = "https://github.com/mslinn/jekyll_flexible_include_plugin"
20
- spec.license = "MIT"
21
- spec.required_ruby_version = ">= 2.6.0"
22
-
23
- spec.metadata["allowed_push_host"] = "https://rubygems.org/"
24
-
25
- spec.metadata["homepage_uri"] = spec.homepage
26
- spec.metadata["source_code_uri"] = "https://github.com/mslinn/jekyll_flexible_include_plugin"
27
- spec.metadata["changelog_uri"] = "https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md"
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
- `git ls-files -z`.split("\x0").reject do |f|
33
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
34
- end
35
- end
36
- spec.bindir = "exe"
37
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
38
- spec.require_paths = ["lib"]
39
-
40
- spec.post_install_message = "Thanks for installing jekyll_flexible_include!"
41
-
42
- spec.add_runtime_dependency 'jekyll', '>= 3.5.0'
43
-
44
- spec.add_development_dependency 'bundler'
45
- spec.add_development_dependency 'debase'
46
- spec.add_development_dependency 'jekyll'
47
- spec.add_development_dependency 'pry'
48
- spec.add_development_dependency 'rake'
49
- spec.add_development_dependency 'rspec'
50
- spec.add_development_dependency 'rubocop'
51
- spec.add_development_dependency 'rubocop-jekyll'
52
- spec.add_development_dependency 'rubocop-rake'
53
- spec.add_development_dependency 'ruby-debug-ide'
54
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllFlexibleIncludePlugin
4
- VERSION = "2.0.2"
5
- end
@@ -1,182 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "jekyll_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_params
67
- unless @params.match FULL_VALID_SYNTAX
68
- raise ArgumentError, <<~MSG
69
- Invalid syntax for the flexible_include tag:
70
-
71
- #{@params}
72
-
73
- Valid syntax:
74
-
75
- #{syntax_example}
76
-
77
- MSG
78
- end
79
- end
80
-
81
- # See https://gist.github.com/steakknife/4606598
82
- def expand_env_vars(str)
83
- str.gsub(/\$([a-zA-Z_]+[a-zA-Z0-9_]*)|\$\{(.+)\}/) { ENV[Regexp.last_match(1) || egexp.last_match(2)] }
84
- end
85
-
86
- # Grab file read opts in the context
87
- def file_read_opts(context)
88
- context.registers[:site].file_read_opts
89
- end
90
-
91
- # Render the variable if required
92
- def render_variable(context)
93
- if @file.match VARIABLE_SYNTAX
94
- partial = context.registers[:site]
95
- .liquid_renderer
96
- .file("(variable)")
97
- .parse(@file)
98
- partial.render!(context)
99
- end
100
- end
101
-
102
- def render(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
103
- file = render_variable(context) || @file
104
- # strip leading and trailing quotes, and expand environment variables
105
- file = expand_env_vars(file.gsub(/\A'|'\Z/, ''))
106
- path = file
107
- case file
108
- when %r{\A/} # Is the file absolute?
109
- # puts "********** render path=#{path}, file=#{file} *************"
110
- when /\A~/ # Is the file relative to user's home directory?
111
- # puts "********** render original file=#{file}, path=#{path} *************"
112
- file.slice! "~/"
113
- path = File.join(ENV['HOME'], file)
114
- # puts "********** render path=#{path}, file=#{file} *************"
115
- when /\A!/ # Is the file on the PATH?
116
- # puts "********** render original file=#{file}, path=#{path} *************"
117
- file.slice! "!"
118
- path = File.which(file)
119
- Jekyll.logger.error "Flexible_include error: #{file} was not found on the PATH, output was not included" unless path
120
- # puts "********** render path=#{path}, file=#{file} *************"
121
- else # The file is relative
122
- source = File.expand_path(context.registers[:site].config['source']) # website root directory
123
- path = File.join(source, file) # Fully qualified path of include file
124
- # puts "********** render file=#{file}, path=#{path}, source=#{source} *************"
125
- end
126
- return unless path
127
-
128
- begin
129
- escaped_contents = read_file(path, context).gsub("{", "&#123;").gsub("}", "&#125;").gsub("<", "&lt;")
130
- # puts escaped_contents
131
- partial = Liquid::Template.parse(escaped_contents)
132
- rescue StandardError => e
133
- abort "flexible_include.rb: #{e.message}"
134
- end
135
-
136
- context.stack do
137
- context["include"] = parse_params(context) if @params
138
- begin
139
- partial.render!(context)
140
- rescue Liquid::Error => e
141
- e.template_name = path
142
- e.markup_context = "included " if e.markup_context.nil?
143
- raise e
144
- end
145
- end
146
- end
147
-
148
- def valid_include_file?(path, dir, safe)
149
- !outside_site_source?(path, dir, safe) && File.file?(path)
150
- end
151
-
152
- def outside_site_source?(path, dir, safe)
153
- safe && !realpath_prefixed_with?(path, dir)
154
- end
155
-
156
- def realpath_prefixed_with?(path, dir)
157
- File.exist?(path) && File.realpath(path).start_with?(dir)
158
- rescue StandardError
159
- false
160
- end
161
-
162
- # This method allows to modify the file content by inheriting from the class.
163
- def read_file(file, context)
164
- File.read(file, **file_read_opts(context))
165
- end
166
-
167
- private
168
-
169
- def could_not_locate_message(file, includes_dirs, safe)
170
- message = "Could not locate the included file '#{file}' in any of "\
171
- "#{includes_dirs}. Ensure it exists in one of those directories and"
172
- message + if safe
173
- " is not a symlink as those are not allowed in safe mode."
174
- else
175
- ", if it is a symlink, does not point outside your site source."
176
- end
177
- end
178
- end
179
- end
180
- end
181
-
182
- Liquid::Template.register_tag("flexible_include", Jekyll::Tags::FlexibleInclude)
@@ -1,4 +0,0 @@
1
- module JekyllFlexibleIncludePlugin
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end