jekyll_flexible_include 2.0.2 → 2.0.3

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: aa11b845ffd2d483de86a54aadce690978744f497bfd432e2a683a834204f6d6
4
+ data.tar.gz: 7cc4cbfecf9061a07802f35aeb9a119b6b5921b8aefc93c2d6f8d707c31d82f4
5
5
  SHA512:
6
- metadata.gz: 5dbdeef00337d13e4a2db94c80e25a324e2bf731886ead64678b3e579a2fb2b568fa9b3c2e68cafa00e21a2bc72fe47d2463e0f046df58f96285f76de0cc78e0
7
- data.tar.gz: dae0c2b23c91458111599ee0db43dad4dc863dc14f6d52ba48e919bff0132d3b3eae160f748fffa7aabe5f82a82f0702113fad71bc6c7a2c16d2ad5f0f8a8180
6
+ metadata.gz: d27e4488a061b886c166cd9bc6f77ef3b17e1ce686c7f18904665f0b1e5ce6445a487bb617c787d9abfafdeac7f2a9dee46c16a66425aaa3f49b44daf05f9c76
7
+ data.tar.gz: 995e5902bd70b1eb67dc67ff1d37235c9e231235693f686ab706015bf23b157e5db41c4d3a131f152d847eb685bf537fbc13d433ab7debd27df7d55c71045496
data/.rubocop.yml CHANGED
@@ -29,3 +29,6 @@ Style/StringLiterals:
29
29
 
30
30
  Style/StringLiteralsInInterpolation:
31
31
  Enabled: false
32
+
33
+ Gemspec/RequireMFA:
34
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,14 +1,8 @@
1
- ## 2.0.2 / 2022-03-11
2
- * This version should actually work, crossing fingers
3
-
4
- ## 2.0.1 / 2022-03-11
5
- * Struggling with poorly documented gem naming conventions, this release is broken, do not use
6
1
  ## 2.0.0 / 2022-03-11
7
2
  * Made into a Ruby gem and published on RubyGems.org as [jekyll_flexible_include](https://rubygems.org/gems/jekyll_flexible_include).
8
3
  * `bin/attach` script added for debugging
9
4
  * Rubocop standards added
10
5
  * Proper versioning and CHANGELOG.md added
11
- * This release is broken, do not use
12
6
 
13
7
  ## 1.1.1 / 2021-05-01
14
8
  * 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
 
@@ -27,6 +32,10 @@ is specified with a value other than <code>false</code>.
27
32
  Note that the [square brackets] merely indicate an optional parameter and are not intended to be literally written.
28
33
 
29
34
 
35
+ ### Additional Information
36
+ More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
37
+
38
+
30
39
  ## Installation
31
40
 
32
41
  Add the following to `Gemfile`, inside the `jekyll_plugins` group:
@@ -36,6 +45,21 @@ group :jekyll_plugins do
36
45
  end
37
46
  ```
38
47
 
48
+ Also add it to `_config.yml`:
49
+ ```yaml
50
+ plugins:
51
+ - flexible_include
52
+ ```
53
+
54
+ And then execute:
55
+
56
+ $ bundle install
57
+
58
+ Or install it yourself as:
59
+
60
+ $ gem install jekyll_flexible_include
61
+
62
+
39
63
  ## Examples
40
64
 
41
65
  1. Include files without parameters; all four types of includes are shown.
@@ -53,6 +77,11 @@ end
53
77
  {% flexible_include '~/folder/under/home/directory/foo.html' do_not_escape='true' %}
54
78
  ```
55
79
 
80
+ ## Additional Information
81
+ More information is available on
82
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
83
+
84
+
56
85
  ## GitHub Pages
57
86
  GitHub Pages only allows [these plugins](https://pages.github.com/versions/).
58
87
  That means `flexible_include` will not work on GitHub Pages.
@@ -75,9 +104,48 @@ If the plugin does not work:
75
104
 
76
105
  ## Development
77
106
 
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.
107
+ After checking out the repo, run `bin/setup` to install dependencies.
108
+
109
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
110
+
111
+ ### Build and Install Locally
112
+ To build and install this gem onto your local machine, run:
113
+ ```shell
114
+ $ rake install:local
115
+ ```
116
+
117
+ The following also does the same thing:
118
+ ```shell
119
+ $ bundle exec rake install
120
+ ```
121
+
122
+ Examine the newly built gem:
123
+ ```shell
124
+ $ gem info jekyll_flexible_include
125
+
126
+ *** LOCAL GEMS ***
127
+
128
+ jekyll_flexible_include (1.0.0)
129
+ Author: Mike Slinn
130
+ Homepage:
131
+ https://github.com/mslinn/jekyll_flexible_include
132
+ License: MIT
133
+ Installed at: /home/mslinn/.gems
134
+
135
+ Generates Jekyll logger with colored output.
136
+ ```
137
+
79
138
 
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).
139
+ ### Build and Push to RubyGems
140
+ To release a new version,
141
+ 1. Update the version number in `version.rb`.
142
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
143
+ 3. Run the following:
144
+ ```shell
145
+ $ bundle exec rake release
146
+ ```
147
+ The above creates a git tag for the version, commits the created tag,
148
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
81
149
 
82
150
 
83
151
  ## Contributing
@@ -89,4 +157,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
89
157
 
90
158
  ## License
91
159
 
92
- [MIT](./LICENSE)
160
+ 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"]
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 = JekyllFlexibleIncludePlugin::VERSION
39
+
40
+ spec.add_dependency "jekyll", ">= 3.5.0"
41
+ spec.add_dependency "jekyll_plugin_logger", '~> 2.0.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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllFlexibleIncludePlugin
4
- VERSION = "2.0.2"
4
+ VERSION = "2.0.3"
5
5
  end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "jekyll_plugin_logger"
5
+ require_relative "flexible_include/version"
6
+
7
+ module JekyllFlexibleIncludeName
8
+ PLUGIN_NAME = "flexible_include"
9
+ end
10
+
11
+ class FlexibleIncludeError < StandardError
12
+ attr_accessor :path
13
+
14
+ def initialize(msg, path)
15
+ super
16
+ @path = path
17
+ end
18
+ end
19
+
20
+ class FlexibleInclude < Liquid::Tag
21
+ VALID_SYNTAX = %r!
22
+ ([\w-]+)\s*=\s*
23
+ (?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
24
+ !x.freeze
25
+ VARIABLE_SYNTAX = %r!
26
+ (?<variable>[^{]*(\{\{\s*[\w\-.]+\s*(\|.*)?\}\}[^\s{}]*)+)
27
+ (?<params>.*)
28
+ !mx.freeze
29
+
30
+ FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
31
+ VALID_FILENAME_CHARS = %r!^[\w/\.-]+$!.freeze
32
+
33
+ def initialize(tag_name, markup, parse_context)
34
+ super
35
+ @logger = PluginMetaLogger.instance.new_logger(self)
36
+ matched = markup.strip.match(VARIABLE_SYNTAX)
37
+ if matched
38
+ @file = matched["variable"].strip
39
+ @params = matched["params"].strip
40
+ else
41
+ @file, @params = markup.strip.split(%r!\s+!, 2)
42
+ end
43
+ @markup = markup
44
+ @logger.debug("initialize: @markup=#{@markup}")
45
+ @parse_context = parse_context
46
+ end
47
+
48
+ # @param context [Liquid::Context]
49
+ def render(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
50
+ markup = @markup
51
+ @logger.debug { "markup='#{markup}'" }
52
+ markup = sanitize_parameter(markup)
53
+ markup = expand_env(markup)
54
+ path = markup
55
+ if /\A\//.match(markup) # Is the file absolute?
56
+ @logger.debug { "Absolute path=#{path}, markup=#{markup}" }
57
+ elsif /\A~/.match(markup) # Relative path to user's home directory?
58
+ @logger.debug { "Relative start markup=#{markup}, path=#{path}" }
59
+ markup.slice! "~/"
60
+ path = File.join(ENV['HOME'], markup)
61
+ @logger.debug { "Relative end markup=#{markup}, path=#{path}" }
62
+ elsif /\A\!/.match(markup) # Run command and return response
63
+ markup.slice! "!"
64
+ @logger.debug { "Execute markup=#{markup}" }
65
+ contents = run(markup)
66
+ else # The file is relative or it was passed as a parameter to an include and was not noticed before, e.g. @file='{{include.file}}'
67
+ @logger.debug { "Catchall start @file=#{@file}, markup=#{markup}, path=#{path}" }
68
+ file = render_variable(context)
69
+ markup = file if file
70
+ markup = expand_env(markup)
71
+ markup = sanitize_parameter(markup)
72
+ if /\A\//.match(markup) # Absolute path
73
+ path = markup
74
+ elsif /\A\!/.match(markup)
75
+ markup.slice! "!"
76
+ @logger.debug { "Execute markup=#{markup}" }
77
+ contents = run(markup)
78
+ elsif /\A~/.match(markup) # Relative path to user's home directory?
79
+ markup.slice! "~/"
80
+ path = File.join(ENV['HOME'], markup)
81
+ else # Relative path
82
+ site = context.registers[:site]
83
+ source = File.expand_path(site.config['source']) # website root directory
84
+ path = File.join(source, markup) # Fully qualified path of include file from relative path
85
+ end
86
+ @logger.debug { "Catchall end markup=#{markup}, path=#{path}" }
87
+ end
88
+ render_completion(context, path, contents)
89
+ end
90
+
91
+ private
92
+
93
+ def escape_html?(context)
94
+ do_not_escape = false
95
+ if @params
96
+ context["include"] = parse_params(context)
97
+ @logger.debug { "context['include']['do_not_escape'] = #{context['include']['do_not_escape']}" }
98
+ do_not_escape = context['include'].fetch('do_not_escape', 'false')
99
+ @logger.debug { "do_not_escape=#{do_not_escape}" }
100
+ @logger.debug { "do_not_escape=='false' = #{do_not_escape=='false'}" }
101
+ end
102
+ do_not_escape
103
+ end
104
+
105
+ def escape_html(string)
106
+ string.gsub("{", "&#123;").gsub("}", "&#125;").gsub("<", "&lt;")
107
+ end
108
+
109
+ def expand_env(str)
110
+ str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) { ENV[$1] }
111
+ end
112
+
113
+ # Grab file read opts in the context
114
+ def file_read_opts(context)
115
+ context.registers[:site].file_read_opts
116
+ end
117
+
118
+ def parse_params(context)
119
+ params = {}
120
+ markup = @params
121
+
122
+ while (match = VALID_SYNTAX.match(markup))
123
+ markup = markup[match.end(0)..-1]
124
+
125
+ value = if match[2]
126
+ match[2].gsub(%r!\\"!, '"')
127
+ elsif match[3]
128
+ match[3].gsub(%r!\\'!, "'")
129
+ elsif match[4]
130
+ context[match[4]]
131
+ end
132
+
133
+ params[match[1]] = value
134
+ end
135
+ params
136
+ end
137
+
138
+ def read_file(file)
139
+ File.read(file)
140
+ end
141
+
142
+ def realpath_prefixed_with?(path, dir)
143
+ File.exist?(path) && File.realpath(path).start_with?(dir)
144
+ rescue StandardError
145
+ false
146
+ end
147
+
148
+ def render_completion(context, path, contents)
149
+ begin
150
+ contents = read_file(path) unless contents
151
+ rescue StandardError => e
152
+ puts "flexible_include.rb error: #{e.message}".red
153
+ $stderr.reopen(IO::NULL)
154
+ $stdout.reopen(IO::NULL)
155
+ exit
156
+ end
157
+ escaped_contents = escape_html?(context) ? escape_html(contents) : contents
158
+ context.stack do # Temporarily push a new local scope onto the variable stack
159
+ begin
160
+ partial = Liquid::Template.parse(escaped_contents) # Type Liquid::Template
161
+ rescue StandardError => e
162
+ puts "flexible_include.rb error: #{e.message}".red
163
+ $stderr.reopen(IO::NULL)
164
+ $stdout.reopen(IO::NULL)
165
+ exit
166
+ end
167
+
168
+ begin
169
+ partial.render!(context)
170
+ rescue Liquid::Error => e
171
+ e.template_name = path
172
+ e.markup_context = "included " if e.markup_context.nil?
173
+ raise e
174
+ end
175
+ end
176
+ end
177
+
178
+ # @return setvalue of 'file' variable if defined
179
+ def render_variable(context)
180
+ if @file.match VARIABLE_SYNTAX
181
+ partial = context.registers[:site]
182
+ .liquid_renderer
183
+ .file("(variable)")
184
+ .parse(@file)
185
+ partial.render!(context)
186
+ end
187
+ end
188
+
189
+ def run(cmd)
190
+ %x[ #{cmd} ].chomp
191
+ end
192
+
193
+ # strip leading and trailing quotes if present
194
+ def sanitize_parameter(parameter)
195
+ parameter.strip.gsub(/\A'|'\Z/, '').strip if parameter
196
+ end
197
+
198
+ def valid_include_file?(path, dir, safe)
199
+ !outside_site_source?(path, dir, safe) && File.file?(path)
200
+ end
201
+
202
+ def outside_site_source?(path, dir, safe)
203
+ safe && !realpath_prefixed_with?(path, dir)
204
+ end
205
+
206
+ def could_not_locate_message(file, includes_dirs, safe)
207
+ message = "Could not locate the included file '#{file}' in any of "\
208
+ "#{includes_dirs}. Ensure it exists in one of those directories and"
209
+ message + if safe
210
+ " is not a symlink as those are not allowed in safe mode."
211
+ else
212
+ ", if it is a symlink, does not point outside your site source."
213
+ end
214
+ end
215
+ end
216
+
217
+ PluginMetaLogger.instance.info { "Loaded #{JekyllFlexibleIncludeName::PLUGIN_NAME} v#{JekyllFlexibleIncludePlugin::VERSION} plugin." }
218
+ Liquid::Template.register_tag('flexible_include', FlexibleInclude)
metadata CHANGED
@@ -1,14 +1,14 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-13 00:00:00.000000000 Z
11
+ date: 2022-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.5.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: jekyll_plugin_logger
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: 2.0.0
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: debase
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,104 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  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
55
  - !ruby/object:Gem::Dependency
154
56
  name: ruby-debug-ide
155
57
  requirement: !ruby/object:Gem::Requirement
@@ -170,34 +72,32 @@ description: |
170
72
  filenames relative to the top-level directory of the Jekyll web site,
171
73
  filenames relative to the user home directory,
172
74
  and executable filenames on the PATH.
173
- email: mslinn@mslinn.com
75
+ email:
76
+ - mslinn@mslinn.com
174
77
  executables: []
175
78
  extensions: []
176
79
  extra_rdoc_files: []
177
80
  files:
178
- - ".editorconfig"
179
81
  - ".rubocop.yml"
180
- - ".vscode/launch.json"
181
- - ".vscode/settings.json"
182
82
  - CHANGELOG.md
183
- - Gemfile
184
- - Gemfile.lock
185
- - LICENSE
186
83
  - README.md
187
84
  - 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
85
+ - jekyll_flexible_include_plugin.gemspec
86
+ - lib/flexible_include.rb
87
+ - lib/flexible_include/version.rb
88
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude
193
89
  licenses:
194
90
  - MIT
195
91
  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
92
+ allowed_push_host: https://rubygems.org
93
+ bug_tracker_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/issues
199
94
  changelog_uri: https://github.com/mslinn/jekyll_flexible_include_plugin/CHANGELOG.md
200
- post_install_message: Thanks for installing jekyll_flexible_include!
95
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#flexibleInclude
96
+ source_code_uri: https://github.com/mslinn/jekyll_flexible_include_plugin
97
+ post_install_message: |2+
98
+
99
+ Thanks for installing jekyll_flexible_include!
100
+
201
101
  rdoc_options: []
202
102
  require_paths:
203
103
  - lib
@@ -212,9 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
112
  - !ruby/object:Gem::Version
213
113
  version: '0'
214
114
  requirements: []
215
- rubygems_version: 3.2.5
115
+ rubygems_version: 3.1.4
216
116
  signing_key:
217
117
  specification_version: 4
218
- summary: This Jekyll plugin supports various ways to include content into the generated
118
+ summary: Jekyll plugin supports various ways to include content into the generated
219
119
  site.
220
120
  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,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