jekyll_draft 1.0.0 → 1.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 +4 -4
- data/.rubocop.yml +3 -3
- data/CHANGELOG.md +3 -0
- data/lib/jekyll_draft/version.rb +1 -1
- data/lib/jekyll_draft.rb +20 -21
- data/spec/jekyll_draft_spec.rb +31 -6
- data/spec/spec_helper.rb +4 -5
- metadata +4 -7
- data/spec/status_persistence.txt +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6247e977c1fc678658877ae531a93041fce2cc1c2ae4df0cdab2d5f69df599c3
|
|
4
|
+
data.tar.gz: d3d03b417141f2daf752118bef92de184a3aabf02bd03a90c1cc33bb44ee6572
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3f6458afb1fc8f2c62e0f79b53aade5f91b87ed2301a29cc02038c84eea68fa166530ece6531cdac1f948b22b11a8c5e632ee24f8d90547d0cf4c5b335a07a3
|
|
7
|
+
data.tar.gz: 16d8ca0eb55a72ddb9689880be8ad95c7e74f7d09dba815031037e3f7cfc740da7c02bdecf009e029ec662cb447aa66ea4c4533aaa07a21ca620749512a397d1
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/jekyll_draft/version.rb
CHANGED
data/lib/jekyll_draft.rb
CHANGED
|
@@ -2,44 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
# @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
|
|
4
4
|
|
|
5
|
-
require
|
|
5
|
+
require 'jekyll_plugin_logger'
|
|
6
6
|
require 'yaml'
|
|
7
7
|
|
|
8
8
|
# Detects draft documents
|
|
9
9
|
module Jekyll
|
|
10
|
-
# Define these methods outside of
|
|
10
|
+
# Define these methods outside of module DraftFilter so they can be invoked externally and tested easily
|
|
11
11
|
module Draft
|
|
12
|
-
|
|
13
|
-
|
|
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?
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
|
|
16
|
+
return doc.draft if doc.respond_to?(:draft)
|
|
17
17
|
|
|
18
|
-
return doc
|
|
18
|
+
return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
|
|
19
19
|
|
|
20
|
-
return doc['published']
|
|
20
|
+
return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
|
|
21
21
|
|
|
22
|
-
return doc.
|
|
22
|
+
return doc.published == false if doc.respond_to?(:published)
|
|
23
23
|
|
|
24
|
-
return doc['
|
|
24
|
+
return doc['published'] == false if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('published'))
|
|
25
25
|
|
|
26
26
|
false
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# @return HTML that indicates if a doc is a draft or not
|
|
29
30
|
def draft_html(doc)
|
|
30
|
-
# puts "draft_html invoked from #{doc.path}"
|
|
31
31
|
return '' unless draft?(doc)
|
|
32
32
|
|
|
33
33
|
" <i class='bg_light_yellow' style='padding-left: 0.5em; padding-right: 0.5em;'>Draft</i>"
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# @return path to root of the collection that doc is a member of
|
|
36
37
|
def root(doc, site)
|
|
37
|
-
|
|
38
|
-
return "/index.html" unless doc.respond_to?(:collection)
|
|
38
|
+
return '/index.html' unless doc.respond_to?(:collection)
|
|
39
39
|
|
|
40
40
|
collection_name = doc.collection
|
|
41
41
|
docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs
|
|
42
|
-
index = docs.find { |d| d.url.end_with?
|
|
42
|
+
index = docs.find { |d| d.url.end_with? 'index.html' }
|
|
43
43
|
return index.url if index
|
|
44
44
|
|
|
45
45
|
docs.min.url
|
|
@@ -48,22 +48,21 @@ module Jekyll
|
|
|
48
48
|
module_function :draft?, :draft_html, :root
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# Interface to Jekyll filters
|
|
51
52
|
module DraftFilter
|
|
52
|
-
def is_draft(doc)
|
|
53
|
-
Draft
|
|
53
|
+
def is_draft(doc) # rubocop:disable Naming/PredicateName
|
|
54
|
+
Draft.draft?(doc)
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def draft_html(doc)
|
|
57
|
-
Draft
|
|
58
|
+
Draft.draft_html(doc)
|
|
58
59
|
end
|
|
59
60
|
|
|
60
|
-
# DraftFilter.singleton_class.included_modules
|
|
61
|
-
# [JSON::Ext::Generator::GeneratorMethods::Object, PP::ObjectMixin, Kernel]
|
|
62
61
|
def root(doc, site)
|
|
63
|
-
Draft
|
|
62
|
+
Draft.root(doc, site)
|
|
64
63
|
end
|
|
65
64
|
end
|
|
66
65
|
|
|
67
66
|
Liquid::Template.register_filter(DraftFilter)
|
|
68
|
-
PluginMetaLogger.instance.info {
|
|
67
|
+
PluginMetaLogger.instance.info { 'Loaded DraftFilter plugin.' }
|
|
69
68
|
end
|
data/spec/jekyll_draft_spec.rb
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
|
|
3
|
+
require 'jekyll'
|
|
4
|
+
require 'jekyll_plugin_logger'
|
|
5
|
+
require_relative '../lib/jekyll_draft'
|
|
5
6
|
|
|
6
|
-
RSpec.describe(
|
|
7
|
-
include
|
|
7
|
+
RSpec.describe(Jekyll::Draft) do # rubocop:disable Metrics/BlockLength
|
|
8
|
+
include Jekyll::Draft
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
let(:page_draft) do
|
|
11
|
+
page_ = double('Jekyll::Page')
|
|
12
|
+
allow(page_).to receive(:draft) { true }
|
|
13
|
+
page_
|
|
14
|
+
end
|
|
15
|
+
let(:page_not_draft) do
|
|
16
|
+
page_ = double('Jekyll::Page')
|
|
17
|
+
allow(page_).to receive(:draft) { false }
|
|
18
|
+
page_
|
|
19
|
+
end
|
|
20
|
+
let(:page_published) do
|
|
21
|
+
page_ = double('Jekyll::Page')
|
|
22
|
+
allow(page_).to receive(:published) { true }
|
|
23
|
+
page_
|
|
24
|
+
end
|
|
25
|
+
let(:page_not_published) do
|
|
26
|
+
page_ = double('Jekyll::Page')
|
|
27
|
+
allow(page_).to receive(:published) { false }
|
|
28
|
+
page_
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'detects drafts' do
|
|
32
|
+
expect(draft?(page_draft)).to be_truthy
|
|
33
|
+
expect(draft?(page_not_draft)).to be_falsey
|
|
34
|
+
expect(draft?(page_published)).to be_falsey
|
|
35
|
+
expect(draft?(page_not_published)).to be_truthy
|
|
11
36
|
end
|
|
12
37
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
|
|
5
|
-
require_relative "../lib/jekyll_draft"
|
|
3
|
+
require 'jekyll'
|
|
4
|
+
require_relative '../lib/jekyll_draft'
|
|
6
5
|
|
|
7
6
|
RSpec.configure do |config|
|
|
8
7
|
config.filter_run :focus
|
|
9
|
-
config.order =
|
|
8
|
+
config.order = 'random'
|
|
10
9
|
config.run_all_when_everything_filtered = true
|
|
11
10
|
|
|
12
11
|
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
|
13
|
-
config.example_status_persistence_file_path =
|
|
12
|
+
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
|
14
13
|
end
|
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.
|
|
4
|
+
version: 1.1.0
|
|
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-05
|
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|
|
@@ -57,7 +57,6 @@ 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
|
|
61
60
|
homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename
|
|
62
61
|
licenses:
|
|
63
62
|
- MIT
|
|
@@ -86,11 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
85
|
version: '0'
|
|
87
86
|
requirements: []
|
|
88
87
|
rubygems_version: 3.3.3
|
|
89
|
-
signing_key:
|
|
88
|
+
signing_key:
|
|
90
89
|
specification_version: 4
|
|
91
90
|
summary: This Jekyll filter detects draft documents.
|
|
92
91
|
test_files:
|
|
93
92
|
- spec/jekyll_draft_spec.rb
|
|
94
93
|
- spec/spec_helper.rb
|
|
95
|
-
- spec/status_persistence.txt
|
|
96
|
-
...
|
data/spec/status_persistence.txt
DELETED