jekyll_eval_filter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +71 -0
- data/CHANGELOG.md +2 -0
- data/README.md +100 -0
- data/Rakefile +40 -0
- data/jekyll_eval_filter.gemspec +35 -0
- data/lib/evaluate.rb +26 -0
- data/lib/jekyll_eval_filter/version.rb +3 -0
- data/lib/jekyll_eval_filter.rb +10 -0
- data/spec/jekyll_eval_filter_spec.rb +13 -0
- data/spec/spec_helper.rb +79 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be8155d7e7318ab2b296502685ffe77ee49324e2c3c496eeef0d281b9a85ed9c
|
4
|
+
data.tar.gz: d0e60177381189d15979296ac1e3790009a83afc77dad12da0657ad65045914e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38fc2366d7130c3cab747b3eb5a1ee762162bdd0868cbd1148a8584659e9e1a118fbb10b8670b1bbae37ca960492d59679a8f99bc70d020ad86c83e36a964321
|
7
|
+
data.tar.gz: bd657a032d11e7ab6cd35e549164413603465e84abbad002a96b1a6037f9483cac583500cde85da6f6c90f5c81f33c10fb0bcff62ad0d40bfb4d5317a626d0ef
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require:
|
2
|
+
# - rubocop-jekyll
|
3
|
+
- rubocop-md
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
Exclude:
|
10
|
+
- binstub/**/*
|
11
|
+
- exe/**/*
|
12
|
+
- vendor/**/*
|
13
|
+
- Gemfile*
|
14
|
+
NewCops: enable
|
15
|
+
TargetRubyVersion: 3.1.3
|
16
|
+
|
17
|
+
Gemspec/DeprecatedAttributeAssignment:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Gemspec/RequireMFA:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Layout/HashAlignment:
|
24
|
+
EnforcedColonStyle: table
|
25
|
+
EnforcedHashRocketStyle: table
|
26
|
+
|
27
|
+
Layout/LineLength:
|
28
|
+
Max: 150
|
29
|
+
|
30
|
+
Metrics/AbcSize:
|
31
|
+
Max: 35
|
32
|
+
|
33
|
+
Metrics/BlockLength:
|
34
|
+
Exclude:
|
35
|
+
- jekyll_eval_filter.gemspec
|
36
|
+
Max: 30
|
37
|
+
|
38
|
+
Metrics/CyclomaticComplexity:
|
39
|
+
Max: 15
|
40
|
+
|
41
|
+
Metrics/MethodLength:
|
42
|
+
Max: 40
|
43
|
+
|
44
|
+
Metrics/ModuleLength:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Metrics/PerceivedComplexity:
|
48
|
+
Max: 15
|
49
|
+
|
50
|
+
Naming/FileName:
|
51
|
+
Exclude:
|
52
|
+
- Rakefile
|
53
|
+
|
54
|
+
Style/Documentation:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/FrozenStringLiteralComment:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/TrailingCommaInHashLiteral:
|
61
|
+
EnforcedStyleForMultiline: comma
|
62
|
+
|
63
|
+
RSpec/FilePath:
|
64
|
+
IgnoreMethods: true
|
65
|
+
SpecSuffixOnly: true
|
66
|
+
|
67
|
+
RSpec/ExampleLength:
|
68
|
+
Max: 30
|
69
|
+
|
70
|
+
RSpec/MultipleExpectations:
|
71
|
+
Max: 15
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
`jekyll_eval_filter`
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/jekyll_eval_filter.svg)](https://badge.fury.io/rb/jekyll_eval_filter)
|
3
|
+
===========
|
4
|
+
|
5
|
+
`jekyll_eval_filter` evaluates given Ruby expression passed to it and returns the response.
|
6
|
+
|
7
|
+
|
8
|
+
## CAUTION
|
9
|
+
This filter can evaluation *any Ruby expression*.
|
10
|
+
No limitations are imposed.
|
11
|
+
|
12
|
+
If you use this filter, only allow trusted and verified people to edit the source of your Jekyll website.
|
13
|
+
|
14
|
+
With great power comes great responsibility.
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```
|
20
|
+
{{ '1+2' | eval }} # returns 3
|
21
|
+
|
22
|
+
{{ 'sudo rm -rf /' | eval }} # potentially destroys your system
|
23
|
+
# On a clear disk you can seek forever
|
24
|
+
```
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'jekyll_eval_filter'
|
32
|
+
```
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
```bash
|
36
|
+
$ bundle
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## Additional Information
|
41
|
+
More information is available on
|
42
|
+
[Mike Slinn’s website](https://www.mslinn.com/jekyll/10400-jekyll-plugin-template-collection.html).
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
48
|
+
|
49
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
|
52
|
+
### Build and Install Locally
|
53
|
+
To build and install this gem onto your local machine, run:
|
54
|
+
|
55
|
+
```shell
|
56
|
+
$ bundle exec rake install
|
57
|
+
jekyll_eval_filter 1.0.0 built to pkg/jekyll_eval_filter-0.1.0.gem.
|
58
|
+
jekyll_eval_filter (1.0.0) installed.
|
59
|
+
```
|
60
|
+
|
61
|
+
Examine the newly built gem:
|
62
|
+
```
|
63
|
+
$ gem info jekyll_eval_filter
|
64
|
+
|
65
|
+
*** LOCAL GEMS ***
|
66
|
+
|
67
|
+
jekyll_eval_filter (1.0.0)
|
68
|
+
Author: Mike Slinn
|
69
|
+
Homepage:
|
70
|
+
https://github.com/mslinn/jekyll_eval_filter
|
71
|
+
License: MIT
|
72
|
+
Installed at: /home/mslinn/.gems
|
73
|
+
|
74
|
+
Generates Jekyll logger with colored output.
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
### Build and Push to RubyGems
|
79
|
+
To release a new version,
|
80
|
+
1. Update the version number in `version.rb`.
|
81
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
82
|
+
3. Run the following:
|
83
|
+
```shell
|
84
|
+
$ bundle exec rake release
|
85
|
+
```
|
86
|
+
The above creates a git tag for the version, commits the created tag,
|
87
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
88
|
+
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork the project
|
93
|
+
2. Create a descriptively named feature branch
|
94
|
+
3. Add your feature
|
95
|
+
4. Submit a pull request
|
96
|
+
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Bump patch version'
|
11
|
+
task :patch do
|
12
|
+
system 'gem bump --tag'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Bump minor version'
|
16
|
+
task :minor do
|
17
|
+
system 'gem bump --version minor --tag'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Bump major version'
|
21
|
+
task :major do
|
22
|
+
system 'gem bump --version major --tag'
|
23
|
+
end
|
24
|
+
|
25
|
+
task publish: [:build] do
|
26
|
+
$VERBOSE = nil
|
27
|
+
load 'jekyll_eval_filter/version.rb'
|
28
|
+
system "gem push pkg/jekyll_eval_filter-#{JekyllEvalFilter::VERSION}.gem"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Bump patch version, create git tag, build the gem and release to geminabox (default)'
|
32
|
+
task release_patch: %i[test patch publish]
|
33
|
+
|
34
|
+
desc 'Bump minor version, create git tag, build the gem and release to geminabox'
|
35
|
+
task release_minor: %i[test minor publish]
|
36
|
+
|
37
|
+
desc 'Bump major version, create git tag, build the gem and release to geminabox'
|
38
|
+
task release_major: %i[test major publish]
|
39
|
+
|
40
|
+
task default: :test
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'lib/jekyll_eval_filter/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
host = 'https://github.com/mslinn/jekyll_eval_filter'
|
5
|
+
|
6
|
+
spec.authors = ['Mike Slinn']
|
7
|
+
spec.description = <<~END_DESC
|
8
|
+
Evaluates input. Caution! Input can be any Ruby expression.
|
9
|
+
END_DESC
|
10
|
+
spec.email = ['mslinn@mslinn.com']
|
11
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
12
|
+
spec.homepage = 'https://github.com/mslinn/jekyll_eval_filter'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.metadata = {
|
15
|
+
'allowed_push_host' => 'https://rubygems.org',
|
16
|
+
'bug_tracker_uri' => "#{host}/issues",
|
17
|
+
'changelog_uri' => "#{host}/CHANGELOG.md",
|
18
|
+
'homepage_uri' => spec.homepage,
|
19
|
+
'source_code_uri' => host,
|
20
|
+
}
|
21
|
+
spec.name = 'jekyll_eval_filter'
|
22
|
+
spec.post_install_message = <<~END_MESSAGE
|
23
|
+
|
24
|
+
Thanks for installing #{spec.name}!
|
25
|
+
|
26
|
+
END_MESSAGE
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
spec.required_ruby_version = '>= 2.6.0'
|
29
|
+
spec.summary = 'Evaluates input. Caution! Input can be any Ruby expression.'
|
30
|
+
spec.version = JekyllEvalFilter::VERSION
|
31
|
+
|
32
|
+
spec.add_dependency 'geminabox', '>= 2.2.1'
|
33
|
+
spec.add_dependency 'jekyll', '>= 3.5.0'
|
34
|
+
spec.add_dependency 'jekyll_plugin_support', '>= 0.7.0'
|
35
|
+
end
|
data/lib/evaluate.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'jekyll_plugin_logger'
|
2
|
+
|
3
|
+
# Sample Jekyll filter.
|
4
|
+
module JekyllEvalFilter
|
5
|
+
class << self
|
6
|
+
attr_accessor :logger
|
7
|
+
end
|
8
|
+
self.logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
9
|
+
|
10
|
+
# This Jekyll filter evaluates the input string and returns the result.
|
11
|
+
# Use it as a calculator or one-line Ruby program evaluator.
|
12
|
+
#
|
13
|
+
# @param input_string [String].
|
14
|
+
# @return [String] input string and the evaluation result.
|
15
|
+
# @example Use like this:
|
16
|
+
# {{ 'TODO: show typical input' | eval }} => "TODO: show output"
|
17
|
+
def evaluate(input_string)
|
18
|
+
input_string.strip!
|
19
|
+
JekyllEvalFilter.logger.debug { "input_string=#{input_string}" }
|
20
|
+
Kernel.eval input_string.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
PluginMetaLogger.instance.logger.info { 'Loaded evaluate Liquid filter.' }
|
24
|
+
end
|
25
|
+
|
26
|
+
Liquid::Template.register_filter JekyllEvalFilter
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'jekyll_plugin_logger'
|
3
|
+
require 'jekyll_plugin_support'
|
4
|
+
|
5
|
+
require_relative 'jekyll_eval_filter/version'
|
6
|
+
|
7
|
+
# Require all Ruby files in 'lib/', except this file
|
8
|
+
Dir[File.join(__dir__, '*.rb')].each do |file|
|
9
|
+
require file unless file.end_with?('/jekyll_eval_filter.rb')
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../lib/jekyll_eval_filter'
|
2
|
+
|
3
|
+
RSpec.describe JekyllEvalFilter::JekyllEvalFilter do
|
4
|
+
let(:logger) do
|
5
|
+
PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:parse_context) { TestParseContext.new }
|
9
|
+
|
10
|
+
it 'has a test' do
|
11
|
+
expect(true).to be_true
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'jekyll_plugin_logger'
|
3
|
+
require 'liquid'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'yaml'
|
6
|
+
require_relative '../lib/<%= @gem_name %>'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.filter_run :focus
|
10
|
+
# config.order = 'random'
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
|
13
|
+
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
14
|
+
config.example_status_persistence_file_path = '../spec/status_persistence.txt'
|
15
|
+
|
16
|
+
config.filter_run_when_matching focus: true
|
17
|
+
end
|
18
|
+
|
19
|
+
Registers = Struct.new(:page, :site)
|
20
|
+
|
21
|
+
# Mock for Collections
|
22
|
+
class Collections
|
23
|
+
def values
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Mock for Site
|
29
|
+
class SiteMock
|
30
|
+
attr_reader :config
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@config = YAML.safe_load(File.read('../demo/_config.yml'))
|
34
|
+
@config['env'] = { 'JEKYLL_ENV' => 'development' }
|
35
|
+
end
|
36
|
+
|
37
|
+
def collections
|
38
|
+
Collections.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class TestLiquidContext < Liquid::Context
|
43
|
+
def initialize
|
44
|
+
super
|
45
|
+
|
46
|
+
page = {
|
47
|
+
'content' => 'blah blah',
|
48
|
+
'description' => 'Jekyll plugin support demo',
|
49
|
+
'dir' => '/',
|
50
|
+
'excerpt' => nil,
|
51
|
+
'layout' => 'default',
|
52
|
+
'name' => 'index.html',
|
53
|
+
'path' => 'index.html',
|
54
|
+
'title' => 'Welcome',
|
55
|
+
'url' => '/',
|
56
|
+
}
|
57
|
+
|
58
|
+
@content = 'Interior of the tag'
|
59
|
+
@registers = Registers.new(
|
60
|
+
page,
|
61
|
+
SiteMock.new
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Mock for Liquid::ParseContent
|
67
|
+
class TestParseContext < Liquid::ParseContext
|
68
|
+
attr_reader :line_number, :registers
|
69
|
+
|
70
|
+
def initialize
|
71
|
+
super
|
72
|
+
@line_number = 123
|
73
|
+
|
74
|
+
@registers = Registers.new(
|
75
|
+
{ 'path' => 'path/to/page.html' },
|
76
|
+
SiteMock.new
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_eval_filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Slinn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geminabox
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.1
|
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.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jekyll_plugin_support
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
55
|
+
description: 'Evaluates input. Caution! Input can be any Ruby expression.
|
56
|
+
|
57
|
+
'
|
58
|
+
email:
|
59
|
+
- mslinn@mslinn.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- jekyll_eval_filter.gemspec
|
69
|
+
- lib/evaluate.rb
|
70
|
+
- lib/jekyll_eval_filter.rb
|
71
|
+
- lib/jekyll_eval_filter/version.rb
|
72
|
+
- spec/jekyll_eval_filter_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/mslinn/jekyll_eval_filter
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
bug_tracker_uri: https://github.com/mslinn/jekyll_eval_filter/issues
|
80
|
+
changelog_uri: https://github.com/mslinn/jekyll_eval_filter/CHANGELOG.md
|
81
|
+
homepage_uri: https://github.com/mslinn/jekyll_eval_filter
|
82
|
+
source_code_uri: https://github.com/mslinn/jekyll_eval_filter
|
83
|
+
post_install_message: |2+
|
84
|
+
|
85
|
+
Thanks for installing jekyll_eval_filter!
|
86
|
+
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.6.0
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubygems_version: 3.3.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Evaluates input. Caution! Input can be any Ruby expression.
|
105
|
+
test_files: []
|
106
|
+
...
|