jekyll_include_plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +87 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/jekyll_include_plugin.gemspec +42 -0
- data/lib/jekyll_include_plugin.rb +7 -0
- data/lib/jekyll_include_plugin/jekyll_include_plugin.rb +101 -0
- data/lib/jekyll_include_plugin/utils.rb +116 -0
- data/lib/jekyll_include_plugin/version.rb +5 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53b0e6e7b0dbd571c517660e123f56720943bd007d46d3c3103d3b101db3e357
|
4
|
+
data.tar.gz: fe4f1a211570c08cffb2facfc05b4af31e12c4fccb45930f55f26bd86abb85d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da56e27aa2e81e3970ce743fb47c7d8d1a3560b0a4b26910c741bdbeee2db9faaccb48cea2573c123057c87a584ebff58c7450729831607bf00f1b10611074b9
|
7
|
+
data.tar.gz: 4240470f917c00c2c54be13356a9b01429ae655241f075de2e99bccf7b471ea670c00f5541bef273f90418ade94c05e38c526238e91d18f5740f69acd9a1999e
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.5
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jekyll_include_plugin (1.0.0)
|
5
|
+
jekyll (~> 3.9.1)
|
6
|
+
liquid (~> 4.0.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
colorator (1.1.0)
|
14
|
+
concurrent-ruby (1.1.9)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
em-websocket (0.5.2)
|
17
|
+
eventmachine (>= 0.12.9)
|
18
|
+
http_parser.rb (~> 0.6.0)
|
19
|
+
eventmachine (1.2.7)
|
20
|
+
ffi (1.15.3)
|
21
|
+
forwardable-extended (2.6.0)
|
22
|
+
http_parser.rb (0.6.0)
|
23
|
+
i18n (0.9.5)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
jekyll (3.9.1)
|
26
|
+
addressable (~> 2.4)
|
27
|
+
colorator (~> 1.0)
|
28
|
+
em-websocket (~> 0.5)
|
29
|
+
i18n (~> 0.7)
|
30
|
+
jekyll-sass-converter (~> 1.0)
|
31
|
+
jekyll-watch (~> 2.0)
|
32
|
+
kramdown (>= 1.17, < 3)
|
33
|
+
liquid (~> 4.0)
|
34
|
+
mercenary (~> 0.3.3)
|
35
|
+
pathutil (~> 0.9)
|
36
|
+
rouge (>= 1.7, < 4)
|
37
|
+
safe_yaml (~> 1.0)
|
38
|
+
jekyll-sass-converter (1.5.2)
|
39
|
+
sass (~> 3.4)
|
40
|
+
jekyll-watch (2.2.1)
|
41
|
+
listen (~> 3.0)
|
42
|
+
kramdown (2.3.1)
|
43
|
+
rexml
|
44
|
+
liquid (4.0.3)
|
45
|
+
listen (3.5.1)
|
46
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
47
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
48
|
+
mercenary (0.3.6)
|
49
|
+
pathutil (0.16.2)
|
50
|
+
forwardable-extended (~> 2.6)
|
51
|
+
public_suffix (4.0.6)
|
52
|
+
rake (13.0.3)
|
53
|
+
rb-fsevent (0.11.0)
|
54
|
+
rb-inotify (0.10.1)
|
55
|
+
ffi (~> 1.0)
|
56
|
+
rexml (3.2.5)
|
57
|
+
rouge (3.26.0)
|
58
|
+
rspec (3.10.0)
|
59
|
+
rspec-core (~> 3.10.0)
|
60
|
+
rspec-expectations (~> 3.10.0)
|
61
|
+
rspec-mocks (~> 3.10.0)
|
62
|
+
rspec-core (3.10.1)
|
63
|
+
rspec-support (~> 3.10.0)
|
64
|
+
rspec-expectations (3.10.1)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.10.0)
|
67
|
+
rspec-mocks (3.10.2)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.10.0)
|
70
|
+
rspec-support (3.10.2)
|
71
|
+
safe_yaml (1.0.5)
|
72
|
+
sass (3.7.4)
|
73
|
+
sass-listen (~> 4.0.0)
|
74
|
+
sass-listen (4.0.0)
|
75
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
76
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
jekyll_include_plugin!
|
83
|
+
rake (~> 13.0)
|
84
|
+
rspec (~> 3.0)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Flant
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Jekyll Include Plugin
|
2
|
+
|
3
|
+
Include local/remote file contents (or part of it) into your pages.
|
4
|
+
Allows multilang comments in the included files, which language will be used depends on `{{ page.lang }}`.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Basic usage as follows:
|
9
|
+
|
10
|
+
```jinja
|
11
|
+
jekyllroot/pages/foo.md:
|
12
|
+
-----------------------
|
13
|
+
lang: en
|
14
|
+
-----------------------
|
15
|
+
{% include_file "this_dir_is_inside_jekyll_root_dir/foo/Dockerfile" snippet="system_deps" syntax="Dockerfile" %}
|
16
|
+
```
|
17
|
+
|
18
|
+
```Dockerfile
|
19
|
+
this_dir_is_inside_jekyll_root_dir/foo/Dockerfile:
|
20
|
+
--------------------------------------------------------
|
21
|
+
FROM ruby
|
22
|
+
|
23
|
+
# [<snippet install_system_deps>]
|
24
|
+
# [<en>] Install system dependencies
|
25
|
+
# [<en>] (multiline possible too)
|
26
|
+
# [<ru>] Установка системных зависимостей
|
27
|
+
RUN apt update && apt install curl -y
|
28
|
+
# [<endsnippet install_system_deps>]
|
29
|
+
```
|
30
|
+
|
31
|
+
Result:
|
32
|
+
```Dockerfile
|
33
|
+
# Install system dependencies
|
34
|
+
# (multiline possible too)
|
35
|
+
RUN apt update && apt install curl -y
|
36
|
+
```
|
37
|
+
|
38
|
+
Include whole file:
|
39
|
+
```jinja
|
40
|
+
{% include_file "Dockerfile" %}
|
41
|
+
```
|
42
|
+
|
43
|
+
Include remote file:
|
44
|
+
```jinja
|
45
|
+
{% include_file "https://raw.githubusercontent.com/werf/werf-guides/master/examples/rails/010_build/Dockerfile" %}
|
46
|
+
```
|
47
|
+
|
48
|
+
Dynamic parameters:
|
49
|
+
```jinja
|
50
|
+
{% include_file "{{ $templatingAllowedHere }}" snippet="{{ $hereToo }}" %}
|
51
|
+
```
|
52
|
+
|
53
|
+
## Installation
|
54
|
+
|
55
|
+
Add this line to your application's Gemfile:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
gem 'jekyll_include_plugin'
|
59
|
+
```
|
60
|
+
|
61
|
+
And this into your Jekyll config:
|
62
|
+
```yaml
|
63
|
+
plugins:
|
64
|
+
- jekyll_include_plugin
|
65
|
+
```
|
66
|
+
|
67
|
+
Then execute:
|
68
|
+
```bash
|
69
|
+
bundle install
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
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).
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "jekyll_include_plugin"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("lib", __dir__))
|
4
|
+
require_relative "lib/jekyll_include_plugin/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll_include_plugin"
|
8
|
+
spec.version = JekyllIncludePlugin::VERSION
|
9
|
+
spec.authors = ["Ilya Lesikov"]
|
10
|
+
spec.email = ["ilya@lesikov.com"]
|
11
|
+
|
12
|
+
spec.summary = "Include files or file samples into Markdown"
|
13
|
+
# spec.description = "TODO: Write a longer description or delete this line."
|
14
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = ">= 2.6.3"
|
17
|
+
|
18
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
|
20
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
22
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "liquid", "~> 4.0.3"
|
34
|
+
spec.add_runtime_dependency "jekyll", "~> 3.9.1"
|
35
|
+
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
# spec.add_development_dependency "rubocop", "~> 1.7"
|
39
|
+
|
40
|
+
# For more information and examples about making a new gem, checkout our
|
41
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
42
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "jekyll_include_plugin/version"
|
4
|
+
require_relative "jekyll_include_plugin/utils"
|
5
|
+
require_relative "jekyll_include_plugin/jekyll_include_plugin"
|
6
|
+
|
7
|
+
Liquid::Template.register_tag("include_file", JekyllIncludePlugin::IncludeFileTag)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# TODO: don't read the whole file into the memory from the beginning, instead process file with the parser line by line
|
2
|
+
require "open-uri"
|
3
|
+
require "liquid"
|
4
|
+
|
5
|
+
module JekyllIncludePlugin
|
6
|
+
class IncludeFileTag < Liquid::Tag
|
7
|
+
include Utils
|
8
|
+
include TextUtils
|
9
|
+
|
10
|
+
def initialize(tag_name, raw_markup, tokens)
|
11
|
+
super
|
12
|
+
@raw_markup = raw_markup
|
13
|
+
@params = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(context)
|
17
|
+
parse_params(context)
|
18
|
+
|
19
|
+
file_contents = get_raw_file_contents(context)
|
20
|
+
|
21
|
+
if @params["snippet"]
|
22
|
+
file_contents = pick_snippet(file_contents, @params["snippet"])
|
23
|
+
else
|
24
|
+
file_contents = remove_all_snippets(file_contents)
|
25
|
+
end
|
26
|
+
|
27
|
+
file_contents = remove_excessive_newlines(file_contents)
|
28
|
+
file_contents = remove_excessive_indentation(file_contents)
|
29
|
+
file_contents = render_comments(file_contents, context.registers[:page]["lang"])
|
30
|
+
file_contents = wrap_in_codeblock(file_contents, @params["syntax"]) if @params["syntax"]
|
31
|
+
|
32
|
+
return file_contents
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def parse_params(context)
|
38
|
+
rendered_markup = Liquid::Template
|
39
|
+
.parse(@raw_markup)
|
40
|
+
.render(context)
|
41
|
+
.gsub(%r!\\\{\\\{|\\\{\\%!, '\{\{' => "{{", '\{\%' => "{%")
|
42
|
+
.strip
|
43
|
+
debug("Rendered params: #{rendered_markup}")
|
44
|
+
|
45
|
+
markup = %r!^"?(?<path>[^\s\"]+)"?(?<params>(\s+\w+="[^\"]+")*)?$!.match(rendered_markup)
|
46
|
+
debug("Matched params: #{markup.inspect}")
|
47
|
+
abort("Can't parse include_file tag params: #{@raw_markup}") unless markup
|
48
|
+
|
49
|
+
if markup[:params]
|
50
|
+
@params = Hash[ *markup[:params].scan(%r!(?<param>[^\s="]+)(?:="(?<value>[^"]+)")?\s?!).flatten ]
|
51
|
+
end
|
52
|
+
|
53
|
+
if %r!^https?://\S+$!.match?(markup[:path])
|
54
|
+
@params["abs_file_url"] = markup[:path]
|
55
|
+
else
|
56
|
+
@params["rel_file_path"] = markup[:path]
|
57
|
+
end
|
58
|
+
|
59
|
+
validate_param_by_regex("snippet", "^[-_.a-zA-Z0-9]+$")
|
60
|
+
validate_param_by_regex("syntax", "^[-_.a-zA-Z0-9]+$")
|
61
|
+
|
62
|
+
debug("Params set: #{@params.inspect}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def validate_param_by_regex(param_name, param_regex)
|
66
|
+
if @params[param_name] && ! %r!#{param_regex}!.match?(@params[param_name])
|
67
|
+
abort("Parameter '#{param_name}' with value '#{@params[param_name]}' is not valid, must match regex: #{param_regex}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_raw_file_contents(context)
|
72
|
+
if @params["abs_file_url"]
|
73
|
+
return get_remote_file_contents()
|
74
|
+
elsif @params["rel_file_path"]
|
75
|
+
return get_local_file_contents(context)
|
76
|
+
end
|
77
|
+
raise "Neither abs_file_url nor rel_file_path have been found"
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_local_file_contents(context)
|
81
|
+
base_source_dir = File.expand_path(context.registers[:site].config["source"]).freeze
|
82
|
+
abs_file_path = File.join(base_source_dir, @params["rel_file_path"])
|
83
|
+
|
84
|
+
begin
|
85
|
+
debug("Getting contents of specified local file: #{abs_file_path}")
|
86
|
+
return File.read(abs_file_path, **context.registers[:site].file_read_opts)
|
87
|
+
rescue SystemCallError, IOError => e
|
88
|
+
abort("Can't get the contents of specified local file '#{abs_file_path}': #{e.message}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_remote_file_contents()
|
93
|
+
begin
|
94
|
+
debug("Getting contents of specified remote file: #{@params["abs_file_url"]}")
|
95
|
+
return open(@params["abs_file_url"]).read
|
96
|
+
rescue OpenURI::HTTPError => e
|
97
|
+
abort("Can't get the contents of specified remote file '#{@params["abs_file_url"]}': #{e.message}")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module JekyllIncludePlugin
|
2
|
+
module Utils
|
3
|
+
def debug(msg)
|
4
|
+
Jekyll.logger.debug("[jekyll_include_plugin] DEBUG:", msg)
|
5
|
+
end
|
6
|
+
|
7
|
+
def info(msg)
|
8
|
+
Jekyll.logger.info("[jekyll_include_plugin] INFO:", msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def abort(msg)
|
12
|
+
Jekyll.logger.abort_with("[jekyll_include_plugin] FATAL:", msg)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module TextUtils
|
17
|
+
include Utils
|
18
|
+
|
19
|
+
def pick_snippet(text, snippet_name)
|
20
|
+
snippet_content = ""
|
21
|
+
snippet_start_found = false
|
22
|
+
snippet_end_found = false
|
23
|
+
text.each_line do |line|
|
24
|
+
if %r!\[<snippet\s+#{snippet_name}>\]!.match?(line)
|
25
|
+
if snippet_start_found
|
26
|
+
abort("Snippet '#{snippet_name}' occured twice. Each snippet should have a unique name, same name not allowed.")
|
27
|
+
end
|
28
|
+
snippet_start_found = true
|
29
|
+
debug("Snippet '#{snippet_name}' start matched by line: #{line}")
|
30
|
+
elsif %r!\[<endsnippet\s+#{snippet_name}>\]!.match?(line)
|
31
|
+
snippet_end_found = true
|
32
|
+
debug("Snippet '#{snippet_name}' end matched by line: #{line}")
|
33
|
+
break
|
34
|
+
elsif %r!\[<(end)?snippet\s+[^>]+>\]!.match?(line)
|
35
|
+
debug("Skipping line with non-relevant (end)snippet: #{line}")
|
36
|
+
next
|
37
|
+
elsif snippet_start_found
|
38
|
+
snippet_content += line
|
39
|
+
end
|
40
|
+
end
|
41
|
+
abort("Snippet '#{snippet_name}' has not been found.") unless snippet_start_found
|
42
|
+
abort("End of the snippet '#{snippet_name}' has not been found.") unless snippet_end_found
|
43
|
+
abort("Snippet '#{snippet_name}' appears to be empty. Fix and retry.") if snippet_content.empty?
|
44
|
+
|
45
|
+
return snippet_content
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_all_snippets(text)
|
49
|
+
result_text = ""
|
50
|
+
text.each_line do |line|
|
51
|
+
if %r!\[<(end)?snippet\s+[^>]+>\]!.match?(line)
|
52
|
+
debug("Skipping line with non-relevant (end)snippet: #{line}")
|
53
|
+
next
|
54
|
+
else
|
55
|
+
result_text += line
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
return result_text
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_comments(text, lang)
|
63
|
+
rendered_file_contents = ""
|
64
|
+
text.each_line do |line|
|
65
|
+
if %r!\[<#{lang}>\]!.match?(line)
|
66
|
+
debug("Matched doc line: #{line}")
|
67
|
+
rendered_file_contents += line.sub(/\[<#{lang}>\]\s*/, "")
|
68
|
+
elsif %r!\[<\w+>\]!.match?(line)
|
69
|
+
debug("Found non-matching doc line, skipping: #{line}")
|
70
|
+
next
|
71
|
+
else
|
72
|
+
rendered_file_contents += line
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return rendered_file_contents
|
77
|
+
end
|
78
|
+
|
79
|
+
def remove_excessive_newlines(text)
|
80
|
+
return text.sub(/^(\s*\R)*/, "").rstrip()
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_excessive_indentation(text)
|
84
|
+
unindented_text = ""
|
85
|
+
|
86
|
+
lowest_indent = nil
|
87
|
+
text.each_line do |line|
|
88
|
+
if %r!^\s*$!.match?(line)
|
89
|
+
next
|
90
|
+
else
|
91
|
+
cur_indent = %r!^\s*!.match(line)[0].length
|
92
|
+
lowest_indent = cur_indent if lowest_indent.nil? || lowest_indent > cur_indent
|
93
|
+
end
|
94
|
+
end
|
95
|
+
return text if lowest_indent.nil?
|
96
|
+
|
97
|
+
text.each_line do |line|
|
98
|
+
if blank_line?(line)
|
99
|
+
unindented_text += line
|
100
|
+
else
|
101
|
+
unindented_text += line[lowest_indent..-1]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
return unindented_text
|
106
|
+
end
|
107
|
+
|
108
|
+
def wrap_in_codeblock(text, syntax)
|
109
|
+
return "```#{syntax}\n#{text}\n```"
|
110
|
+
end
|
111
|
+
|
112
|
+
def blank_line?(line)
|
113
|
+
return %r!^\s*$!.match?(line)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_include_plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Lesikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.9.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.9.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.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: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ilya@lesikov.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".github/workflows/main.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- jekyll_include_plugin.gemspec
|
88
|
+
- lib/jekyll_include_plugin.rb
|
89
|
+
- lib/jekyll_include_plugin/jekyll_include_plugin.rb
|
90
|
+
- lib/jekyll_include_plugin/utils.rb
|
91
|
+
- lib/jekyll_include_plugin/version.rb
|
92
|
+
homepage:
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.6.3
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.0.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Include files or file samples into Markdown
|
115
|
+
test_files: []
|