jekyll_draft 2.0.0 → 2.0.1

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: 5123990f175f9d09091e7f092a202b075067497e9b17dabf3eda397c48d9b11e
4
- data.tar.gz: 80f3912e94858f6ccc373d2a155f0b6f907c79c13ea6bb8495837d019656508b
3
+ metadata.gz: d833da47df880dd897725f84046568f02e24e88a2dff0d14ec8b3c86e0d24265
4
+ data.tar.gz: 1bb026e448058d47f96f0841bd1a80bc8c217010cc00bfa628ff708bd34d2a8d
5
5
  SHA512:
6
- metadata.gz: 406222aeae0160d0ff1ef9c5c5d5ad9af0a4f357541dd43742a58c229bc6094343960c215efd498cee33d37fb76457aac1e6d0d5183c4f16277cbf044f4c0f79
7
- data.tar.gz: eed26a657a04c4907700ef805fb41d67b2ed4842058f12918d3231035c46b2c6fe7c17b065a3a8c625410401f5376c86d3db4d40f607baa7e8c89320f623d6f5
6
+ metadata.gz: b5bf1572f2ac67123110e0c8cfd536c2b19d8c8f796468a0c0b18a39f5603909b70a29af4a126390980f631d61d7e32ea63566ec92603efaaa95e73306b6a180
7
+ data.tar.gz: b07fdb3abdba168e1a207a80382f6192ae142b23358f3a73d6dccfd95a24384e25932f4daa9f794942da4c1891d73ca91e5bb0c684aa5a2d81043019d5b1d4f5
data/CHANGELOG.md CHANGED
@@ -1,9 +1,24 @@
1
1
  # Change Log
2
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
+
3
17
  ## 2.0.0 / 2023-11-29
4
18
 
5
- * Made into a Jekyll block tag, because the filter implementation had problems with infinite recursing Jekyll exerpts.
6
- This was a complete rewrite, incompatible with previous version.
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.
7
22
 
8
23
 
9
24
  ## 1.1.2 / 2023-02-25
data/README.md CHANGED
@@ -1,33 +1,87 @@
1
1
  # jekyll_draft [![Gem Version](https://badge.fury.io/rb/jekyll_draft.svg)](https://badge.fury.io/rb/jekyll_draft)
2
2
 
3
- This is a Jekyll plugin that provides two Liquid filters: `is_draft` and `draft_html`.
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
- More information is available on my website about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#draft).
30
+
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.
6
53
 
7
54
 
8
55
  ## Installation
9
56
 
10
- Add the following to your CSS:
57
+ ### For Use In A Jekyll Website
11
58
 
12
- ```css
13
- .jekyll_draft {
14
- background-color: #fefeab;
15
- padding-bottom: 2px;
16
- padding-left: 0.5em;
17
- padding-right: 0.5em;
18
- padding-top: 2px;
19
- }
20
- ```
59
+ Add the CSS found in [`demo/assets/css/jekyll_draft.css`](demo/assets/css/jekyll_draft.css) to your Jekyll layout(s).
21
60
 
22
- Add this line to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
61
+ Add the following to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
23
62
 
24
63
  ```ruby
25
64
  group :jekyll_plugins do
26
- gem 'jekyll_draft'
65
+ gem 'jekyll_draft', '>2.0.0' # v2.0.0 was a dud, do not use it
27
66
  end
28
67
  ```
29
68
 
30
- And then execute:
69
+ And then type:
70
+
71
+ ```shell
72
+ $ bundle
73
+ ```
74
+
75
+
76
+ ### For Use In a Gem
77
+
78
+ Add the following to your gem&rsquo;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:
31
85
 
32
86
  ```shell
33
87
  $ bundle
@@ -36,26 +90,132 @@ $ bundle
36
90
 
37
91
  ## Usage
38
92
 
39
- ### `is_draft`
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.
96
+
97
+ ```html
98
+ {% if_draft %}
99
+ <p>This is a draft document!</p>
100
+ {% endif_draft %}
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
+ ```
40
152
 
41
- This filter detects if a page is invisible when published in `production` mode,
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,
42
198
  and either returns `true` or `false`.
43
199
 
44
200
  ```html
45
201
  {{ page | is_draft }} => true
46
202
  ```
47
203
 
48
- ### `draft_html`
204
+
205
+ #### `draft_html`
49
206
 
50
207
  This filter generates HTML to display if a page is invisible when published in `production` mode.
51
208
  If the page is not a draft then the empty string is returned.
52
209
  The generated HTML for draft pages is:<br>
53
- `" &lt;i class='jekyll_draft'>Draft&lt;/i>"`
210
+ `" <i class='jekyll_draft'>Draft</i>"`
54
211
 
55
212
  ```html
56
- {{ page | draft_html }} => " <i class='bg_light_yellow' style='padding-left: 0.5em; padding-right: 0.5em;'>Draft</i>"
213
+ {{ page | draft_html }} => " <i class='jekyll_draft'>Draft</i>"
57
214
  ```
58
215
 
216
+ The optional parameters for the `draft_html` inline tag are not available for
217
+ use with the `draft_html` filter.
218
+
59
219
 
60
220
  ### Invoking From Another Jekyll Plugin
61
221
 
@@ -68,26 +228,18 @@ draft = Jekyll::Draft.draft_html post
68
228
  ```
69
229
 
70
230
 
71
- ## Demo
72
-
73
- The [`demo`](./demo) directory contains a demonstration website, which uses the plugin.
74
- To run, type:
75
-
76
- ```console
77
- $ demo/_bin/debug -r
78
- ```
79
-
80
- Now point your web browser to http://localhost:4444
81
-
82
231
 
83
232
  ## Development
84
233
 
85
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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.
86
238
 
87
239
  Install development dependencies like this:
88
240
 
89
241
  ```shell
90
- $ BUNDLE_WITH="development" bundle
242
+ $ BUNDLE_WITH=development bundle
91
243
  ```
92
244
 
93
245
  To install this gem onto your local machine, run:
@@ -96,39 +248,72 @@ To install this gem onto your local machine, run:
96
248
  $ bundle exec rake install
97
249
  ```
98
250
 
99
- To release a new version,
251
+ ### Debugging The Demo
100
252
 
101
- 1. Update the version number in `version.rb`.
102
- 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
103
- 3. Run the following:
104
-
105
- ```shell
106
- $ bundle exec rake release
107
- ```
108
-
109
- The above creates a git tag for the version, commits the created tag,
110
- and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
253
+ Set breakpoints, then use the Visual Studio Code launch configuration called `Debug Demo`.
111
254
 
112
255
 
113
- ### Debugging
256
+ ### Debugging From Another Jekyll Site
114
257
 
115
258
  Run `bin/attach` and pass the directory name of a Jekyll website that has a suitable script called `_bin/debug`.
116
259
  The `demo` subdirectory fits this description.
117
260
 
118
261
  ```console
119
262
  $ bin/attach demo
120
- Successfully uninstalled jekyll_draft-0.1.0
121
- jekyll_draft 0.1.0 built to pkg/jekyll_draft-0.1.0.gem.
122
- jekyll_draft (0.1.0) installed.
123
- Fast Debugger (ruby-debug-ide 0.7.3, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
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...
124
292
  ```
125
293
 
126
294
  Now attach to the debugger process.
127
- This git repo includes a [Visual Studio Code launcher](./.vscode/launch.json) for this purpose labeled `Listen for rdebug-ide`.
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.
128
297
 
129
298
  Now point your web browser to http://localhost:4444
130
299
 
131
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
+
132
317
  ## Contributing
133
318
 
134
319
  Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_draft.
data/lib/draft.rb CHANGED
@@ -1,29 +1,54 @@
1
+ require 'jekyll_plugin_logger'
2
+
1
3
  # Define these methods outside of the JekyllDraft class so they can be invoked externally and tested more easily
2
- module Draft
3
- # @return true by checking in this order:
4
- # - document is in _drafts directory, detectable by doc['draft']==true
5
- # - document front matter contains 'published: false'
6
- def draft?(doc)
7
- return true if doc.respond_to?(:draft) && doc.draft
8
- return true if doc.key?('draft') && doc['draft'] # ignore !doc['draft']
9
- return !doc['published'] if doc.key?('published')
10
-
11
- false
12
- rescue StandardError => e
13
- @logger.error { e }
14
- false
15
- end
4
+ module Jekyll
5
+ module Draft
6
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
16
7
 
17
- # @param doc [Jekyll::Drops::DocumentDrop]
18
- # @return HTML that indicates if a doc is a draft or not
19
- def draft_html
20
- return '' unless is_draft
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
21
20
 
22
- " <i class='jekyll_draft'>Draft</i>"
23
- rescue StandardError => e
24
- @logger.error { e }
25
- ''
26
- end
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
27
33
 
28
- module_function :draft?, :draft_html
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
29
54
  end
data/lib/draft_html.rb CHANGED
@@ -1,13 +1,27 @@
1
1
  require 'jekyll_plugin_support'
2
2
 
3
- class Else < JekyllSupport::JekyllTag
3
+ class DraftHtml < JekyllSupport::JekyllTag
4
4
  VERSION = '0.1.0'.freeze
5
- PLUGIN_NAME = 'else'.freeze
5
+ DRAFT_HTML = 'draft_html'.freeze unless defined? Else::VERSION
6
6
 
7
7
  def render_impl
8
- " <i class='jekyll_draft'>Draft</i>" if Draft.draft?(@page)
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>"
9
24
  end
10
25
 
11
- JekyllPluginHelper.register(self, PLUGIN_NAME)
12
- PluginMetaLogger.instance.info { "Loaded #{PLUGIN_NAME.class} v#{DraftVersion::VERSION} plugin." }
26
+ JekyllPluginHelper.register(self, DRAFT_HTML)
13
27
  end
data/lib/else.rb CHANGED
@@ -1,13 +1,19 @@
1
1
  require 'jekyll_plugin_support'
2
2
 
3
- class Else < JekyllSupport::JekyllTag
3
+ class ElseBase < JekyllSupport::JekyllTag
4
4
  VERSION = '0.1.0'.freeze
5
- PLUGIN_NAME = 'else'.freeze
5
+ ELSE_DRAFT = 'else_if_draft'.freeze
6
+ ELSE_NOT_DRAFT = 'else_if_not_draft'.freeze
6
7
 
7
8
  def render_impl
8
9
  RECORD_SEPARATOR
9
10
  end
11
+ end
12
+
13
+ class ElseDraft < ElseBase
14
+ JekyllPluginHelper.register(self, ELSE_DRAFT)
15
+ end
10
16
 
11
- JekyllPluginHelper.register(self, PLUGIN_NAME)
12
- PluginMetaLogger.instance.info { "Loaded #{PLUGIN_NAME.class} v#{DraftVersion::VERSION} plugin." }
17
+ class ElseNotDraft < ElseBase
18
+ JekyllPluginHelper.register(self, ELSE_NOT_DRAFT)
13
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 CHANGED
@@ -1,17 +1,27 @@
1
1
  require 'jekyll_plugin_support'
2
2
 
3
- # Jekyll inline plugin that detects draft documents
4
- class JekyllDraft < JekyllSupport::JekyllBlock
5
- PLUGIN_NAME = 'if_draft'.freeze
6
- VERSION = DraftVersion::VERSION
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
7
8
 
8
9
  def render_impl(content)
9
10
  true_value, false_value, extra = content.split(RECORD_SEPARATOR)
10
11
  raise DraftError, "Warning: More than one else clause detected" if extra
11
12
 
12
- Draft.draft?(@page) ? true_value : false_value
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
13
18
  end
19
+ end
20
+
21
+ class IfDraft < DraftBase
22
+ JekyllPluginHelper.register(self, IF_DRAFT)
23
+ end
14
24
 
15
- JekyllPluginHelper.register(self, PLUGIN_NAME)
16
- PluginMetaLogger.instance.info { "Loaded #{PLUGIN_NAME.class} v#{DraftVersion::VERSION} plugin." }
25
+ class UnlessDraft < DraftBase
26
+ JekyllPluginHelper.register(self, UNLESS_DRAFT)
17
27
  end
@@ -1,3 +1,3 @@
1
1
  module DraftVersion
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
data/lib/jekyll_draft.rb CHANGED
@@ -10,5 +10,7 @@ RECORD_SEPARATOR = "\u{241E}".freeze
10
10
  DraftError = JekyllSupport.define_error
11
11
 
12
12
  require_relative 'draft'
13
- require_relative 'else'
14
13
  require_relative 'if_draft'
14
+ require_relative 'else'
15
+ require_relative 'draft_html'
16
+ require_relative 'filters'
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: 2.0.0
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-29 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -56,6 +56,7 @@ files:
56
56
  - lib/draft.rb
57
57
  - lib/draft_html.rb
58
58
  - lib/else.rb
59
+ - lib/filters.rb
59
60
  - lib/if_draft.rb
60
61
  - lib/jekyll_draft.rb
61
62
  - lib/jekyll_draft/version.rb