jekyll_draft 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b81abf3dd2ad47f14dc0c7a5694642337e779a82e28500510f81eb72622abd8
4
- data.tar.gz: ef24a39d682076c1d73d29dd286ce8bc5c5162af5fcc6d461aeb275f95b79598
3
+ metadata.gz: 6247e977c1fc678658877ae531a93041fce2cc1c2ae4df0cdab2d5f69df599c3
4
+ data.tar.gz: d3d03b417141f2daf752118bef92de184a3aabf02bd03a90c1cc33bb44ee6572
5
5
  SHA512:
6
- metadata.gz: 3d20f8aa839be087692b4da14db1993d762d32aac95f6a6410f9cb17ee377e8516e3e218891602085eb9da1e69e95760765d2aefab370c2131f42b55c5e9ca7e
7
- data.tar.gz: c191c1ff541451b6a6247c0974d2af7a7ef2d1d11e6aded828f124fe0ffb1167344ec8811c0b7235ce6d9e5dd10c0c7c52e6f2995041a45973715de751930d60
6
+ metadata.gz: f3f6458afb1fc8f2c62e0f79b53aade5f91b87ed2301a29cc02038c84eea68fa166530ece6531cdac1f948b22b11a8c5e632ee24f8d90547d0cf4c5b335a07a3
7
+ data.tar.gz: 16d8ca0eb55a72ddb9689880be8ad95c7e74f7d09dba815031037e3f7cfc740da7c02bdecf009e029ec662cb447aa66ea4c4533aaa07a21ca620749512a397d1
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
- require: rubocop-jekyll
2
- inherit_gem:
3
- rubocop-jekyll: .rubocop.yml
1
+ # require: rubocop-jekyll
2
+ # inherit_gem:
3
+ # rubocop-jekyll: .rubocop.yml
4
4
 
5
5
  AllCops:
6
6
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ ## 1.0.1 / 2022-08-05
2
+ * Improved how drafts are recognized
3
+
1
4
  ## 1.0.0 / 2022-04-02
2
5
  * Initial version
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllDraftVersion
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
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 "jekyll_plugin_logger"
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 the filter module so they can be invoked externally
10
+ # Define these methods outside of module DraftFilter so they can be invoked externally and tested easily
11
11
  module Draft
12
- def draft?(doc)
13
- abort "Jekyll:Draft.draft? doc is nil!".red if doc.nil?
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
- # puts "draft? invoked from #{doc.path}"
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.published==false if doc.respond_to?(:published)
18
+ return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
19
19
 
20
- return doc['published']==false if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('published'))
20
+ return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
21
21
 
22
- return doc.draft if doc.respond_to?(:draft)
22
+ return doc.published == false if doc.respond_to?(:published)
23
23
 
24
- return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
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
- # puts "root invoked from #{doc.path}"
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? "index.html" }
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::draft?(doc)
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::draft_html(doc)
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::root(doc, site)
62
+ Draft.root(doc, site)
64
63
  end
65
64
  end
66
65
 
67
66
  Liquid::Template.register_filter(DraftFilter)
68
- PluginMetaLogger.instance.info { "Loaded DraftFilter plugin." }
67
+ PluginMetaLogger.instance.info { 'Loaded DraftFilter plugin.' }
69
68
  end
@@ -1,12 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "jekyll"
4
- require_relative "../lib/jekyll_draft"
3
+ require 'jekyll'
4
+ require 'jekyll_plugin_logger'
5
+ require_relative '../lib/jekyll_draft'
5
6
 
6
- RSpec.describe(jekyllDraftName) do
7
- include jekyllDraftName
7
+ RSpec.describe(Jekyll::Draft) do # rubocop:disable Metrics/BlockLength
8
+ include Jekyll::Draft
8
9
 
9
- it "verifies basename" do
10
- expect(basename("a/b/c/d/e.html")).to be_true
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 "liquid"
4
- require "fileutils"
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 = "random"
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 = "spec/status_persistence.txt"
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.0.0
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-03 00:00:00.000000000 Z
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
- ...
@@ -1,4 +0,0 @@
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 |