jekyll_draft 2.0.2 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8b48bd7048b0c4eb3836226b81c8da703f6573e5a564bf5c9ef22733be35167
4
- data.tar.gz: 0ebe1a2cbbea83bb3f47fb3e512203a6aebfde0248cff99266e74a66536c99d7
3
+ metadata.gz: 86ee1458ee28aab9d7f99d46deeff46e98a795cb6d3737a84b2e0e9f17f68632
4
+ data.tar.gz: a1abc81b94ccfdc3ee46ec312324d0d086567bbabcaa40784fca3d8d1c8415e4
5
5
  SHA512:
6
- metadata.gz: 4383047a610783981f175d29ccc86212c9b76a571ef587d06d29b487c3895e3e73737559ceeea25f4d849fe3a1fd5c64994b035378095ad355948f0bffe032b5
7
- data.tar.gz: d2b9ec0decefb9c1b238c498c5a36735b1033362ff327c3d06760c9d0ce6a4e26bd2f657758403664f0b8a04914e8ad9396bdf6f383cac031849a2534d4e89dd
6
+ metadata.gz: a70c60fa72cfb2dc9a8842e5b54ec9f0dec2746976edd90ed174990dcf24a14aadf801246258c257ac375c68fd72a518c9e9bc55bbbf975498c43d09a5a94774
7
+ data.tar.gz: 030ef794350d158b43395d957ce6f080c8497dde0db7005dacc96dd2900cacbc712c353addf1cb2443f8261e2e2fee471d9e1f39c7f7c9a758776f23a7ca56d5
data/.rubocop.yml CHANGED
@@ -55,7 +55,7 @@ Metrics/BlockLength:
55
55
  Metrics/ClassLength:
56
56
  Exclude:
57
57
  - spec/**/*
58
- Max: 50
58
+ Max: 60
59
59
 
60
60
  Metrics/CyclomaticComplexity:
61
61
  Max: 20
@@ -73,6 +73,9 @@ Naming/FileName:
73
73
  RSpec/ExampleLength:
74
74
  Max: 20
75
75
 
76
+ RSpec/IndexedLet:
77
+ Enabled: false
78
+
76
79
  RSpec/MultipleExpectations:
77
80
  Max: 15
78
81
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.1.0 / 2025-02-07
4
+
5
+ * Added ability to return a page in any collection, or those not in a collection,
6
+ whose path uniquely contains a string is a draft or not.
7
+ * Uses the binary search added in `jekyll_all_collections` v0.4.0 to find `APage`s whose `href` matches a suffix.
8
+ * Added the `bin/release_port` script that kills hung processes being debugged
9
+
10
+
3
11
  ## 2.0.2 / 2024-07-24
4
12
 
5
13
  * Compatible with `jekyll_plugin_support` v1.0.0
@@ -7,10 +15,8 @@
7
15
 
8
16
  ## 2.0.1 / 2024-02-07
9
17
 
10
- * Added Jekyll block tags `if_secret` and `unless_secret`.
11
- * Added Jekyll inline tags: `unless_draft_only`, `else_if_secret` and `else_if_not_secret`.
12
- * Added Liquid filter: `is_secret`.
13
- * Added method `draft_only?` and `secret?` to API module `Jekyll::Draft`.
18
+ * Added Jekyll inline tag: `unless_draft_only`.
19
+ * Added method `draft_only?` to API module `Jekyll::Draft`.
14
20
 
15
21
 
16
22
  ## 2.0.1 / 2023-11-30
data/README.md CHANGED
@@ -1,37 +1,39 @@
1
1
  # jekyll_draft [![Gem Version](https://badge.fury.io/rb/jekyll_draft.svg)](https://badge.fury.io/rb/jekyll_draft)
2
2
 
3
- Jekyll has various ways of specifying that a page or document is
3
+ Jekyll has various ways of specifying that a page or document will be
4
4
  visible when the website is published in `production` mode.
5
- The Jekyll documentation is scattered and incomplete regarding this topic.
6
- This plugin’s filters provide a simple means for marking draft pages in `development` mode.
7
-
8
- A secret document is a special form of a draft document.
9
- Secrets are always drafts, but not the converse.
5
+ The Jekyll documentation is scattered and incomplete regarding detecting draft pages and documents.
6
+ This plugin provides standard ways for detecting draft pages and documents.
10
7
 
11
8
  `Jekyll_draft` provides the following:
12
9
 
13
- * Jekyll block tags: `if_draft` and `unless_draft`.
14
- * Jekyll block tags: `if_secret` and `unless_secret`.
15
- * Jekyll inline tags: `else_if_not_draft`, `else_if_draft`, `else_if_not_secret` and `else_if_secret`.
16
- These are meant for use within `if_draft`, `unless_draft`, `if_secret` and `unless_secret`, respectively.
17
- Both of them are identical; they are both provided so usage seems natural.
18
- * Jekyll inline tag `draft_html`, which generates HTML that indicates if the document
19
- it is embedded within is a draft or a secret.
10
+ * Jekyll block tags: `if_draft`, `if_page_draft`, `unless_draft`, and `unless_page_draft`.
11
+ * Jekyll inline tags: `else_if_draft`, `else_if_page_draft`,
12
+ `else_unless_draft` and `else_unless_page_draft`.
13
+ These are meant for use within the above block tags.
14
+ They are all identical; they are provided so usage seems natural.
15
+ * Jekyll inline tag `draft_html`, which generates HTML that indicates if
16
+ the enclosing document or a specified is a draft.
20
17
  * Liquid filters:
21
18
  * `is_draft` returns a boolean indicating if the document passed to it is a draft.
22
- * `is_secret` returns a boolean indicating if the document passed to it is a secret.
19
+ * `page_match_is_draft` is like `is_draft`, but works on other pages.
23
20
  * `draft_html` returns the same string the `draft_html` tag returns,
24
- indicating if the document passed to it is a draft.
21
+ indicating if the <code>Jekyll::Page</code> passed to the filter is a draft.
22
+ * `page_match_draft_html` is like `draft_html` but works on other pages.
23
+ It accepts a string that will be matched against
24
+ [`APage.href`](https://github.com/mslinn/jekyll_all_collections?tab=readme-ov-file#the-apage-class)
25
+ values in <code>site.everything</code>.
25
26
  * Module `Jekyll::Draft` defines an API that your plugin can call.
26
27
  It has the following methods:
27
- * `draft?` returns a boolean indicating if the document passed to it is a draft or a secret.
28
- * `draft_only?` returns a boolean indicating if the document passed to it is a draft and not a secret.
29
- * `draft_html` returns the same string that `draft_html` tag returns;
30
- the response indicates if the document passed to it is a draft.
28
+ * `draft?` returns a boolean indicating if the object passed to it is a draft.
29
+ It handles `AllCollectionsHooks::APage` instances, `Jekyll::Page` instances,
30
+ and `Jekyll::Document` instances.
31
+ * `draft_html` accepts the same parameter types as `draft?`,
32
+ and returns the same string that `draft_html` tag returns.
33
+ The response indicates if the document passed to it is a draft.
34
+ * `page_match` returns the `APage` whose `href` uniquely ends with the string passed to it.
31
35
  * `root` returns the path to the root of the collection that the document passed to it is a member of.
32
- This method is not functionally related to Jekyll draft documents;
33
- it should be packaged separately ... maybe one day...
34
- * `secret?` returns a boolean indicating if the document passed to it is a draft.
36
+ This method is not functionally related to Jekyll draft documents.
35
37
 
36
38
  The difference between the tag called `draft_html` and the filter of the same name
37
39
  is that the tag only works on the document that it is embedded in,
@@ -48,26 +50,15 @@ To mark a blog as a draft, put it in the `_drafts` directory.
48
50
  To mark any other article as a draft, add the following to its front matter:
49
51
 
50
52
  ```text
53
+ ---
51
54
  published: false
52
- ```
53
-
54
- To mark any article (including blog posts) as a secret, add the following to its front matter:
55
-
56
- ```text
57
- secret: true
58
- ```
59
-
60
- Secret documents are a type of draft document, so the above implies:
61
-
62
- ```text
63
- published: false
64
- secret: true
55
+ ---
65
56
  ```
66
57
 
67
58
 
68
59
  ## Demo
69
60
 
70
- The [demo](demo) subdirectory has working examples of this Jekyll plugin's functionality
61
+ The [demo/](demo) subdirectory has working examples of this Jekyll plugin's functionality
71
62
  in a demonstration website.
72
63
  It can be used to debug the plugin or it can run freely.
73
64
  Please examine the <code>HTML</code> files in the demo to see how the plugin works.
@@ -102,7 +93,8 @@ so you can learn how to write Jekyll pages that include this functionality.
102
93
 
103
94
  ```ruby
104
95
  group :jekyll_plugins do
105
- gem 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
96
+ gem 'jekyll_all_collections', '>= 0.3.8'
97
+ gem 'jekyll_draft', '>=2.1.0'
106
98
  end
107
99
  ```
108
100
 
@@ -112,13 +104,16 @@ so you can learn how to write Jekyll pages that include this functionality.
112
104
  $ bundle
113
105
  ```
114
106
 
107
+ 4. Restart Jekyll.
108
+
115
109
 
116
110
  ### For Use In a Gem
117
111
 
118
112
  1. Add the following to your gem&rsquo;s `.gemspec`:
119
113
 
120
114
  ```ruby
121
- spec.add_dependency 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
115
+ spec.add_dependency 'jekyll_all_collections', '>= 0.3.8'
116
+ spec.add_dependency 'jekyll_draft', '>=2.1.0'
122
117
  ```
123
118
 
124
119
  2. Type:
@@ -128,162 +123,316 @@ so you can learn how to write Jekyll pages that include this functionality.
128
123
  ```
129
124
 
130
125
 
131
- ## Usage in a Web Page
126
+ ## Configuration
132
127
 
133
- ### `if_draft`, `unless_draft`, `if_secret` and `unless_secret` Block Tags
128
+ ### _config.yml
134
129
 
135
- The `if_draft` and `if_secret` block tags acts as `if-then` or `if-then-else` programming constructs.
130
+ The default settings run more quickly than id `verify_unique_match` is enabled,
131
+ which guarantee that no broken internal links exist.
132
+ If a Jekyll web page has hundreds or thousands of pages,
133
+ site generation can take many minutes if `verify_unique_match` is enabled.
136
134
 
137
- The following generates `<p>This is a draft or a secret document!</p>`
138
- if the document it is embedded in is a draft, and the Jekyll website generation was performed in development mode:
135
+ The following settings are the default values for `_config.yml`.
136
+ They apply to all tags defined by this plugin
137
+ (`if_draft`, `unless_draft`, `if_page_draft`, `unless_page_draft`)
138
+ except `draft_html` tag, which does not reference these settings:
139
139
 
140
- ```html
141
- {% if_draft %}
142
- <p>This is a draft or a secret document!</p>
143
- {% endif_draft %}
140
+ ```yaml
141
+ if_draft:
142
+ error_if_no_match: true
143
+ verify_unique_match: false
144
144
  ```
145
145
 
146
- The following generates `<p>This is a draft document!</p>`
147
- if the document it is embedded in is a draft and not a secret, and the Jekyll website generation was performed in development mode:
146
+ ### Environment Variables
148
147
 
149
- ```html
150
- {% if_draft_only %}
151
- <p>This is a draft document!</p>
152
- {% endif_draft %}
153
- ```
148
+ Environment variables override `_config.yml` settings.
149
+
150
+ * `if_draft_error_if_no_match` overrides `if_draft.error_if_no_match`
151
+ * `if_draft_verify_unique_match` overrides `if_draft.verify_unique_match`
152
+
153
+
154
+ ## Usage in a Web Page
155
+
156
+ This section documents the usage of the inline and block tags described [above](#top).
157
+
158
+ The `if_draft` and `if_page_draft` block tags act as `if-then` or `if-then-else` programming constructs.
159
+ Draft documents only exist in development mode.
160
+ In production mode, there is no way to programmatically detect if a draft document exists in development mode.
161
+
162
+ Thus, `if_draft` and `if_page_draft` actually mean "if in development mode and the document is a draft".
163
+
164
+ Furthermore, `unless_draft` and `unless_page_draft` actually mean "if in production mode or the document is not a draft".
165
+ These block tags act as Ruby
166
+ [`unless-then`](https://rubystyle.guide/#unless-for-negatives) and
167
+ [`unless-then-else`](https://rubystyle.guide/#no-else-with-unless) programming constructs.
154
168
 
155
- The following generates `<p>This is a secret document!</p>`
156
- if the document it is embedded in is a secret, and the Jekyll website generation was performed in development mode:
169
+ The `draft_html` inline tag generates HTML that indicates if a page is a draft or not.
170
+
171
+
172
+ ### `if_draft` and `unless_draft` Block Tags
173
+
174
+ These tags consider the status of the document that the tag is embedded in.
175
+
176
+ The <code>if_draft</code> block tag acts as an <code>if-then</code> or an <code>if-then-else</code> programming construct.
177
+
178
+ The following generates `<p>This is a draft document!</p>`
179
+ if the document it is embedded in is a draft,
180
+ and the Jekyll website generation was performed in development mode:
157
181
 
158
182
  ```html
159
- {% if_secret %}
160
- <p>This is a secret document!</p>
183
+ {% if_draft %}
184
+ <p>This is a draft document.</p>
161
185
  {% endif_draft %}
162
186
  ```
163
187
 
164
- The following enhances the previous example by also generating `<p>This is not a draft or a secret document!</p>`
165
- when in production mode:
188
+ The following enhances the previous example by generating `<p>This is not a draft document!</p>`
189
+ if the document this code is embedded in is not a draft.
190
+ The message for the else clause is generated for documents that are not drafts,
191
+ regardless of whether Jekyll is in `production` or `development` mode.
166
192
 
167
193
  ```html
168
194
  {% if_draft %}
169
- <p>This is a draft or a secret document!</p>
170
- {% else_if_not_secret %}
171
- <p>This is not a secret document, but might be a draft!</p>
195
+ <p>This is a draft document!</p>
172
196
  {% else_if_not_draft %}
173
- <p>This is not a draft or a secret document!</p>
197
+ <p>This is not a draft document!</p>
174
198
  {% endif_draft %}
175
199
  ```
176
200
 
177
- The `unless_draft`, `unless_draft_only` and `unless_secret` block tags acts as Ruby
178
- [unless-then](https://rubystyle.guide/#unless-for-negatives) or
179
- an [unless-then-else](https://rubystyle.guide/#no-else-with-unless) programming constructs.
201
+ The `unless_draft` block tag switches the then and else clauses of the `if_draft` block tag.
202
+ It acts as a Ruby [<code>unless-then</code>](https://rubystyle.guide/#unless-for-negatives) or
203
+ [<code>unless-then-else</code>](https://rubystyle.guide/#no-else-with-unless) programming construct.
180
204
 
181
205
  ```html
182
206
  {% unless_draft %}
183
- <p>This is not a draft or a secret document!</p>
207
+ <p>This is not a draft document!</p>
184
208
  {% endunless_draft %}
185
209
  ```
186
210
 
187
211
  ```html
188
- {% unless_draft_only %}
189
- <p>This is not a draft document, but might be a secret!</p>
212
+ {% unless_draft %}
213
+ <p>This is not a draft document!</p>
214
+ {% else_unless_draft %}
215
+ <p>This is a draft document!</p>
190
216
  {% endunless_draft %}
191
217
  ```
192
218
 
219
+
220
+ ### `if_page_draft` and `unless_page_draft` Block Tags
221
+
222
+ These tags consider the status of the document whose url uniquely includes the specified string.
223
+
224
+ An error is raised in `development` mode if no page exists whose URL contains the matching string.
225
+
226
+ The following generates `<p><code>/directory/blah_blah.html</code> is a draft document!</p>`
227
+ if the rendered page with a url that ends with the string `blah.html` in is a draft,
228
+ and the Jekyll website generation was performed in development mode,
229
+ and the only page with a matching URL is <code>/directory/blah_blah.html</code>:
230
+
193
231
  ```html
194
- {% unless_secret %}
195
- <p>This is not a secret document, but might be a draft!</p>
196
- {% endunless_draft %}
232
+ {% if_page_draft blah.html %}
233
+ <p><code>{{matched_page.url}}</code> is a draft document.</p>
234
+ {% endif_page_draft %}
197
235
  ```
198
236
 
199
- This is how you can specify an `else` clause for `unless_draft`:
237
+ Notice the reference to a Jekyll variable called `matched_page` in the above example.
238
+ It is set to the Jekyll `Page` whose `url` uniquely matched the string following the `if_page_draft` tag.
239
+ This variable is only defined for `development` mode within the `then` clause of the `if_page_draft` tag,
240
+ and for the `else` clause of the `unless_page_draft` block tag.
241
+
242
+ You can specify any `Page` attribute with `matched_page`, for example {{matched_page.title}}.
243
+
244
+ The following generates `<p><code>/directory/blah_blah.html</code> is not a draft document!</p>`
245
+ if the `/directory/blah_blah.html` in is a draft document,
246
+ and the Jekyll website generation was performed in development mode:
200
247
 
201
248
  ```html
202
- {% unless_draft %}
203
- <p>This is not a draft document!</p>
204
- {% else_if_draft %}
205
- <p>This is a draft document!</p>
249
+ {% unless_page_draft blah.html %}
250
+ <p><code>{{matched_page.url}}</code> is not a draft document!</p>
206
251
  {% endunless_draft %}
207
252
  ```
208
253
 
254
+ The following shows how to specify `else` clauses for `if_page_draft` and `unless_page_draft`.
255
+ Note that the `if_draft` else clause activates in `production` mode regardless of whether a page matches or not,
256
+ so you should not reference `matched_page` in an else clause without testing
257
+ [`jekyll.environment`](https://jekyllrb.com/docs/configuration/environments/).
258
+ Instead, you can reference the match string with `{{path_portion}}`:
259
+
260
+ ```html
261
+ {% if_page_draft blah.html %}
262
+ <p><code>{{matched_page.url}}</code> is a draft document!</p>
263
+ {% else_if_page_draft %}
264
+ {% if jekyll.environment == 'development' %}
265
+ <p><code>{{matched_page.url}}</code> is not a draft document!</p>
266
+ {% else %}
267
+ <p>Production mode cannot detect if <code>{{path_portion}}</code> matches a draft document or not.</p>
268
+ {% endif %}
269
+ {% endif_page_draft %}
270
+ ```
271
+
272
+ Similarly, the `unless_draft` then clause activates in `production` mode regardless of whether a page matches or not,
273
+ so you should not reference `matched_page` in a then clause without testing
274
+ [`jekyll.environment`](https://jekyllrb.com/docs/configuration/environments/).
275
+
209
276
  ```html
210
- {% unless_draft %}
211
- <p>This is not a draft document!</p>
212
- {% else_if_draft %}
213
- <p>This is a draft or a secret document!</p>
214
- {% else_if_draft_only %}
215
- <p>This is a draft document!</p>
216
- {% else_if_secret %}
217
- <p>This is a secret document!</p>
218
- {% endunless_draft %}
277
+ {% unless_page_draft blah.html %}
278
+ {% if jekyll.environment == 'development' %}
279
+ <p>The page whose URL contains <code>{{path_portion}}</code> is not a draft document!</p>
280
+ {% else %}
281
+ <p>Production mode cannot detect if <code>{{path_portion}}</code> matches a draft document or not.</p>
282
+ {% endif %}
283
+ {% else_unless_page_draft %}
284
+ <p><code>{{matched_page.url}}</code> is a draft document!</p>
285
+ {% endunless_page_draft %}
219
286
  ```
220
287
 
221
- You can use the keywords `else_if_draft` and `else_if_not_draft` interchangeably.
222
- They are actually made by registering the same code twice with different subclass names.
288
+ As with the `if_page_draft` and `unless_page_draft` examples, the above example
289
+ references scoped Jekyll variables called `matched_page` and `path_portion`.
290
+ These variables are only defined within the body of `if_page_draft` and `unless_page_draft` blocks.
291
+
292
+
293
+ ### Else Clauses
294
+
295
+ You can use the keywords
296
+ `else_if_draft`, `else_if_page_draft`, `else_unless_draft`, and `else_unless_page_draft` interchangeably.
297
+ They are actually made by registering the same code multiple times with different subclass names.
223
298
  Use the keyword that makes the most sense to you.
224
299
 
225
300
 
226
301
  ### `draft_html` Inline Tag
227
302
 
303
+ #### Default Behavior
304
+
305
+ The `draft_html` inline tag can return the status of the page it is embedded in, or any other page that exists.
306
+ Recall that draft pages do not exist in `production` mode.
307
+
228
308
  Here is an example of embedding the `draft_html` inline tag into an HTML document:
229
309
 
230
310
  ```html
231
311
  <p>Is this a draft document? Look here to see: {% draft_html %}</p>
232
312
  ```
233
313
 
234
- By default, if the document is a draft or a secret, and the Jekyll website generation was performed in development mode,
235
- `draft_html` emits ` <i class='jekyll_draft>Draft</i>` or ` <i class='jekyll_secret>Secret</i>` ,
314
+ By default, if the document is a draft, and the Jekyll website generation was performed in development mode,
315
+ `draft_html` emits ` <i class='jekyll_draft>Draft</i>`,
236
316
  otherwise it does not emit anything.
237
317
 
238
- You can change this behavior several ways:
318
+ <p>You can change this behavior in several ways:</p>
319
+
320
+ * Add the <code>draft_output</code> parameter to specify the HTML that should be
321
+ emitted if the document is a draft,
322
+ and the Jekyll website generation was performed in development mode:
323
+
324
+ ```text
325
+ {% draft_html
326
+ draft_output="<p>Is a draft</p>"
327
+ %}
328
+
329
+ {% draft_html
330
+ draft_output="<p>Is a draft</p>"
331
+ published_output="<p>Not a draft</p>"
332
+ %}
333
+ ```
334
+
335
+ * Add the <code>published_output</code> parameter to specify the HTML that
336
+ should be emitted if the document is not a draft.
337
+ The default message will continue to be output for draft documents when the
338
+ <code>published_output</code> parameter is used.
339
+
340
+ ```text
341
+ {% draft_html published_output="<p>Not a draft</p>" %}
342
+ ```
239
343
 
240
- * Add the `published_output` parameter to specify the HTML that should be emitted if the document is not a draft or a secret,
344
+ * Add the <code>draft_class</code> parameter to specify the CSS class that should be added
345
+ to the emitted HTML if the document is a draft,
346
+ and the Jekyll website generation was performed in development mode:
347
+
348
+ ```text
349
+ {% draft_html draft_class="my_draft_class" %}
350
+
351
+ {% draft_html
352
+ draft_class="my_draft_class"
353
+ published_output="<p>Not a draft</p>"
354
+ %}
355
+ ```
356
+
357
+ * Add the <code>draft_style</code> parameter to specify the CSS class that should be added
358
+ to the emitted HTML if the document is a draft,
359
+ and the Jekyll website generation was performed in development mode:
360
+
361
+ ```text
362
+ {% draft_html draft_style="font-size: 24pt;" %}
363
+
364
+ {% draft_html
365
+ draft_class="my_draft_class"
366
+ draft_style="font-size: 24pt;"
367
+ %}
368
+
369
+ {% draft_html
370
+ draft_class="my_draft_class"
371
+ draft_style="font-size: 24pt;"
372
+ published_output="<p>Not a draft</p>"
373
+ %}
374
+ ```
375
+
376
+
377
+ #### Testing Another Page
378
+
379
+ The `path_portion` option enables the `draft_html` tag to report on the draft status
380
+ of other pages when Jekyll is in `development` mode.
381
+ By default, an empty string is always returned when in `production` mode.
382
+
383
+ ```html
384
+ <p>
385
+ Is <code>/directory/blah_blah.html</code> a draft document?
386
+ Look here to see: {% draft_html path_portion='blah.html' %}
387
+ </p>
388
+ ```
389
+
390
+ It might be desirable to enclose the above in a test for Jekyll mode as follows:
391
+
392
+ ```html
393
+ {% if jekyll.environment == "development" %}
394
+ <p>
395
+ Is <code>/directory/blah_blah.html</code> a draft document?
396
+ Look here to see: {% draft_html path_portion='blah.html' %}
397
+ </p>
398
+ {% endif %}
399
+ ```
400
+
401
+
402
+ #### Additional Options
403
+
404
+ In addition to the `path_portion` option, the following can be also be specified:
405
+
406
+ * Add the `published_output` parameter to specify the HTML that should be emitted if the document is not a draft,
241
407
  and the Jekyll website generation was performed in development mode.
242
408
  The default message will continue to be output for draft documents when the `published_output` parameter is used.
243
409
 
244
410
  ```html
245
- {% draft_html published_output="<p>Not a draft or a secret</p>" %}
411
+ {% draft_html published_output="<p>Not a draft</p>" %}
246
412
  ```
247
413
 
248
414
  * Add the `draft_output` parameter to specify the HTML that should be emitted if the document is a draft,
249
- the `secret_output` parameter to specify the HTML that should be emitted if the document is a secret,
250
415
  and the Jekyll website generation was performed in development mode:
251
416
 
252
417
  ```html
253
418
  {% draft_html
254
- draft_output="<p>Is a draft</p>"
255
- %}
256
- {% draft_html
257
- draft_output="<p>Is a draft</p>"
258
- published_output="<p>Not a draft</p>"
259
- %}
260
- {% draft_html
261
- secret_output="<p>Is a secret</p>"
419
+ draft_output="<p>Is a draft</p>"
262
420
  %}
263
421
  {% draft_html
264
- draft_output="<p>Is a draft</p>"
265
- published_output="<p>Not a draft or a secret</p>"
266
- secret_output="<p>Is a secret</p>"
422
+ draft_output="<p>Is a draft</p>"
423
+ published_output="<p>Not a draft</p>"
267
424
  %}
268
425
  ```
269
426
 
270
427
  * Add the `draft_class` parameter to specify the CSS class that should be added
271
- to the emitted HTML if the document is a draft,
272
- add the `secret_class` parameter to specify the CSS class that should be added
273
- to the emitted HTML if the document is a secret,
428
+ to the emitted HTML if the document is a draft
274
429
  and the Jekyll website generation was performed in development mode:
275
430
 
276
431
  ```html
277
432
  {% draft_html draft_class="my_draft_class" %}
278
433
  {% draft_html
279
- draft_class="my_draft_class"
280
- published_output="<p>Not a draft or a secret</p>"
281
- %}
282
- {% draft_html draft_class="my_draft_class" secret_class="my_secret_class" %}
283
- {% draft_html
284
- draft_class="my_draft_class"
285
- published_output="<p>Not a draft or a secret</p>"
286
- secret_class="my_secret_class"
434
+ draft_class="my_draft_class"
435
+ published_output="<p>Not a draft</p>"
287
436
  %}
288
437
  ```
289
438
 
@@ -293,19 +442,14 @@ and the Jekyll website generation was performed in development mode:
293
442
 
294
443
  ```html
295
444
  {% draft_html draft_style="font-size: 24pt;" %}
296
- {% draft_html secret_style="font-size: 24pt; color: red;" %}
297
445
  {% draft_html
298
- draft_class="my_draft_class"
299
- draft_style="font-size: 24pt;"
300
- secret_class="my_secret_class"
301
- secret_style="font-size: 24pt; color: red;"
446
+ draft_class="my_draft_class"
447
+ draft_style="font-size: 24pt;"
302
448
  %}
303
449
  {% draft_html
304
- draft_class="my_draft_class"
305
- draft_style="font-size: 24pt;"
306
- published_output="<p>Not a draft or a secret</p>"
307
- secret_class="my_secret_class"
308
- secret_style="font-size: 24pt; color: red;"
450
+ draft_class="my_draft_class"
451
+ draft_style="font-size: 24pt;"
452
+ published_output="<p>Not a draft</p>"
309
453
  %}
310
454
  ```
311
455
 
@@ -315,7 +459,7 @@ and the Jekyll website generation was performed in development mode:
315
459
  #### `draft_html`
316
460
 
317
461
  By default, the draft_html Liquid filter generates HTML if a page is invisible when published in `production` mode.
318
- If the page is not a draft then the empty string is returned.
462
+ If the page is not a draft, then the empty string is returned.
319
463
 
320
464
  The optional parameters for the `draft_html` inline tag are not available for
321
465
  use with the `draft_html` filter.
@@ -323,14 +467,10 @@ use with the `draft_html` filter.
323
467
  The default generated HTML for draft pages is:<br>
324
468
  `" <i class='jekyll_draft'>Draft</i>"`
325
469
 
326
- The default generated HTML for secret pages is:<br>
327
- `" <i class='jekyll_secret'>Secret</i>"`
328
-
329
- Invoke the filter like the following; the output depends on whether the document is a draft or a secret:
470
+ Invoke the filter like the following; the output depends on whether the document is a draft:
330
471
 
331
472
  ```html
332
473
  {{ page | draft_html }} => " <i class='jekyll_draft'>Draft</i>"
333
- {{ page | draft_html }} => " <i class='jekyll_secret'>Secret</i>"
334
474
  ```
335
475
 
336
476
  Here is a code snippet that shows the <code>draft_html</code> filter in use:
@@ -347,33 +487,35 @@ Here is a code snippet that shows the <code>draft_html</code> filter in use:
347
487
  ```
348
488
 
349
489
 
350
- #### `is_draft`
490
+ #### `page_match_draft_html`
351
491
 
352
- This filter detects if a page is invisible when published in `production` mode,
353
- and either returns `true` or `false`.
492
+ This filter detects if the page whose URL uniquely contains a string is
493
+ invisible when published in `production` mode,
494
+ and returns the same strings that `draft_html` returns.
354
495
 
355
496
  ```html
356
- {{ page | is_draft }} <!-- true for draft and secret documents in development mode -->
497
+ {{ "unpublished.html" | page_match_draft_html }}
357
498
  ```
358
499
 
359
500
 
360
- #### `is_draft_only`
501
+ #### `is_draft`
361
502
 
362
503
  This filter detects if a page is invisible when published in `production` mode,
363
- and either returns `true` or `false`.
504
+ and returns `true` or `false`.
364
505
 
365
506
  ```html
366
- {{ page | is_draft_only }} <!-- true for draft documents in development mode, but not secret documents -->
507
+ {{ page | is_draft }} <!-- true for draft documents in development mode -->
367
508
  ```
368
509
 
369
510
 
370
- #### `is_secret`
511
+ #### `page_match_is_draft`
371
512
 
372
- This filter detects if a page is invisible when published in `production` mode,
373
- and either returns `true` or `false`.
513
+ This filter detects if the page whose URL uniquely contains a string is
514
+ invisible when published in `production` mode,
515
+ and returns `true` or `false`.
374
516
 
375
517
  ```html
376
- {{ page | is_secret }} <!-- true for secret documents in development mode, but not draft documents -->
518
+ {{ "unpublished.html" | page_match_is_draft }}
377
519
  ```
378
520
 
379
521
 
@@ -382,13 +524,13 @@ and either returns `true` or `false`.
382
524
  ```ruby
383
525
  require 'jekyll_draft'
384
526
 
385
- puts 'Found a draft or a secret' if Jekyll::Draft.is_draft post
527
+ puts 'Found a draft' if Jekyll::Draft.draft? post
386
528
 
387
- draft_or_secret = Jekyll::Draft.draft_html post
529
+ draft = Jekyll::Draft.draft_html post
388
530
  ```
389
531
 
390
532
 
391
- ## Usage in a Plugin
533
+ ### Usage in a Plugin
392
534
 
393
535
  The methods in `lib/draft_html.rb` can be invoked by qualifying them with `Jekyll::Draft`.
394
536
  Here is a complete example of a Jekyll Support plugin that displays an indication of whether the page is a draft or not:
data/jekyll_draft.gemspec CHANGED
@@ -3,15 +3,15 @@ require_relative 'lib/jekyll_draft/version'
3
3
  Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
4
4
  github = 'https://github.com/mslinn/jekyll_draft'
5
5
 
6
- spec.authors = ['Mike Slinn']
7
- spec.bindir = 'exe'
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
8
8
  spec.description = <<~END_OF_DESC
9
9
  This Jekyll filter detects draft documents.
10
10
  END_OF_DESC
11
- spec.email = ['mslinn@mslinn.com']
12
- spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
13
  spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_draft.html'
14
- spec.license = 'MIT'
14
+ spec.license = 'MIT'
15
15
  spec.metadata = {
16
16
  'allowed_push_host' => 'https://rubygems.org',
17
17
  'bug_tracker_uri' => "#{github}/issues",
@@ -19,18 +19,19 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
19
19
  'homepage_uri' => spec.homepage,
20
20
  'source_code_uri' => github,
21
21
  }
22
- spec.name = 'jekyll_draft'
22
+ spec.name = 'jekyll_draft'
23
+ spec.platform = Gem::Platform::RUBY
23
24
  spec.post_install_message = <<~END_MESSAGE
24
25
 
25
26
  Thanks for installing #{spec.name}!
26
27
 
27
28
  END_MESSAGE
28
- spec.require_paths = ['lib']
29
+ spec.require_paths = ['lib']
29
30
  spec.required_ruby_version = '>= 2.6.0'
30
- spec.summary = 'This Jekyll filter detects draft documents.'
31
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
32
- spec.version = DraftVersion::VERSION
31
+ spec.summary = 'This Jekyll filter detects draft documents.'
32
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
+ spec.version = DraftVersion::VERSION
33
34
 
34
35
  spec.add_dependency 'jekyll', '>= 3.5.0'
35
- spec.add_dependency 'jekyll_plugin_support', '>=1.0.0'
36
+ spec.add_dependency 'jekyll_plugin_support', '>=1.1.0'
36
37
  end
@@ -1,11 +1,12 @@
1
- require 'jekyll_plugin_support'
2
-
3
1
  class DraftHtml < JekyllSupport::JekyllTag
4
2
  VERSION = '0.1.0'.freeze
5
3
  DRAFT_HTML = 'draft_html'.freeze unless defined? Else::VERSION
6
4
 
7
5
  def render_impl
8
- is_draft = Jekyll::Draft.draft?(@page)
6
+ path_portion = @helper.parameter_specified? 'path_portion'
7
+ page = path_portion ? page_match(path_portion) : @page
8
+
9
+ is_draft = Jekyll::Draft.draft? page
9
10
 
10
11
  published_output = @helper.parameter_specified? 'published_output'
11
12
  return published_output if !is_draft && published_output
@@ -0,0 +1,35 @@
1
+ require 'jekyll_plugin_support'
2
+
3
+ class ElseBase < JekyllSupport::JekyllTag
4
+ VERSION = '0.1.0'.freeze
5
+
6
+ ELSE_DRAFT = 'else_if_draft'.freeze
7
+ ELSE_IF_NOT_DRAFT = 'else_if_not_draft'.freeze
8
+ ELSE_IF_PAGE_DRAFT = 'else_if_page_draft'.freeze
9
+ ELSE_UNLESS_DRAFT = 'else_unless_draft'.freeze
10
+ ELSE_UNLESS_PAGE_DRAFT = 'else_unless_page_draft'.freeze
11
+
12
+ def render_impl
13
+ RECORD_SEPARATOR
14
+ end
15
+ end
16
+
17
+ class ElseDraft < ElseBase
18
+ ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_DRAFT, quiet: true)
19
+ end
20
+
21
+ class ElseNotDraft < ElseBase
22
+ ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_IF_NOT_DRAFT, quiet: true)
23
+ end
24
+
25
+ class ElsePageDraft < ElseBase
26
+ ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_IF_PAGE_DRAFT, quiet: true)
27
+ end
28
+
29
+ class ElseUnlessDraft < ElseBase
30
+ ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_UNLESS_DRAFT, quiet: true)
31
+ end
32
+
33
+ class ElseUnlessPageDraft < ElseBase
34
+ ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_UNLESS_PAGE_DRAFT, quiet: true)
35
+ end
@@ -1,9 +1,6 @@
1
- require 'jekyll_plugin_logger'
2
- require 'yaml'
3
-
4
- # Jekyll filters that detect draft documents
1
+ # Jekyll filters that detects if the containing page is a draft document
5
2
  module Jekyll
6
- module DraftFilter
3
+ module ContainingPageFilters
7
4
  def is_draft(doc) # rubocop:disable Naming/PredicateName
8
5
  Draft.draft? doc
9
6
  end
@@ -17,5 +14,5 @@ module Jekyll
17
14
  end
18
15
  end
19
16
 
20
- Liquid::Template.register_filter(DraftFilter)
17
+ Liquid::Template.register_filter(ContainingPageFilters)
21
18
  end
@@ -0,0 +1,90 @@
1
+ # Define these methods outside of the JekyllDraft class so they can be invoked externally and tested more easily
2
+ module Jekyll
3
+ module Draft
4
+ class << self
5
+ attr_accessor :logger
6
+ end
7
+ Draft.logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
8
+
9
+ # @parameter doc [AllCollectionsHooks::APage|Jekyll::Page|Jekyll::Document]
10
+ # @return true by checking in this order:
11
+ # - document is in _drafts directory, detectable by doc['draft']==true
12
+ # - document front matter contains 'published: false'
13
+ def draft?(doc)
14
+ if doc.respond_to?(:data) && doc.data.respond_to?(:key?)
15
+ return !doc.data['published'] if doc.data.key? 'published'
16
+ return doc.data['draft'] if doc.data.key? 'draft'
17
+ end
18
+ if doc.respond_to?(:key?)
19
+ return !doc['published'] if doc.key? 'published'
20
+ return doc['draft'] if doc.key? 'draft'
21
+ end
22
+
23
+ return doc.draft if doc.respond_to? :draft
24
+
25
+ false
26
+ rescue StandardError => e
27
+ Draft.logger.error { e.full_message }
28
+ false
29
+ end
30
+
31
+ # @param doc [Jekyll::Drops::DocumentDrop]
32
+ # @return HTML that indicates if a doc is a draft or not
33
+ def draft_html(doc)
34
+ return '' unless draft? doc
35
+
36
+ " <i class='jekyll_draft'>Draft</i>"
37
+ rescue StandardError => e
38
+ Draft.logger.error { e.full_message }
39
+ ''
40
+ end
41
+
42
+ # This is a computationally intense method, and really slows down site generation.
43
+ # TODO: implement cache in front of sorted objects containing paths and page reference
44
+ # This cache is also needed by compute_link_and_text in jekyll_href
45
+ # @return APage whose href uniquely contains path_portion,
46
+ # or `path_portion` as a String for non-local URLs.
47
+ def page_match(path_portion, error_if_no_match: true, verify_unique_match: false)
48
+ return :non_local_url if path_portion.start_with? 'http:', 'https:', 'mailto'
49
+
50
+ matching_pages = if verify_unique_match
51
+ ::AllCollectionsHooks.sorted_lru_files.select path_portion
52
+ else
53
+ match = ::AllCollectionsHooks.sorted_lru_files.find path_portion
54
+ match.nil? ? [] : [match]
55
+ end
56
+ case matching_pages.length
57
+ when 0
58
+ return '' unless error_if_no_match
59
+
60
+ Draft.logger.error do
61
+ "No page or asset path has a href that includes the string '#{path_portion}'"
62
+ end
63
+ exit! 1 if @error_if_no_match
64
+ when 1
65
+ matching_pages.first
66
+ else
67
+ Draft.logger.error do # :\n #{matching_pages.map(&:href).join("\n ")}
68
+ "More than one page or asset path has a href that includes the string '#{path_portion}'"
69
+ end
70
+ exit! 2 # The user should fix this problem before allowing the website to generate
71
+ end
72
+ rescue StandardError => e
73
+ puts e.full_message
74
+ end
75
+
76
+ # @return path to root of the collection that doc is a member of
77
+ def root(doc, site)
78
+ return '/index.html' unless doc.respond_to?(:collection)
79
+
80
+ collection_name = doc.collection
81
+ docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
82
+ index = docs.find { |d| d.href.end_with? 'index.html' }
83
+ return index.href if index
84
+
85
+ docs.min.href
86
+ end
87
+
88
+ module_function :draft?, :draft_html, :page_match, :root
89
+ end
90
+ end
@@ -1,5 +1,3 @@
1
- require 'jekyll_plugin_support'
2
-
3
1
  # Jekyll block tags that detect draft documents
4
2
  class DraftBase < JekyllSupport::JekyllBlock
5
3
  IF_DRAFT = 'if_draft'.freeze
@@ -8,7 +6,7 @@ class DraftBase < JekyllSupport::JekyllBlock
8
6
 
9
7
  def render_impl(content)
10
8
  true_value, false_value, extra = content.split(RECORD_SEPARATOR)
11
- raise DraftError, "Warning: More than one else clause detected" if extra
9
+ raise DraftError, 'Warning: More than one else clause detected' if extra
12
10
 
13
11
  if @tag_name == IF_DRAFT
14
12
  return ::Jekyll::Draft.draft?(@page) ? true_value : false_value
@@ -23,5 +21,5 @@ class IfDraft < DraftBase
23
21
  end
24
22
 
25
23
  class UnlessDraft < DraftBase
26
- ::JekyllSupport::JekyllPluginHelper.register(self, UNLESS_DRAFT)
24
+ ::JekyllSupport::JekyllPluginHelper.register(self, UNLESS_DRAFT, quiet: true)
27
25
  end
@@ -0,0 +1,14 @@
1
+ # Jekyll filters that detect if the page that uniquely contains a string is a draft document
2
+ module Jekyll
3
+ module OtherPageFilters
4
+ def page_match_is_draft(path_portion)
5
+ Draft.draft? Draft.page_match path_portion
6
+ end
7
+
8
+ def page_match_draft_html(path_portion)
9
+ Draft.draft_html Draft.page_match path_portion
10
+ end
11
+ end
12
+
13
+ Liquid::Template.register_filter(OtherPageFilters)
14
+ end
@@ -0,0 +1,95 @@
1
+ # Jekyll block tags that detect draft documents
2
+ class DraftPageBase < JekyllSupport::JekyllBlock
3
+ IF_DRAFT = 'if_page_draft'.freeze
4
+ UNLESS_DRAFT = 'unless_page_draft'.freeze
5
+ VERSION = DraftVersion::VERSION.freeze
6
+
7
+ # Content has a true clause, and optionally might have an else clause
8
+ # Clauses can reference two variables: path_portion and matched_page
9
+ # path_portion is specified as the sole argument to this block tag
10
+ # matched_path is the APage with an href that uniquely includes path_portion,
11
+ # or nil if no matching APage was found
12
+ def render_impl(content)
13
+ true_content, false_content, extra_content = content.split(RECORD_SEPARATOR)
14
+ raise DraftError, 'Warning: More than one else clause detected' if extra_content
15
+
16
+ @path_portion = @argument_string.strip
17
+ raise DraftError, 'Error: path_portion was not specified' unless @path_portion
18
+
19
+ configure
20
+
21
+ @matched_page = if @path_portion.start_with?('#')
22
+ @page
23
+ else
24
+ Jekyll::Draft.page_match(@path_portion, error_if_no_match: @error_if_no_match,
25
+ verify_unique_match: @verify_unique_match)
26
+ end
27
+ raise DraftError, "Error: path_portion='#{@path_portion}' does not specify a local page." if @matched_page == :non_local_url
28
+
29
+ is_draft = Jekyll::Draft.draft? @matched_page
30
+ clause_value = if @tag_name == IF_DRAFT
31
+ is_draft ? true_content : false_content
32
+ else # UNLESS_DRAFT
33
+ is_draft ? false_content : true_content
34
+ end
35
+ process_variables clause_value
36
+ rescue StandardError => e
37
+ puts e.full_message
38
+ exit!
39
+ end
40
+
41
+ private
42
+
43
+ def configure
44
+ tag_config = @config['if_draft']
45
+ if tag_config
46
+ @error_if_no_match = tag_config['error_if_no_match'] # defaults true
47
+ @error_if_no_match = @error_if_no_match ? @error_if_no_match == true : true
48
+
49
+ @verify_unique_match = tag_config['verify_unique_match'] == true # defaults false
50
+ else
51
+ @logger.warn { "There is no entry for #{@tag_name} in _config.yml; default values were applied." }
52
+ end
53
+
54
+ env_var = ENV.fetch('if_draft_error_if_no_match', nil) # Environment variable overrides _config.yml setting
55
+ @error_if_no_match = env_var != 'false' if env_var
56
+
57
+ env_var = ENV.fetch('if_draft_verify_unique_match', nil) # Environment variable overrides _config.yml setting
58
+ @verify_unique_match = env_var != 'false' if env_var
59
+ end
60
+
61
+ def process_variables(markup)
62
+ return '' unless markup
63
+
64
+ path_portion = @path_portion # add this to the binding
65
+ matched_page = @matched_page # add this to the binding
66
+ _ = path_portion == matched_page # Just to keep the lint checker happy
67
+ markup.gsub!(/(<<([^<>]*)>>)/) do
68
+ token = Regexp.last_match[1] # gsub replaces token with the return value of this block
69
+ expression = Regexp.last_match[2]
70
+ if expression == 'matched_page' && matched_page.class != String
71
+ @logger.warn do
72
+ expression = 'matched_page.href'
73
+ <<~END_MSG
74
+ The expression #{token} should either specify a property, for example <<matched_page.href>>,
75
+ or a hash value, for example <<matched_page['title']>>.
76
+ The expression was modified to <<matched_page.href>> for you.
77
+ END_MSG
78
+ end
79
+ end
80
+ result = eval expression, binding # rubocop:disable Security/Eval
81
+ result.to_s
82
+ end
83
+ markup
84
+ rescue StandardError => e
85
+ @logger.error { e.full_message }
86
+ end
87
+ end
88
+
89
+ class IfPageDraft < DraftPageBase
90
+ JekyllSupport::JekyllPluginHelper.register(self, IF_DRAFT, quiet: true)
91
+ end
92
+
93
+ class UnlessPageDraft < DraftPageBase
94
+ JekyllSupport::JekyllPluginHelper.register(self, UNLESS_DRAFT, quiet: true)
95
+ end
@@ -1,3 +1,3 @@
1
1
  module DraftVersion
2
- VERSION = '2.0.2'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
data/lib/jekyll_draft.rb CHANGED
@@ -9,8 +9,15 @@ RECORD_SEPARATOR = "\u{241E}".freeze
9
9
 
10
10
  DraftError = JekyllSupport.define_error
11
11
 
12
- require_relative 'draft'
13
- require_relative 'if_draft'
14
- require_relative 'else'
15
- require_relative 'draft_html'
16
- require_relative 'filters'
12
+ # Common code
13
+ require_relative 'jekyll_draft/common/draft_html'
14
+ require_relative 'jekyll_draft/common/else'
15
+ require_relative 'jekyll_draft/common/filters'
16
+ require_relative 'jekyll_draft/common/module_functions'
17
+
18
+ # Code related to processing other pages
19
+ require_relative 'jekyll_draft/other_page/filters'
20
+ require_relative 'jekyll_draft/other_page/if_draft'
21
+
22
+ # Code related to processing the containing page
23
+ require_relative 'jekyll_draft/containing_page/if_draft'
data/spec/jekyll/mocks.rb CHANGED
@@ -31,6 +31,7 @@ class TestLiquidContext < Liquid::Context
31
31
  "description" => "Jekyll draft demo",
32
32
  "dir" => "/",
33
33
  "excerpt" => nil,
34
+ "href" => "/index.html",
34
35
  "layout" => "default",
35
36
  "name" => "index.html",
36
37
  "path" => "index.html",
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_draft
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
10
+ date: 2025-02-07 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: jekyll
@@ -30,14 +29,14 @@ dependencies:
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 1.0.0
32
+ version: 1.1.0
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 1.0.0
39
+ version: 1.1.0
41
40
  description: 'This Jekyll filter detects draft documents.
42
41
 
43
42
  '
@@ -53,12 +52,14 @@ files:
53
52
  - README.md
54
53
  - Rakefile
55
54
  - 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
61
55
  - lib/jekyll_draft.rb
56
+ - lib/jekyll_draft/common/draft_html.rb
57
+ - lib/jekyll_draft/common/else.rb
58
+ - lib/jekyll_draft/common/filters.rb
59
+ - lib/jekyll_draft/common/module_functions.rb
60
+ - lib/jekyll_draft/containing_page/if_draft.rb
61
+ - lib/jekyll_draft/other_page/filters.rb
62
+ - lib/jekyll_draft/other_page/if_draft.rb
62
63
  - lib/jekyll_draft/version.rb
63
64
  - spec/draft_spec.rb
64
65
  - spec/jekyll/draft_spec.rb
@@ -92,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubygems_version: 3.5.16
96
- signing_key:
96
+ rubygems_version: 3.6.3
97
97
  specification_version: 4
98
98
  summary: This Jekyll filter detects draft documents.
99
99
  test_files:
data/lib/draft.rb DELETED
@@ -1,54 +0,0 @@
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/else.rb DELETED
@@ -1,19 +0,0 @@
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
- ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_DRAFT)
15
- end
16
-
17
- class ElseNotDraft < ElseBase
18
- ::JekyllSupport::JekyllPluginHelper.register(self, ELSE_NOT_DRAFT)
19
- end