jekyll_draft 1.0.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: 5b81abf3dd2ad47f14dc0c7a5694642337e779a82e28500510f81eb72622abd8
4
- data.tar.gz: ef24a39d682076c1d73d29dd286ce8bc5c5162af5fcc6d461aeb275f95b79598
3
+ metadata.gz: 2024b9ea176d56e527de8b6adfcb10c5072f6ea93d3c9d661cf64859e6c69dbc
4
+ data.tar.gz: d4518a8a07e342bd9586628c4d66a796ae284d89bd4808f805f0f77614b53ea5
5
5
  SHA512:
6
- metadata.gz: 3d20f8aa839be087692b4da14db1993d762d32aac95f6a6410f9cb17ee377e8516e3e218891602085eb9da1e69e95760765d2aefab370c2131f42b55c5e9ca7e
7
- data.tar.gz: c191c1ff541451b6a6247c0974d2af7a7ef2d1d11e6aded828f124fe0ffb1167344ec8811c0b7235ce6d9e5dd10c0c7c52e6f2995041a45973715de751930d60
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,2 +1,12 @@
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
+
8
+ ## 1.0.1 / 2022-08-05
9
+ * Improved how drafts are recognized
10
+
1
11
  ## 1.0.0 / 2022-04-02
2
12
  * Initial version
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.0.0"
2
+ VERSION = '1.1.1'.freeze
5
3
  end
data/lib/jekyll_draft.rb CHANGED
@@ -1,69 +1,92 @@
1
- # frozen_string_literal: true
2
-
3
1
  # @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
4
2
 
5
- require "jekyll_plugin_logger"
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
- # Define these methods outside of the filter module so they can be invoked externally
8
+ # Define these methods outside of module DraftFilter so they can be invoked externally and tested easily
11
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.
12
13
  def draft?(doc)
13
- abort "Jekyll:Draft.draft? doc is nil!".red if doc.nil?
14
-
15
- # puts "draft? invoked from #{doc.path}"
16
- return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
17
-
18
- return doc.published==false if doc.respond_to?(:published)
14
+ abort 'Jekyll::Draft.draft? doc is nil!'.red if doc.nil?
19
15
 
20
- return doc['published']==false if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('published'))
16
+ return is_unpublished(doc) if published_was_specified(doc)
21
17
 
18
+ # Try Jekyll's naming convention to determine draft status
19
+ return doc.data['draft'] if doc.respond_to?('data') && doc.data.key?('draft')
22
20
  return doc.draft if doc.respond_to?(:draft)
23
21
 
24
- return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
25
-
26
22
  false
27
23
  end
28
24
 
25
+ # @return HTML that indicates if a doc is a draft or not
29
26
  def draft_html(doc)
30
- # puts "draft_html invoked from #{doc.path}"
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
 
32
+ # @return path to root of the collection that doc is a member of
36
33
  def root(doc, site)
37
- # puts "root invoked from #{doc.path}"
38
- return "/index.html" unless doc.respond_to?(:collection)
34
+ return '/index.html' unless doc.respond_to?(:collection)
39
35
 
40
36
  collection_name = doc.collection
41
37
  docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
42
- index = docs.find { |d| d.url.end_with? "index.html" }
38
+ index = docs.find { |d| d.url.end_with? 'index.html' }
43
39
  return index.url if index
44
40
 
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
 
71
+ # Jekyll filters interface
51
72
  module DraftFilter
52
- def is_draft(doc)
53
- Draft::draft?(doc)
73
+ def is_draft(doc) # rubocop:disable Naming/PredicateName
74
+ Draft.draft?(doc)
54
75
  end
55
76
 
56
77
  def draft_html(doc)
57
- Draft::draft_html(doc)
78
+ Draft.draft_html(doc)
79
+ end
80
+
81
+ def is_unpublished(doc) # rubocop:disable Naming/PredicateName
82
+ Draft.is_unpublished(doc)
58
83
  end
59
84
 
60
- # DraftFilter.singleton_class.included_modules
61
- # [JSON::Ext::Generator::GeneratorMethods::Object, PP::ObjectMixin, Kernel]
62
85
  def root(doc, site)
63
- Draft::root(doc, site)
86
+ Draft.root(doc, site)
64
87
  end
65
88
  end
66
89
 
67
90
  Liquid::Template.register_filter(DraftFilter)
68
- PluginMetaLogger.instance.info { "Loaded DraftFilter plugin." }
91
+ PluginMetaLogger.instance.info { 'Loaded DraftFilter plugin.' }
69
92
  end
@@ -1,12 +1,35 @@
1
- # frozen_string_literal: true
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require_relative '../lib/jekyll_draft'
2
4
 
3
- require "jekyll"
4
- require_relative "../lib/jekyll_draft"
5
+ RSpec.describe(Jekyll::Draft) do # rubocop:disable Metrics/BlockLength
6
+ include Jekyll::Draft
5
7
 
6
- RSpec.describe(jekyllDraftName) do
7
- include jekyllDraftName
8
+ let(:page_draft) do
9
+ page_ = double('Jekyll::Page')
10
+ allow(page_).to receive(:draft) { true }
11
+ page_
12
+ end
13
+ let(:page_not_draft) do
14
+ page_ = double('Jekyll::Page')
15
+ allow(page_).to receive(:draft) { false }
16
+ page_
17
+ end
18
+ let(:page_published) do
19
+ page_ = double('Jekyll::Page')
20
+ allow(page_).to receive(:published) { true }
21
+ page_
22
+ end
23
+ let(:page_not_published) do
24
+ page_ = double('Jekyll::Page')
25
+ allow(page_).to receive(:published) { false }
26
+ page_
27
+ end
8
28
 
9
- it "verifies basename" do
10
- expect(basename("a/b/c/d/e.html")).to be_true
29
+ it 'detects drafts' do
30
+ expect(draft?(page_draft)).to be_truthy
31
+ expect(draft?(page_not_draft)).to be_falsey
32
+ expect(draft?(page_published)).to be_falsey
33
+ expect(draft?(page_not_published)).to be_truthy
11
34
  end
12
35
  end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- require "liquid"
4
- require "fileutils"
5
- require_relative "../lib/jekyll_draft"
1
+ require 'jekyll'
2
+ require_relative '../lib/jekyll_draft'
6
3
 
7
4
  RSpec.configure do |config|
8
5
  config.filter_run :focus
9
- config.order = "random"
6
+ config.order = 'random'
10
7
  config.run_all_when_everything_filtered = true
11
8
 
12
9
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
13
- config.example_status_persistence_file_path = "spec/status_persistence.txt"
10
+ config.example_status_persistence_file_path = 'spec/status_persistence.txt'
14
11
  end
@@ -1,4 +1,3 @@
1
- example_id | status | run_time |
2
- ------------------------------------ | ------ | --------------- |
3
- ./spec/basename_dirname_spec.rb[1:1] | passed | 0.00214 seconds |
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.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.0.0
4
+ version: 1.1.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: 2022-05-03 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