jekyll_draft 1.1.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -5
- data/CHANGELOG.md +38 -6
- data/README.md +258 -51
- data/jekyll_draft.gemspec +3 -3
- data/lib/draft.rb +54 -0
- data/lib/draft_html.rb +27 -0
- data/lib/else.rb +19 -0
- data/lib/filters.rb +21 -0
- data/lib/if_draft.rb +27 -0
- data/lib/jekyll_draft/version.rb +2 -2
- data/lib/jekyll_draft.rb +10 -87
- data/spec/draft_spec.rb +12 -0
- data/spec/jekyll/draft_spec.rb +11 -1
- data/spec/jekyll/mocks.rb +62 -0
- data/spec/spec_helper.rb +2 -4
- data/spec/status_persistence.txt +3 -4
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d833da47df880dd897725f84046568f02e24e88a2dff0d14ec8b3c86e0d24265
|
4
|
+
data.tar.gz: 1bb026e448058d47f96f0841bd1a80bc8c217010cc00bfa628ff708bd34d2a8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5bf1572f2ac67123110e0c8cfd536c2b19d8c8f796468a0c0b18a39f5603909b70a29af4a126390980f631d61d7e32ea63566ec92603efaaa95e73306b6a180
|
7
|
+
data.tar.gz: b07fdb3abdba168e1a207a80382f6192ae142b23358f3a73d6dccfd95a24384e25932f4daa9f794942da4c1891d73ca91e5bb0c684aa5a2d81043019d5b1d4f5
|
data/.rubocop.yml
CHANGED
@@ -11,11 +11,11 @@ require:
|
|
11
11
|
AllCops:
|
12
12
|
Exclude:
|
13
13
|
- demo/_site/**/*
|
14
|
-
-
|
14
|
+
- binstub/**/*
|
15
15
|
- vendor/**/*
|
16
16
|
- Gemfile*
|
17
|
+
- _site/**/*
|
17
18
|
NewCops: enable
|
18
|
-
TargetRubyVersion: 2.6
|
19
19
|
|
20
20
|
Gemspec/DeprecatedAttributeAssignment:
|
21
21
|
Enabled: false
|
@@ -23,10 +23,12 @@ Gemspec/DeprecatedAttributeAssignment:
|
|
23
23
|
Gemspec/RequireMFA:
|
24
24
|
Enabled: false
|
25
25
|
|
26
|
+
Gemspec/RequiredRubyVersion:
|
27
|
+
Enabled: false
|
28
|
+
|
26
29
|
Layout/HashAlignment:
|
27
30
|
EnforcedColonStyle: table
|
28
|
-
|
29
|
-
- jekyll_draft.gemspec
|
31
|
+
EnforcedHashRocketStyle: table
|
30
32
|
|
31
33
|
Layout/InitialIndentation:
|
32
34
|
Exclude:
|
@@ -53,7 +55,7 @@ Metrics/BlockLength:
|
|
53
55
|
Metrics/ClassLength:
|
54
56
|
Exclude:
|
55
57
|
- spec/**/*
|
56
|
-
Max:
|
58
|
+
Max: 50
|
57
59
|
|
58
60
|
Metrics/CyclomaticComplexity:
|
59
61
|
Max: 20
|
@@ -74,6 +76,9 @@ RSpec/ExampleLength:
|
|
74
76
|
RSpec/MultipleExpectations:
|
75
77
|
Max: 15
|
76
78
|
|
79
|
+
RSpec/NoExpectationExample:
|
80
|
+
Enabled: false
|
81
|
+
|
77
82
|
Style/CommandLiteral:
|
78
83
|
Enabled: false
|
79
84
|
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,47 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 2.0.1 / 2023-11-30
|
4
|
+
|
5
|
+
* Jekyll block tags: `if_draft` and `unless_draft`.
|
6
|
+
* Jekyll inline tags: `else_if_not_draft` and `else_if_draft`.
|
7
|
+
* Jekyll inline tag `draft_html`.
|
8
|
+
* Liquid filters:
|
9
|
+
* `is_draft`
|
10
|
+
* `draft_html`
|
11
|
+
* Module `Jekyll::Draft` defines an API with the following methods:
|
12
|
+
* `draft?` returns a boolean indicating if the document passed to it is a draft.
|
13
|
+
* `draft_html` returns the same string the `draft_html` tag returns,
|
14
|
+
indicating if the document passed to it is a draft.
|
15
|
+
|
16
|
+
|
17
|
+
## 2.0.0 / 2023-11-29
|
18
|
+
|
19
|
+
* This version was published prematurely by accident.
|
20
|
+
It is broken, do not use it.
|
21
|
+
* This is a complete rewrite, incompatible with previous versions.
|
22
|
+
|
23
|
+
|
1
24
|
## 1.1.2 / 2023-02-25
|
2
|
-
|
25
|
+
|
26
|
+
* Avoids Jekyll generating the message `Deprecation: Document#published is now a key in the #data hash.`
|
27
|
+
|
3
28
|
|
4
29
|
## 1.1.1 / 2023-02-16
|
5
|
-
|
30
|
+
|
31
|
+
* Avoids Jekyll generating the message `Deprecation: Document#draft is now a key in the #data hash.`
|
32
|
+
|
6
33
|
|
7
34
|
## 1.1.0 / 2023-02-05
|
8
|
-
|
9
|
-
|
35
|
+
|
36
|
+
* Works with CSS classes instead of generating CSS styling
|
37
|
+
* Improved how unpublished documents are recognized
|
38
|
+
|
10
39
|
|
11
40
|
## 1.0.1 / 2022-08-05
|
12
|
-
|
41
|
+
|
42
|
+
* Improved how drafts are recognized
|
43
|
+
|
13
44
|
|
14
45
|
## 1.0.0 / 2022-04-02
|
15
|
-
|
46
|
+
|
47
|
+
* Initial version
|
data/README.md
CHANGED
@@ -1,112 +1,319 @@
|
|
1
|
-
jekyll_draft
|
2
|
-
|
3
|
-
|
1
|
+
# jekyll_draft [![Gem Version](https://badge.fury.io/rb/jekyll_draft.svg)](https://badge.fury.io/rb/jekyll_draft)
|
2
|
+
|
3
|
+
This Jekyll plugin provides the following:
|
4
|
+
|
5
|
+
* Jekyll block tags: `if_draft` and `unless_draft`.
|
6
|
+
* Jekyll inline tags: `else_if_not_draft` and `else_if_draft`.
|
7
|
+
These are meant for use within `if_draft` and `unless_draft`, respectively.
|
8
|
+
Both of them are identical; they are both provided so usage seems natural.
|
9
|
+
* Jekyll inline tag `draft_html`, which generates HTML that indicates if the document it is embedded within is a draft.
|
10
|
+
* Liquid filters:
|
11
|
+
* `is_draft` returns a boolean indicating if the document passed to it is a draft.
|
12
|
+
* `draft_html` returns the same string the `draft_html` tag returns,
|
13
|
+
indicating if the document passed to it is a draft.
|
14
|
+
* Module `Jekyll::Draft` defines an API that your plugin can call.
|
15
|
+
It has the following methods:
|
16
|
+
* `draft?` returns a boolean indicating if the document passed to it is a draft.
|
17
|
+
* `draft_html` returns the same string that `draft_html` tag returns;
|
18
|
+
the response indicates if the document passed to it is a draft.
|
19
|
+
* `root` returns the path to the root of the collection that the document passed to it is a member of.
|
20
|
+
This method is not functionally related to Jekyll draft documents;
|
21
|
+
it should be packaged separately ... maybe one day...
|
22
|
+
|
23
|
+
The difference between the tag called `draft_html` and the filter of the same name
|
24
|
+
is that the tag only works on the document that it is embedded in,
|
25
|
+
while the filter works on any document passed to it.
|
26
|
+
Both the tag and the filter call the same API methods defined in the `Jekyll::Draft` module.
|
27
|
+
|
28
|
+
More information is available on [Mike Slinn’s website](https://www.mslinn.com/jekyll_plugins/jekyll_draft.html).
|
4
29
|
|
5
|
-
This is a Jekyll plugin that provides two Liquid filters: `is_draft` and `draft_html`.
|
6
30
|
|
7
|
-
|
31
|
+
## Demo
|
32
|
+
|
33
|
+
The [demo](demo) subdirectory has working examples of this Jekyll plugin's functionality
|
34
|
+
in a demonstration website.
|
35
|
+
To run the demo, type:
|
36
|
+
|
37
|
+
```console
|
38
|
+
$ demo/_bin/debug -r
|
39
|
+
```
|
40
|
+
|
41
|
+
Now point your web browser to http://localhost:4444.
|
42
|
+
You should see:
|
43
|
+
|
44
|
+
![jekyll_draft demo](jekyll_draft_demo.png)
|
45
|
+
|
46
|
+
When the demonstration is running, any time you modify the <code>.html</code> files,
|
47
|
+
the demo website will regenerate.
|
48
|
+
Each time you make a change, the website instantly regenerates.
|
49
|
+
This helps the learning experience.
|
50
|
+
|
51
|
+
Please play with the contents of the <code>.html</code> files,
|
52
|
+
so you can learn how to write Jekyll pages that include this functionality.
|
8
53
|
|
9
54
|
|
10
55
|
## Installation
|
11
56
|
|
12
|
-
|
13
|
-
|
14
|
-
.jekyll_draft
|
15
|
-
background-color: #fefeab;
|
16
|
-
padding-bottom: 2px;
|
17
|
-
padding-left: 0.5em;
|
18
|
-
padding-right: 0.5em;
|
19
|
-
padding-top: 2px;
|
20
|
-
}
|
21
|
-
```
|
57
|
+
### For Use In A Jekyll Website
|
58
|
+
|
59
|
+
Add the CSS found in [`demo/assets/css/jekyll_draft.css`](demo/assets/css/jekyll_draft.css) to your Jekyll layout(s).
|
22
60
|
|
23
|
-
Add
|
61
|
+
Add the following to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
|
24
62
|
|
25
63
|
```ruby
|
26
64
|
group :jekyll_plugins do
|
27
|
-
gem 'jekyll_draft'
|
65
|
+
gem 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
|
28
66
|
end
|
29
67
|
```
|
30
68
|
|
31
|
-
And then
|
69
|
+
And then type:
|
32
70
|
|
33
|
-
|
71
|
+
```shell
|
72
|
+
$ bundle
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
### For Use In a Gem
|
77
|
+
|
78
|
+
Add the following to your gem’s `.gemspec`:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
spec.add_dependency 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
|
82
|
+
```
|
83
|
+
|
84
|
+
And then type:
|
85
|
+
|
86
|
+
```shell
|
87
|
+
$ bundle
|
88
|
+
```
|
34
89
|
|
35
90
|
|
36
91
|
## Usage
|
37
92
|
|
38
|
-
### `
|
93
|
+
### `if_draft` and `unless_draft` Block Tags
|
94
|
+
|
95
|
+
The `if_draft` block tag acts as an `if-then` or an `if-then-else` programming construct.
|
39
96
|
|
40
|
-
|
97
|
+
```html
|
98
|
+
{% if_draft %}
|
99
|
+
<p>This is a draft document!</p>
|
100
|
+
{% endif_draft %}
|
41
101
|
```
|
102
|
+
|
103
|
+
```html
|
104
|
+
{% if_draft %}
|
105
|
+
<p>This is a draft document!</p>
|
106
|
+
{% else_if_not_draft %}
|
107
|
+
<p>This is not a draft document!</p>
|
108
|
+
{% endif_draft %}
|
109
|
+
```
|
110
|
+
|
111
|
+
The `unless_draft` block tag acts as a Ruby [unless-then](https://rubystyle.guide/#unless-for-negatives) or
|
112
|
+
an [unless-then-else](https://rubystyle.guide/#no-else-with-unless) programming construct.
|
113
|
+
|
114
|
+
```html
|
115
|
+
{% unless_draft %}
|
116
|
+
<p>This is not a draft document!</p>
|
117
|
+
{% endunless_draft %}
|
118
|
+
```
|
119
|
+
|
120
|
+
```html
|
121
|
+
{% unless_draft %}
|
122
|
+
<p>This is not a draft document!</p>
|
123
|
+
{% else_if_draft %}
|
124
|
+
<p>This is a draft document!</p>
|
125
|
+
{% endunless_draft %}
|
126
|
+
```
|
127
|
+
|
128
|
+
You can use the keywords `else_if_draft` and `else_if_not_draft` interchangeably.
|
129
|
+
They are actually made by registering the same code twice with different subclass names.
|
130
|
+
Use the keyword that makes the most sense to you.
|
131
|
+
|
132
|
+
|
133
|
+
### `draft_html` Inline Tag
|
134
|
+
|
135
|
+
Here is an example of embedding the `draft_html` inline tag into an HTML document:
|
136
|
+
|
137
|
+
```html
|
138
|
+
<p>Is this a draft document? Look here to see: {% draft_html %}</p>
|
139
|
+
```
|
140
|
+
|
141
|
+
By default, `draft_html` emits ` <i class='jekyll_draft>Draft</i>` if the document is a draft,
|
142
|
+
otherwise it does not emit anything.
|
143
|
+
|
144
|
+
You can change this behavior several ways:
|
145
|
+
|
146
|
+
* Add the `published_output` parameter to specify the HTML that should be emitted if the document is not a draft.
|
147
|
+
The default message will continue to be output for draft documents when the `published_output` parameter is used.
|
148
|
+
|
149
|
+
```html
|
150
|
+
{% draft_html published_output="<p>Not a draft</p>" %}
|
151
|
+
```
|
152
|
+
|
153
|
+
* Add the `draft_output` parameter to specify the HTML that should be emitted if the document is a draft:
|
154
|
+
|
155
|
+
```html
|
156
|
+
{% draft_html
|
157
|
+
draft_output="<p>Is a draft</p>"
|
158
|
+
%}
|
159
|
+
{% draft_html
|
160
|
+
draft_output="<p>Is a draft</p>"
|
161
|
+
published_output="<p>Not a draft</p>"
|
162
|
+
%}
|
163
|
+
```
|
164
|
+
|
165
|
+
* Add the `draft_class` parameter to specify the CSS class that should be added
|
166
|
+
to the emitted HTML if the document is a draft:
|
167
|
+
|
168
|
+
```html
|
169
|
+
{% draft_html draft_class="my_draft_class" %}
|
170
|
+
{% draft_html
|
171
|
+
draft_class="my_draft_class"
|
172
|
+
published_output="<p>Not a draft</p>"
|
173
|
+
%}
|
174
|
+
```
|
175
|
+
|
176
|
+
* Add the `draft_style` parameter to specify the CSS class that should be added
|
177
|
+
to the emitted HTML if the document is a draft:
|
178
|
+
|
179
|
+
```html
|
180
|
+
{% draft_html draft_style="font-size: 24pt;" %}
|
181
|
+
{% draft_html
|
182
|
+
draft_class="my_draft_class"
|
183
|
+
draft_style="font-size: 24pt;"
|
184
|
+
%}
|
185
|
+
{% draft_html
|
186
|
+
draft_class="my_draft_class"
|
187
|
+
draft_style="font-size: 24pt;"
|
188
|
+
published_output="<p>Not a draft</p>"
|
189
|
+
%}
|
190
|
+
```
|
191
|
+
|
192
|
+
|
193
|
+
### Filters
|
194
|
+
|
195
|
+
#### `is_draft`
|
196
|
+
|
197
|
+
This filter detects if a page is invisible when published in `production` mode,
|
198
|
+
and either returns `true` or `false`.
|
199
|
+
|
200
|
+
```html
|
42
201
|
{{ page | is_draft }} => true
|
43
202
|
```
|
44
203
|
|
45
|
-
|
46
|
-
|
204
|
+
|
205
|
+
#### `draft_html`
|
206
|
+
|
207
|
+
This filter generates HTML to display if a page is invisible when published in `production` mode.
|
47
208
|
If the page is not a draft then the empty string is returned.
|
48
|
-
|
49
|
-
|
209
|
+
The generated HTML for draft pages is:<br>
|
210
|
+
`" <i class='jekyll_draft'>Draft</i>"`
|
211
|
+
|
212
|
+
```html
|
213
|
+
{{ page | draft_html }} => " <i class='jekyll_draft'>Draft</i>"
|
50
214
|
```
|
51
215
|
|
216
|
+
The optional parameters for the `draft_html` inline tag are not available for
|
217
|
+
use with the `draft_html` filter.
|
218
|
+
|
219
|
+
|
52
220
|
### Invoking From Another Jekyll Plugin
|
221
|
+
|
53
222
|
```ruby
|
54
223
|
require 'jekyll_draft'
|
55
224
|
|
56
|
-
|
225
|
+
puts 'Found a draft' if Jekyll::Draft.is_draft post
|
57
226
|
|
58
227
|
draft = Jekyll::Draft.draft_html post
|
59
228
|
```
|
60
229
|
|
61
|
-
## Demo
|
62
|
-
The [`demo`](./demo) directory contains a demonstration website, which uses the plugin.
|
63
|
-
To run, type:
|
64
|
-
```console
|
65
|
-
$ demo/_bin/debug -r
|
66
|
-
```
|
67
|
-
Now point your web browser to http://localhost:4444
|
68
230
|
|
69
231
|
|
70
232
|
## Development
|
71
233
|
|
72
|
-
|
234
|
+
### Setup
|
235
|
+
|
236
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
237
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
238
|
|
74
239
|
Install development dependencies like this:
|
75
|
-
|
76
|
-
|
240
|
+
|
241
|
+
```shell
|
242
|
+
$ BUNDLE_WITH=development bundle
|
77
243
|
```
|
78
244
|
|
79
245
|
To install this gem onto your local machine, run:
|
246
|
+
|
80
247
|
```shell
|
81
248
|
$ bundle exec rake install
|
82
249
|
```
|
83
250
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
```
|
91
|
-
The above creates a git tag for the version, commits the created tag,
|
92
|
-
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
251
|
+
### Debugging The Demo
|
252
|
+
|
253
|
+
Set breakpoints, then use the Visual Studio Code launch configuration called `Debug Demo`.
|
254
|
+
|
255
|
+
|
256
|
+
### Debugging From Another Jekyll Site
|
93
257
|
|
94
|
-
### Debugging
|
95
258
|
Run `bin/attach` and pass the directory name of a Jekyll website that has a suitable script called `_bin/debug`.
|
96
259
|
The `demo` subdirectory fits this description.
|
260
|
+
|
97
261
|
```console
|
98
262
|
$ bin/attach demo
|
99
|
-
Successfully uninstalled jekyll_draft-
|
100
|
-
|
101
|
-
jekyll_draft
|
102
|
-
|
263
|
+
Successfully uninstalled jekyll_draft-1.1.2
|
264
|
+
Successfully uninstalled jekyll_draft-2.0.0
|
265
|
+
jekyll_draft 2.0.0 built to pkg/jekyll_draft-2.0.0.gem.
|
266
|
+
jekyll_draft (2.0.0) installed.
|
267
|
+
jekyll_draft 2.0.0 built to pkg/jekyll_draft-2.0.0.gem.
|
268
|
+
jekyll_draft (2.0.0) installed.
|
269
|
+
Fetching gem metadata from https://rubygems.org/..........
|
270
|
+
Resolving dependencies...
|
271
|
+
Bundle complete! 21 Gemfile dependencies, 104 gems now installed.
|
272
|
+
Use `bundle info [gemname]` to see where a bundled gem is installed.
|
273
|
+
|
274
|
+
|
275
|
+
INFO PluginMetaLogger: Loaded else_if_draft v0.1.0 plugin.
|
276
|
+
INFO PluginMetaLogger: Loaded else_if_not_draft v0.1.0 plugin.
|
277
|
+
INFO PluginMetaLogger: Loaded String and String, v2.0.0 plugin.
|
278
|
+
INFO PluginMetaLogger: Loaded if_draft v2.0.0 plugin.
|
279
|
+
INFO PluginMetaLogger: Loaded unless_draft v2.0.0 plugin.
|
280
|
+
INFO PluginMetaLogger: Loaded String and String, v2.0.0 plugin.
|
281
|
+
INFO PluginMetaLogger: Loaded exec v1.4.2 plugin.
|
282
|
+
INFO PluginMetaLogger: Loaded noselect v1.4.2 plugin.
|
283
|
+
INFO PluginMetaLogger: Loaded pre v1.4.2 plugin.
|
284
|
+
INFO PluginMetaLogger: Loaded jekyll_pre v1.4.2 plugin.
|
285
|
+
Configuration file: /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/_config.yml
|
286
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/_site...
|
287
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/.jekyll-metadata...
|
288
|
+
Cleaner: Removing /mnt/f/work/jekyll/my_plugins/jekyll_draft/demo/.jekyll-cache...
|
289
|
+
Cleaner: Nothing to do for .sass-cache.
|
290
|
+
DEBUGGER: Debugger can attach via TCP/IP (127.0.0.1:45409)
|
291
|
+
DEBUGGER: wait for debugger connection...
|
103
292
|
```
|
293
|
+
|
104
294
|
Now attach to the debugger process.
|
105
|
-
This git repo includes a [Visual Studio Code launcher](
|
295
|
+
This git repo includes a [Visual Studio Code launcher](.vscode/launch.json) for this purpose labeled `Attach rdbg`.
|
296
|
+
It uses TCP/IP port 45409 to attach; you might need to modify that value.
|
106
297
|
|
107
298
|
Now point your web browser to http://localhost:4444
|
108
299
|
|
109
300
|
|
301
|
+
### Releasing A New Version
|
302
|
+
|
303
|
+
To release a new version,
|
304
|
+
|
305
|
+
1. Update the version number in `version.rb`.
|
306
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
307
|
+
3. Run the following:
|
308
|
+
|
309
|
+
```shell
|
310
|
+
$ bundle exec rake release
|
311
|
+
```
|
312
|
+
|
313
|
+
The above creates a git tag for the version, commits the created tag,
|
314
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
315
|
+
|
316
|
+
|
110
317
|
## Contributing
|
111
318
|
|
112
319
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_draft.
|
data/jekyll_draft.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
10
10
|
END_OF_DESC
|
11
11
|
spec.email = ['mslinn@mslinn.com']
|
12
12
|
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
13
|
-
spec.homepage = 'https://www.mslinn.com/
|
13
|
+
spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_draft.html'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.metadata = {
|
16
16
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
29
29
|
spec.required_ruby_version = '>= 2.6.0'
|
30
30
|
spec.summary = 'This Jekyll filter detects draft documents.'
|
31
31
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
|
-
spec.version =
|
32
|
+
spec.version = DraftVersion::VERSION
|
33
33
|
|
34
34
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
35
|
-
spec.add_dependency '
|
35
|
+
spec.add_dependency 'jekyll_plugin_support'
|
36
36
|
end
|
data/lib/draft.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'jekyll_plugin_logger'
|
2
|
+
|
3
|
+
# Define these methods outside of the JekyllDraft class so they can be invoked externally and tested more easily
|
4
|
+
module Jekyll
|
5
|
+
module Draft
|
6
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
7
|
+
|
8
|
+
# @return true by checking in this order:
|
9
|
+
# - document is in _drafts directory, detectable by doc['draft']==true
|
10
|
+
# - document front matter contains 'published: false'
|
11
|
+
def draft?(doc)
|
12
|
+
if doc.respond_to? :data
|
13
|
+
return !doc.data['published'] if doc.data.key? 'published'
|
14
|
+
return doc.data['draft'] if doc.data.key? 'draft'
|
15
|
+
end
|
16
|
+
if doc.respond_to? :[]
|
17
|
+
return !doc['published'] if doc.key? 'published'
|
18
|
+
return doc['draft'] if doc.key? 'draft'
|
19
|
+
end
|
20
|
+
|
21
|
+
return doc.draft if doc.respond_to? :draft
|
22
|
+
|
23
|
+
false
|
24
|
+
rescue StandardError => e
|
25
|
+
@logger.error { e }
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param doc [Jekyll::Drops::DocumentDrop]
|
30
|
+
# @return HTML that indicates if a doc is a draft or not
|
31
|
+
def draft_html(doc)
|
32
|
+
return '' unless draft? doc
|
33
|
+
|
34
|
+
" <i class='jekyll_draft'>Draft</i>"
|
35
|
+
rescue StandardError => e
|
36
|
+
@logger.error { e.full_message }
|
37
|
+
''
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return path to root of the collection that doc is a member of
|
41
|
+
def root(doc, site)
|
42
|
+
return '/index.html' unless doc.respond_to?(:collection)
|
43
|
+
|
44
|
+
collection_name = doc.collection
|
45
|
+
docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
|
46
|
+
index = docs.find { |d| d.url.end_with? 'index.html' }
|
47
|
+
return index.url if index
|
48
|
+
|
49
|
+
docs.min.url
|
50
|
+
end
|
51
|
+
|
52
|
+
module_function :draft?, :draft_html, :root
|
53
|
+
end
|
54
|
+
end
|
data/lib/draft_html.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'jekyll_plugin_support'
|
2
|
+
|
3
|
+
class DraftHtml < JekyllSupport::JekyllTag
|
4
|
+
VERSION = '0.1.0'.freeze
|
5
|
+
DRAFT_HTML = 'draft_html'.freeze unless defined? Else::VERSION
|
6
|
+
|
7
|
+
def render_impl
|
8
|
+
is_draft = Jekyll::Draft.draft?(@page)
|
9
|
+
|
10
|
+
published_output = @helper.parameter_specified? 'published_output'
|
11
|
+
return published_output if !is_draft && published_output
|
12
|
+
return unless is_draft
|
13
|
+
|
14
|
+
draft_output = @helper.parameter_specified? 'draft_output'
|
15
|
+
return draft_output if draft_output
|
16
|
+
|
17
|
+
draft_class = @helper.parameter_specified? 'class'
|
18
|
+
dc = " #{draft_class}" if draft_class
|
19
|
+
|
20
|
+
draft_style = @helper.parameter_specified? 'style'
|
21
|
+
ds = " style='#{draft_style}'" if draft_style
|
22
|
+
|
23
|
+
" <i class='jekyll_draft#{dc}'#{ds}>Draft</i>"
|
24
|
+
end
|
25
|
+
|
26
|
+
JekyllPluginHelper.register(self, DRAFT_HTML)
|
27
|
+
end
|
data/lib/else.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'jekyll_plugin_support'
|
2
|
+
|
3
|
+
class ElseBase < JekyllSupport::JekyllTag
|
4
|
+
VERSION = '0.1.0'.freeze
|
5
|
+
ELSE_DRAFT = 'else_if_draft'.freeze
|
6
|
+
ELSE_NOT_DRAFT = 'else_if_not_draft'.freeze
|
7
|
+
|
8
|
+
def render_impl
|
9
|
+
RECORD_SEPARATOR
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class ElseDraft < ElseBase
|
14
|
+
JekyllPluginHelper.register(self, ELSE_DRAFT)
|
15
|
+
end
|
16
|
+
|
17
|
+
class ElseNotDraft < ElseBase
|
18
|
+
JekyllPluginHelper.register(self, ELSE_NOT_DRAFT)
|
19
|
+
end
|
data/lib/filters.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jekyll_plugin_logger'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
# Jekyll filters that detect draft documents
|
5
|
+
module Jekyll
|
6
|
+
module DraftFilter
|
7
|
+
def is_draft(doc) # rubocop:disable Naming/PredicateName
|
8
|
+
Draft.draft? doc
|
9
|
+
end
|
10
|
+
|
11
|
+
def draft_html(doc)
|
12
|
+
Draft.draft_html doc
|
13
|
+
end
|
14
|
+
|
15
|
+
def root(doc, site)
|
16
|
+
Draft.root(doc, site)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Liquid::Template.register_filter(DraftFilter)
|
21
|
+
end
|
data/lib/if_draft.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'jekyll_plugin_support'
|
2
|
+
|
3
|
+
# Jekyll block tags that detect draft documents
|
4
|
+
class DraftBase < JekyllSupport::JekyllBlock
|
5
|
+
IF_DRAFT = 'if_draft'.freeze
|
6
|
+
UNLESS_DRAFT = 'unless_draft'.freeze
|
7
|
+
VERSION = DraftVersion::VERSION.freeze
|
8
|
+
|
9
|
+
def render_impl(content)
|
10
|
+
true_value, false_value, extra = content.split(RECORD_SEPARATOR)
|
11
|
+
raise DraftError, "Warning: More than one else clause detected" if extra
|
12
|
+
|
13
|
+
if @tag_name == IF_DRAFT
|
14
|
+
return Jekyll::Draft.draft?(@page) ? true_value : false_value
|
15
|
+
end
|
16
|
+
|
17
|
+
Jekyll::Draft.draft?(@page) ? false_value : true_value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class IfDraft < DraftBase
|
22
|
+
JekyllPluginHelper.register(self, IF_DRAFT)
|
23
|
+
end
|
24
|
+
|
25
|
+
class UnlessDraft < DraftBase
|
26
|
+
JekyllPluginHelper.register(self, UNLESS_DRAFT)
|
27
|
+
end
|
data/lib/jekyll_draft/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '
|
1
|
+
module DraftVersion
|
2
|
+
VERSION = '2.0.1'.freeze
|
3
3
|
end
|
data/lib/jekyll_draft.rb
CHANGED
@@ -1,93 +1,16 @@
|
|
1
1
|
# @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'jekyll_plugin_support'
|
4
4
|
require 'yaml'
|
5
|
+
require_relative 'jekyll_draft/version' unless defined?(VERSION)
|
5
6
|
|
6
|
-
#
|
7
|
-
|
8
|
-
# Define these methods outside of module DraftFilter so they can be invoked externally and tested easily
|
9
|
-
module Draft
|
10
|
-
# @return true if document front matter contains published that is not true,
|
11
|
-
# or document is in _drafts.
|
12
|
-
# If draft and published are both specified in front matter then published has priority.
|
13
|
-
def draft?(doc)
|
14
|
-
abort 'Jekyll::Draft.draft? doc is nil!'.red if doc.nil?
|
7
|
+
# Unicode record separator https://www.compart.com/en/unicode/U+241E
|
8
|
+
RECORD_SEPARATOR = "\u{241E}".freeze
|
15
9
|
|
16
|
-
|
10
|
+
DraftError = JekyllSupport.define_error
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return HTML that indicates if a doc is a draft or not
|
26
|
-
def draft_html(doc)
|
27
|
-
return '' unless draft?(doc)
|
28
|
-
|
29
|
-
" <i class='jekyll_draft'>Draft</i>"
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return path to root of the collection that doc is a member of
|
33
|
-
def root(doc, site)
|
34
|
-
return '/index.html' unless doc.respond_to?(:collection)
|
35
|
-
|
36
|
-
collection_name = doc.collection
|
37
|
-
docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
|
38
|
-
index = docs.find { |d| d.url.end_with? 'index.html' }
|
39
|
-
return index.url if index
|
40
|
-
|
41
|
-
docs.min.url
|
42
|
-
end
|
43
|
-
|
44
|
-
# Non-standard name used so this method could be invoked from Liquid
|
45
|
-
# @return true if published was specified in a document's front matter, and the value is false
|
46
|
-
def published_was_specified(doc)
|
47
|
-
return true if doc.respond_to?(:published)
|
48
|
-
|
49
|
-
return false unless doc.respond_to?(:data)
|
50
|
-
|
51
|
-
return true if doc.data.key?('published')
|
52
|
-
|
53
|
-
false
|
54
|
-
end
|
55
|
-
|
56
|
-
# Non-standard name used so this method could be invoked from Liquid.
|
57
|
-
# Looks in data before checking for property.
|
58
|
-
# @return true if published was specified in a document's front matter, and the value is false
|
59
|
-
def is_unpublished(doc) # rubocop:disable Naming/PredicateName
|
60
|
-
return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
|
61
|
-
|
62
|
-
return !doc.published if doc.respond_to?(:published)
|
63
|
-
|
64
|
-
return !doc['published'] if doc.key?('published')
|
65
|
-
|
66
|
-
false
|
67
|
-
end
|
68
|
-
|
69
|
-
module_function :draft?, :draft_html, :is_unpublished, :published_was_specified, :root
|
70
|
-
end
|
71
|
-
|
72
|
-
# Jekyll filters interface
|
73
|
-
module DraftFilter
|
74
|
-
def is_draft(doc) # rubocop:disable Naming/PredicateName
|
75
|
-
Draft.draft?(doc)
|
76
|
-
end
|
77
|
-
|
78
|
-
def draft_html(doc)
|
79
|
-
Draft.draft_html(doc)
|
80
|
-
end
|
81
|
-
|
82
|
-
def is_unpublished(doc) # rubocop:disable Naming/PredicateName
|
83
|
-
Draft.is_unpublished(doc)
|
84
|
-
end
|
85
|
-
|
86
|
-
def root(doc, site)
|
87
|
-
Draft.root(doc, site)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
Liquid::Template.register_filter(DraftFilter)
|
92
|
-
PluginMetaLogger.instance.info { 'Loaded DraftFilter plugin.' }
|
93
|
-
end
|
12
|
+
require_relative 'draft'
|
13
|
+
require_relative 'if_draft'
|
14
|
+
require_relative 'else'
|
15
|
+
require_relative 'draft_html'
|
16
|
+
require_relative 'filters'
|
data/spec/draft_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rspec/match_ignoring_whitespace'
|
2
|
+
require_relative 'lib/draft'
|
3
|
+
|
4
|
+
class JekyllPluginHelperOptionsTest
|
5
|
+
RSpec.describe Jekyll::Draft do
|
6
|
+
it 'does nothing' do
|
7
|
+
# TODO: mock doc
|
8
|
+
# described_class.draft? doc
|
9
|
+
expect(true).to be_truthy
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/jekyll/draft_spec.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
require 'jekyll'
|
2
2
|
require 'jekyll_plugin_logger'
|
3
|
+
require 'rspec/match_ignoring_whitespace'
|
3
4
|
require_relative '../../lib/jekyll_draft'
|
5
|
+
require_relative 'mocks'
|
4
6
|
|
5
7
|
RSpec.describe(Jekyll::Draft) do
|
6
8
|
include described_class
|
7
9
|
|
10
|
+
let(:logger) do
|
11
|
+
PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:parse_context) { TestParseContext.new }
|
15
|
+
|
8
16
|
it 'detects drafts' do
|
9
|
-
|
17
|
+
# expect(result).to match_ignoring_whitespace <<-END_RESULT
|
18
|
+
# <img src="./blah.webp">
|
19
|
+
# END_RESULT
|
10
20
|
end
|
11
21
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Registers = Struct.new(:page, :site)
|
2
|
+
|
3
|
+
# Mock for Collections
|
4
|
+
class Collections
|
5
|
+
def values
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Mock for Site
|
11
|
+
class SiteMock
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@config = YAML.safe_load(File.read('../demo/_config.yml'))
|
16
|
+
@config['env'] = { 'JEKYLL_ENV' => 'development' }
|
17
|
+
end
|
18
|
+
|
19
|
+
def collections
|
20
|
+
Collections.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Mock for Liquid::Context
|
25
|
+
class TestLiquidContext < Liquid::Context
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
|
29
|
+
page = {
|
30
|
+
"content" => "blah blah",
|
31
|
+
"description" => "Jekyll draft demo",
|
32
|
+
"dir" => "/",
|
33
|
+
"excerpt" => nil,
|
34
|
+
"layout" => "default",
|
35
|
+
"name" => "index.html",
|
36
|
+
"path" => "index.html",
|
37
|
+
"title" => "Welcome",
|
38
|
+
"url" => "/",
|
39
|
+
}
|
40
|
+
|
41
|
+
@content = "This is the content"
|
42
|
+
@registers = Registers.new(
|
43
|
+
page,
|
44
|
+
SiteMock.new
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Mock for Liquid::ParseContent
|
50
|
+
class TestParseContext < Liquid::ParseContext
|
51
|
+
attr_reader :line_number, :registers
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
super
|
55
|
+
@line_number = 123
|
56
|
+
|
57
|
+
@registers = Registers.new(
|
58
|
+
{ 'path' => 'path/to/page.html' },
|
59
|
+
SiteMock.new
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,8 @@ require 'jekyll'
|
|
2
2
|
require_relative '../lib/jekyll_draft'
|
3
3
|
|
4
4
|
RSpec.configure do |config|
|
5
|
-
config.
|
6
|
-
config.order = 'random'
|
7
|
-
config.run_all_when_everything_filtered = true
|
8
|
-
|
5
|
+
config.filter_run_when_matching focus: true
|
6
|
+
# config.order = 'random'
|
9
7
|
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
10
8
|
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
11
9
|
end
|
data/spec/status_persistence.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/
|
4
|
-
./spec/basename_dirname_spec.rb[1:2] | passed | 0.0002 seconds |
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------- | ------ | --------------- |
|
3
|
+
./spec/jekyll/draft_spec.rb[1:1] | passed | 0.00007 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_draft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: jekyll_plugin_support
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -53,19 +53,26 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
55
|
- jekyll_draft.gemspec
|
56
|
+
- lib/draft.rb
|
57
|
+
- lib/draft_html.rb
|
58
|
+
- lib/else.rb
|
59
|
+
- lib/filters.rb
|
60
|
+
- lib/if_draft.rb
|
56
61
|
- lib/jekyll_draft.rb
|
57
62
|
- lib/jekyll_draft/version.rb
|
63
|
+
- spec/draft_spec.rb
|
58
64
|
- spec/jekyll/draft_spec.rb
|
65
|
+
- spec/jekyll/mocks.rb
|
59
66
|
- spec/spec_helper.rb
|
60
67
|
- spec/status_persistence.txt
|
61
|
-
homepage: https://www.mslinn.com/
|
68
|
+
homepage: https://www.mslinn.com/jekyll_plugins/jekyll_draft.html
|
62
69
|
licenses:
|
63
70
|
- MIT
|
64
71
|
metadata:
|
65
72
|
allowed_push_host: https://rubygems.org
|
66
73
|
bug_tracker_uri: https://github.com/mslinn/jekyll_draft/issues
|
67
74
|
changelog_uri: https://github.com/mslinn/jekyll_draft/CHANGELOG.md
|
68
|
-
homepage_uri: https://www.mslinn.com/
|
75
|
+
homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_draft.html
|
69
76
|
source_code_uri: https://github.com/mslinn/jekyll_draft
|
70
77
|
post_install_message: |2+
|
71
78
|
|
@@ -85,12 +92,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
92
|
- !ruby/object:Gem::Version
|
86
93
|
version: '0'
|
87
94
|
requirements: []
|
88
|
-
rubygems_version: 3.3.
|
95
|
+
rubygems_version: 3.3.7
|
89
96
|
signing_key:
|
90
97
|
specification_version: 4
|
91
98
|
summary: This Jekyll filter detects draft documents.
|
92
99
|
test_files:
|
100
|
+
- spec/draft_spec.rb
|
93
101
|
- spec/jekyll/draft_spec.rb
|
102
|
+
- spec/jekyll/mocks.rb
|
94
103
|
- spec/spec_helper.rb
|
95
104
|
- spec/status_persistence.txt
|
96
105
|
...
|