jekyll-raise_liquid_error 0.1.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/LICENSE.md +21 -0
- data/README.md +63 -0
- data/lib/jekyll/raise_liquid_error/version.rb +7 -0
- data/lib/jekyll/raise_liquid_error.rb +18 -0
- data/lib/jekyll-raise-liquid-error.rb +7 -0
- data/spec/jekyll/raise_liquid_error_filter_spec.rb +29 -0
- data/spec/jekyll/raise_liquid_error_spec.rb +7 -0
- data/spec/spec_helper.rb +25 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a0b5c851ccefee26fa8c39fc0b609786fff793fe5543cf5491fee2d3b5ef9c9
|
4
|
+
data.tar.gz: 10c508a24d7544736c4a4d6f458a890cfa906724107ea180864f70de42b0fd0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94991749148df1be6d2a6e4a9f192ccfc62b452dde863bfeb729433b74a238f7d317edeed2a59e33fc86211280d30d32bca1317d02a882b4a9620996c4966aa2
|
7
|
+
data.tar.gz: 698ab203d4977bb2db8d1243471eee035b3bf7147b3a0dcc54eecbd28755ec58d6c380e8d1fe40e0e6b8fe7e084713b270ff846dfc18265c2ca7e5cff34b2e44
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Simon Greuter
|
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,63 @@
|
|
1
|
+
> Simple liquid filter to raise build-time errors from liquid code
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
This plugin is available as a [RubyGem][ruby-gem].
|
6
|
+
|
7
|
+
Add this line to your application's `Gemfile`:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'jekyll-raise_liquid_error'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute the `bundle` command to install the gem.
|
14
|
+
|
15
|
+
Alternatively, you can also manually install the gem using the following command:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ gem install jekyll-raise_liquid_error
|
19
|
+
```
|
20
|
+
|
21
|
+
After the plugin has been installed successfully, add the following lines to your `_config.yml` in order to tell Jekyll to use the plugin:
|
22
|
+
|
23
|
+
```
|
24
|
+
gems:
|
25
|
+
- jekyll-raise_liquid_error
|
26
|
+
```
|
27
|
+
|
28
|
+
## Getting Started
|
29
|
+
|
30
|
+
In your markup, use the `raise_error` liquid filter anywhere the compiler should never land at build time:
|
31
|
+
|
32
|
+
```
|
33
|
+
{{ 'Error Message: something is wrong with your site' | raise_error }}
|
34
|
+
```
|
35
|
+
|
36
|
+
This will make your build fail with the error message you defined along with the location of the markup file involved.
|
37
|
+
|
38
|
+
## Example usage
|
39
|
+
|
40
|
+
```
|
41
|
+
{%- if your_var != nil -%}
|
42
|
+
{{'Variable your_var expected to be nil, but was: ' | append: your_var | raise_error }}"
|
43
|
+
{%- endif -%}
|
44
|
+
```
|
45
|
+
|
46
|
+
This will fail your build (if external plugins are allowed, e.g. locally) and give you some hint what went wrong.
|
47
|
+
|
48
|
+
# Contribute
|
49
|
+
|
50
|
+
If you know anything more about ruby and can improve this snippet (e.g. adding working tests), please fork this repository and issue a pull request.
|
51
|
+
|
52
|
+
|
53
|
+
# Copyright
|
54
|
+
|
55
|
+
I just packaged this snippet from
|
56
|
+
|
57
|
+
https://stackoverflow.com/questions/43901429/raise-exceptions-during-a-jekyll-build-if-specified-yaml-fields-are-missing
|
58
|
+
|
59
|
+
to get a valid Gem. All kudos to mdlincoln.
|
60
|
+
|
61
|
+
License: MIT
|
62
|
+
|
63
|
+
[ruby-gem]: https://rubygems.org/gems/jekyll-raise_liquid_error
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "raise_liquid_error/version"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module RaiseLiquidError
|
7
|
+
module RaiseLiquidErrorFilter
|
8
|
+
|
9
|
+
def raise_error(msg)
|
10
|
+
source_file = @context.registers[:page]['path']
|
11
|
+
err_msg = "In #{source_file}: #{msg}"
|
12
|
+
raise err_msg
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Liquid::Template.register_filter(Jekyll::RaiseLiquidError::RaiseLiquidErrorFilter)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe(Jekyll::RaiseLiquidError::RaiseLiquidErrorFilter) do
|
6
|
+
|
7
|
+
let(:output) do
|
8
|
+
render_liquid(content, {'error_message' => error_message})
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: make tests work
|
12
|
+
# somehow I need to be able to inject context.registers, but don't
|
13
|
+
# know enough about ruby to do that atm
|
14
|
+
|
15
|
+
# context "Raising an unconditional error" do
|
16
|
+
# msg = "This code should never be reached!"
|
17
|
+
#
|
18
|
+
# let(:error_message) { msg }
|
19
|
+
# let(:content) { "{{ '#{error_message}' | raise_error }}" }
|
20
|
+
#
|
21
|
+
# it "produces the correct error message" do
|
22
|
+
# expect { output }
|
23
|
+
# .to(raise_error do |error|
|
24
|
+
# expect(error).to be_a(Exception)
|
25
|
+
# expect(error.message).to eq msg
|
26
|
+
# end)
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'liquid'
|
4
|
+
require "jekyll/raise_liquid_error"
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Enable flags like --only-failures and --next-failure
|
8
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
9
|
+
|
10
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
config.filter_run :focus
|
19
|
+
config.order = 'random'
|
20
|
+
|
21
|
+
def render_liquid(content, variables)
|
22
|
+
template = Liquid::Template.parse(content)
|
23
|
+
template.render(variables)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-raise_liquid_error
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Greuter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-28 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Liquid filter to raise an error during Jekyll build
|
56
|
+
email:
|
57
|
+
- 6537188+greuters@users.noreply.github.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.md
|
63
|
+
- README.md
|
64
|
+
- lib/jekyll-raise-liquid-error.rb
|
65
|
+
- lib/jekyll/raise_liquid_error.rb
|
66
|
+
- lib/jekyll/raise_liquid_error/version.rb
|
67
|
+
- spec/jekyll/raise_liquid_error_filter_spec.rb
|
68
|
+
- spec/jekyll/raise_liquid_error_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
homepage: https://github.com/greuters/jekyll-raise_liquid_error
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/greuters/jekyll-raise_liquid_error
|
75
|
+
source_code_uri: https://github.com/greuters/jekyll-raise_liquid_error
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.6.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.3.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: This plugin provides a simple liquid filter which raises an error at build
|
95
|
+
time.
|
96
|
+
test_files:
|
97
|
+
- spec/jekyll/raise_liquid_error_filter_spec.rb
|
98
|
+
- spec/jekyll/raise_liquid_error_spec.rb
|
99
|
+
- spec/spec_helper.rb
|