jekyll_draft 1.1.0 → 1.1.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: 6247e977c1fc678658877ae531a93041fce2cc1c2ae4df0cdab2d5f69df599c3
4
- data.tar.gz: d3d03b417141f2daf752118bef92de184a3aabf02bd03a90c1cc33bb44ee6572
3
+ metadata.gz: 2024b9ea176d56e527de8b6adfcb10c5072f6ea93d3c9d661cf64859e6c69dbc
4
+ data.tar.gz: d4518a8a07e342bd9586628c4d66a796ae284d89bd4808f805f0f77614b53ea5
5
5
  SHA512:
6
- metadata.gz: f3f6458afb1fc8f2c62e0f79b53aade5f91b87ed2301a29cc02038c84eea68fa166530ece6531cdac1f948b22b11a8c5e632ee24f8d90547d0cf4c5b335a07a3
7
- data.tar.gz: 16d8ca0eb55a72ddb9689880be8ad95c7e74f7d09dba815031037e3f7cfc740da7c02bdecf009e029ec662cb447aa66ea4c4533aaa07a21ca620749512a397d1
6
+ metadata.gz: a5c3c44b58c2983dc6399822b0b223a387d06c3f624d0891748539569cf5abe72ab7ae1e109101c9fbeaae99002a3d8e02984e75af086940c866b2377997b282
7
+ data.tar.gz: bdef2fa61858f15620e7e54a43199ec434115a91147db7fe485b052f45c3a7cb0be1227e682da7bc6a8b1bdaef2f8d664f14b4f60dd73aaa9ec08ded17f918d0
data/.rubocop.yml CHANGED
@@ -1,7 +1,3 @@
1
- # require: rubocop-jekyll
2
- # inherit_gem:
3
- # rubocop-jekyll: .rubocop.yml
4
-
5
1
  AllCops:
6
2
  Exclude:
7
3
  - vendor/**/*
@@ -9,5 +5,11 @@ AllCops:
9
5
  NewCops: enable
10
6
  TargetRubyVersion: 2.6
11
7
 
8
+ Layout/HashAlignment:
9
+ Enabled: false
10
+
12
11
  Layout/LineLength:
13
12
  Max: 150
13
+
14
+ Style/FrozenStringLiteralComment:
15
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.1.1 / 2023-02-16
2
+ * Avoids Jekyll generating the message `Deprecation: Document#draft is now a key in the #data hash.`
3
+
4
+ ## 1.1.0 / 2023-02-05
5
+ * Works with CSS classes instead of generating CSS styling
6
+ * Improved how unpublished documents are recognized
7
+
1
8
  ## 1.0.1 / 2022-08-05
2
9
  * Improved how drafts are recognized
3
10
 
data/README.md CHANGED
@@ -2,13 +2,24 @@ jekyll_draft
2
2
  [![Gem Version](https://badge.fury.io/rb/jekyll_draft.svg)](https://badge.fury.io/rb/jekyll_draft)
3
3
  ===========
4
4
 
5
- This is a Jekyll plugin that provides two Liquid filters called `is_draft` and `draft_html`.
5
+ This is a Jekyll plugin that provides two Liquid filters: `is_draft` and `draft_html`.
6
6
 
7
- More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
7
+ More information is available on my website about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
8
8
 
9
9
 
10
10
  ## Installation
11
11
 
12
+ Add the following to your CSS:
13
+ ```css
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
+ ```
22
+
12
23
  Add this line to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
13
24
 
14
25
  ```ruby
@@ -21,21 +32,40 @@ And then execute:
21
32
 
22
33
  $ bundle install
23
34
 
24
- Or install it yourself as:
25
-
26
- $ gem install jekyll_draft
27
-
28
35
 
29
36
  ## Usage
30
37
 
31
- ### is_draft
38
+ ### `is_draft`
32
39
 
33
- Filters a string containing a path and returns the portion of th path before the filename and extension.
34
- Example: Extracts "blah/blah" from the path.
40
+ Filters a page according to the directory it resides in, and its front matter.
35
41
  ```
36
42
  {{ page | is_draft }} => true
37
43
  ```
38
44
 
45
+ ### `draft_html`
46
+ Filters a page according to the directory it resides in, and its front matter.
47
+ If the page is not a draft then the empty string is returned.
48
+ ```
49
+ {{ page | draft_html }} => " <i class='bg_light_yellow' style='padding-left: 0.5em; padding-right: 0.5em;'>Draft</i>"
50
+ ```
51
+
52
+ ### Invoking From Another Jekyll Plugin
53
+ ```ruby
54
+ require 'jekyll_draft'
55
+
56
+ p 'Found a draft' if Jekyll::Draft.is_draft post
57
+
58
+ draft = Jekyll::Draft.draft_html post
59
+ ```
60
+
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
+
39
69
 
40
70
  ## Development
41
71
 
@@ -61,6 +91,21 @@ To release a new version,
61
91
  The above creates a git tag for the version, commits the created tag,
62
92
  and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
63
93
 
94
+ ### Debugging
95
+ Run `bin/attach` and pass the directory name of a Jekyll website that has a suitable script called `_bin/debug`.
96
+ The `demo` subdirectory fits this description.
97
+ ```console
98
+ $ bin/attach demo
99
+ Successfully uninstalled jekyll_draft-0.1.0
100
+ jekyll_draft 0.1.0 built to pkg/jekyll_draft-0.1.0.gem.
101
+ jekyll_draft (0.1.0) installed.
102
+ Fast Debugger (ruby-debug-ide 0.7.3, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
103
+ ```
104
+ Now attach to the debugger process.
105
+ This git repo includes a [Visual Studio Code launcher](./.vscode/launch.json) for this purpose labeled `Listen for rdebug-ide`.
106
+
107
+ Now point your web browser to http://localhost:4444
108
+
64
109
 
65
110
  ## Contributing
66
111
 
data/jekyll_draft.gemspec CHANGED
@@ -1,46 +1,36 @@
1
- # frozen_string_literal: true
1
+ require_relative 'lib/jekyll_draft/version'
2
2
 
3
- require_relative "lib/jekyll_draft/version"
3
+ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
4
+ github = 'https://github.com/mslinn/jekyll_draft'
4
5
 
5
- # rubocop:disable Metrics/BlockLength
6
- Gem::Specification.new do |spec|
7
- github = "https://github.com/mslinn/jekyll_draft"
8
-
9
- spec.authors = ["Mike Slinn"]
10
- spec.bindir = "exe"
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
11
8
  spec.description = <<~END_OF_DESC
12
9
  This Jekyll filter detects draft documents.
13
10
  END_OF_DESC
14
- spec.email = ["mslinn@mslinn.com"]
15
- spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
16
- spec.homepage = "https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename"
17
- spec.license = "MIT"
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
+ spec.homepage = 'https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename'
14
+ spec.license = 'MIT'
18
15
  spec.metadata = {
19
- "allowed_push_host" => "https://rubygems.org",
20
- "bug_tracker_uri" => "#{github}/issues",
21
- "changelog_uri" => "#{github}/CHANGELOG.md",
22
- "homepage_uri" => spec.homepage,
23
- "source_code_uri" => github,
16
+ 'allowed_push_host' => 'https://rubygems.org',
17
+ 'bug_tracker_uri' => "#{github}/issues",
18
+ 'changelog_uri' => "#{github}/CHANGELOG.md",
19
+ 'homepage_uri' => spec.homepage,
20
+ 'source_code_uri' => github,
24
21
  }
25
- spec.name = "jekyll_draft"
22
+ spec.name = 'jekyll_draft'
26
23
  spec.post_install_message = <<~END_MESSAGE
27
24
 
28
25
  Thanks for installing #{spec.name}!
29
26
 
30
27
  END_MESSAGE
31
- spec.require_paths = ["lib"]
32
- spec.required_ruby_version = ">= 2.6.0"
33
- spec.summary = "This Jekyll filter detects draft documents."
34
- spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
28
+ spec.require_paths = ['lib']
29
+ 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)/})
35
32
  spec.version = JekyllDraftVersion::VERSION
36
33
 
37
- spec.add_dependency "jekyll", ">= 3.5.0"
38
- spec.add_dependency "jekyll_plugin_logger"
39
-
40
- # spec.add_development_dependency "debase"
41
- # spec.add_development_dependency "rubocop-jekyll"
42
- # spec.add_development_dependency "rubocop-rake"
43
- # spec.add_development_dependency "rubocop-rspec"
44
- # spec.add_development_dependency "ruby-debug-ide"
34
+ spec.add_dependency 'jekyll', '>= 3.5.0'
35
+ spec.add_dependency 'jekyll_plugin_logger'
45
36
  end
46
- # rubocop:enable Metrics/BlockLength
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module JekyllDraftVersion
4
- VERSION = "1.1.0"
2
+ VERSION = '1.1.1'.freeze
5
3
  end
data/lib/jekyll_draft.rb CHANGED
@@ -1,27 +1,23 @@
1
- # frozen_string_literal: true
2
-
3
1
  # @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
4
2
 
5
3
  require 'jekyll_plugin_logger'
6
4
  require 'yaml'
7
5
 
8
- # Detects draft documents
6
+ # Jekyll filter that detects draft documents
9
7
  module Jekyll
10
8
  # Define these methods outside of module DraftFilter so they can be invoked externally and tested easily
11
9
  module Draft
12
- # @return true if doc front matter contains published that is not true, or document is in _drafts; published has priority
13
- def draft?(doc) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
14
- abort 'Jekyll:Draft.draft? doc is nil!'.red if doc.nil?
15
-
16
- return doc.draft if doc.respond_to?(:draft)
17
-
18
- return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
19
-
20
- return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
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?
21
15
 
22
- return doc.published == false if doc.respond_to?(:published)
16
+ return is_unpublished(doc) if published_was_specified(doc)
23
17
 
24
- return doc['published'] == false if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('published'))
18
+ # Try Jekyll's naming convention to determine draft status
19
+ return doc.data['draft'] if doc.respond_to?('data') && doc.data.key?('draft')
20
+ return doc.draft if doc.respond_to?(:draft)
25
21
 
26
22
  false
27
23
  end
@@ -30,7 +26,7 @@ module Jekyll
30
26
  def draft_html(doc)
31
27
  return '' unless draft?(doc)
32
28
 
33
- " <i class='bg_light_yellow' style='padding-left: 0.5em; padding-right: 0.5em;'>Draft</i>"
29
+ " <i class='jekyll_draft'>Draft</i>"
34
30
  end
35
31
 
36
32
  # @return path to root of the collection that doc is a member of
@@ -45,10 +41,34 @@ module Jekyll
45
41
  docs.min.url
46
42
  end
47
43
 
48
- module_function :draft?, :draft_html, :root
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
+ # @return true if published was specified in a document's front matter, and the value is false
58
+ def is_unpublished(doc) # rubocop:disable Naming/PredicateName
59
+ return !doc.published if doc.respond_to?('published')
60
+
61
+ return !doc['published'] if doc.key?('published')
62
+
63
+ return !doc.data['published'] if doc.respond_to?('data') && doc.data.key?('published')
64
+
65
+ false
66
+ end
67
+
68
+ module_function :draft?, :draft_html, :is_unpublished, :published_was_specified, :root
49
69
  end
50
70
 
51
- # Interface to Jekyll filters
71
+ # Jekyll filters interface
52
72
  module DraftFilter
53
73
  def is_draft(doc) # rubocop:disable Naming/PredicateName
54
74
  Draft.draft?(doc)
@@ -58,6 +78,10 @@ module Jekyll
58
78
  Draft.draft_html(doc)
59
79
  end
60
80
 
81
+ def is_unpublished(doc) # rubocop:disable Naming/PredicateName
82
+ Draft.is_unpublished(doc)
83
+ end
84
+
61
85
  def root(doc, site)
62
86
  Draft.root(doc, site)
63
87
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'jekyll'
4
2
  require 'jekyll_plugin_logger'
5
3
  require_relative '../lib/jekyll_draft'
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'jekyll'
4
2
  require_relative '../lib/jekyll_draft'
5
3
 
@@ -0,0 +1,3 @@
1
+ example_id | status | run_time |
2
+ -------------------------------- | ------ | --------------- |
3
+ ./spec/jekyll_draft_spec.rb[1:1] | passed | 0.00903 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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -57,6 +57,7 @@ files:
57
57
  - lib/jekyll_draft/version.rb
58
58
  - spec/jekyll_draft_spec.rb
59
59
  - spec/spec_helper.rb
60
+ - spec/status_persistence.txt
60
61
  homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename
61
62
  licenses:
62
63
  - MIT
@@ -85,9 +86,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  version: '0'
86
87
  requirements: []
87
88
  rubygems_version: 3.3.3
88
- signing_key:
89
+ signing_key:
89
90
  specification_version: 4
90
91
  summary: This Jekyll filter detects draft documents.
91
92
  test_files:
92
93
  - spec/jekyll_draft_spec.rb
93
94
  - spec/spec_helper.rb
95
+ - spec/status_persistence.txt
96
+ ...