jekyll_draft 1.1.0 → 1.1.2

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: 508d8293b65652e57262601a7de1aacebfe7b29e1eeb492b9fefaed87f377794
4
+ data.tar.gz: cf23341ecad96d666b5e5f14e44ca83b6cef430ae8c07321294539b096cc644a
5
5
  SHA512:
6
- metadata.gz: f3f6458afb1fc8f2c62e0f79b53aade5f91b87ed2301a29cc02038c84eea68fa166530ece6531cdac1f948b22b11a8c5e632ee24f8d90547d0cf4c5b335a07a3
7
- data.tar.gz: 16d8ca0eb55a72ddb9689880be8ad95c7e74f7d09dba815031037e3f7cfc740da7c02bdecf009e029ec662cb447aa66ea4c4533aaa07a21ca620749512a397d1
6
+ metadata.gz: b15902c8ed65cd8fd43434a5640ad6cce272cb797ef61c47a5f768a95c3dd86768f17f513ed97dcd82dd93917e09088432fbd1976f6a89490740ae4bb2abf25c
7
+ data.tar.gz: efeca601d5941f016d1ec0046e6e9001c32b3bf9ab518cd92872eea8647cccbf87804aa389ef98f3bb1d0b49e64317a6f2698a692768074b3c98373140ef3a24
data/.rubocop.yml CHANGED
@@ -1,13 +1,106 @@
1
- # require: rubocop-jekyll
1
+ require:
2
+ # - rubocop-jekyll
3
+ - rubocop-md
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
2
8
  # inherit_gem:
3
9
  # rubocop-jekyll: .rubocop.yml
4
10
 
5
11
  AllCops:
6
12
  Exclude:
7
- - vendor/**/*
8
- - Gemfile*
13
+ - demo/_site/**/*
14
+ - exe/**/*
15
+ - vendor/**/*
16
+ - Gemfile*
9
17
  NewCops: enable
10
18
  TargetRubyVersion: 2.6
11
19
 
20
+ Gemspec/DeprecatedAttributeAssignment:
21
+ Enabled: false
22
+
23
+ Gemspec/RequireMFA:
24
+ Enabled: false
25
+
26
+ Layout/HashAlignment:
27
+ EnforcedColonStyle: table
28
+ Exclude:
29
+ - jekyll_draft.gemspec
30
+
31
+ Layout/InitialIndentation:
32
+ Exclude:
33
+ - README.md
34
+
12
35
  Layout/LineLength:
13
36
  Max: 150
37
+
38
+ Layout/MultilineMethodCallIndentation:
39
+ Enabled: false
40
+
41
+ Lint/RedundantCopDisableDirective:
42
+ Exclude:
43
+ - jekyll_draft.gemspec
44
+
45
+ Metrics/AbcSize:
46
+ Max: 45
47
+
48
+ Metrics/BlockLength:
49
+ Exclude:
50
+ - jekyll_draft.gemspec
51
+ - spec/**/*
52
+
53
+ Metrics/ClassLength:
54
+ Exclude:
55
+ - spec/**/*
56
+ Max: 40
57
+
58
+ Metrics/CyclomaticComplexity:
59
+ Max: 20
60
+
61
+ Metrics/MethodLength:
62
+ Max: 40
63
+
64
+ Metrics/PerceivedComplexity:
65
+ Max: 15
66
+
67
+ Naming/FileName:
68
+ Exclude:
69
+ - Rakefile
70
+
71
+ RSpec/ExampleLength:
72
+ Max: 20
73
+
74
+ RSpec/MultipleExpectations:
75
+ Max: 15
76
+
77
+ Style/CommandLiteral:
78
+ Enabled: false
79
+
80
+ Style/CommentedKeyword:
81
+ Enabled: false
82
+
83
+ Style/Documentation:
84
+ Enabled: false
85
+
86
+ Style/FrozenStringLiteralComment:
87
+ Enabled: false
88
+
89
+ Style/PercentLiteralDelimiters:
90
+ Enabled: false
91
+
92
+ Style/RegexpLiteral:
93
+ Enabled: false
94
+
95
+ Style/StringConcatenation:
96
+ Exclude:
97
+ - spec/**/*
98
+
99
+ Style/StringLiterals:
100
+ Enabled: false
101
+
102
+ Style/StringLiteralsInInterpolation:
103
+ Enabled: false
104
+
105
+ Style/TrailingCommaInHashLiteral:
106
+ EnforcedStyleForMultiline: comma
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.1.2 / 2023-02-25
2
+ * Avoids Jekyll generating the message `Deprecation: Document#published is now a key in the #data hash.`
3
+
4
+ ## 1.1.1 / 2023-02-16
5
+ * Avoids Jekyll generating the message `Deprecation: Document#draft is now a key in the #data hash.`
6
+
7
+ ## 1.1.0 / 2023-02-05
8
+ * Works with CSS classes instead of generating CSS styling
9
+ * Improved how unpublished documents are recognized
10
+
1
11
  ## 1.0.1 / 2022-08-05
2
12
  * Improved how drafts are recognized
3
13
 
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/Rakefile CHANGED
@@ -1,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
5
3
 
6
4
  RSpec::Core::RakeTask.new(:spec)
7
- task :default => :spec
5
+ task default: :spec
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.2'.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,35 @@ 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
+ # Looks in data before checking for property.
58
+ # @return true if published was specified in a document's front matter, and the value is false
59
+ def is_unpublished(doc) # rubocop:disable Naming/PredicateName
60
+ return !doc.data['published'] if doc.respond_to?(:data) && doc.data.key?('published')
61
+
62
+ return !doc.published if doc.respond_to?(:published)
63
+
64
+ return !doc['published'] if doc.key?('published')
65
+
66
+ false
67
+ end
68
+
69
+ module_function :draft?, :draft_html, :is_unpublished, :published_was_specified, :root
49
70
  end
50
71
 
51
- # Interface to Jekyll filters
72
+ # Jekyll filters interface
52
73
  module DraftFilter
53
74
  def is_draft(doc) # rubocop:disable Naming/PredicateName
54
75
  Draft.draft?(doc)
@@ -58,6 +79,10 @@ module Jekyll
58
79
  Draft.draft_html(doc)
59
80
  end
60
81
 
82
+ def is_unpublished(doc) # rubocop:disable Naming/PredicateName
83
+ Draft.is_unpublished(doc)
84
+ end
85
+
61
86
  def root(doc, site)
62
87
  Draft.root(doc, site)
63
88
  end
@@ -0,0 +1,11 @@
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require_relative '../../lib/jekyll_draft'
4
+
5
+ RSpec.describe(Jekyll::Draft) do
6
+ include described_class
7
+
8
+ it 'detects drafts' do
9
+ pending('Not yet')
10
+ end
11
+ end
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,4 @@
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 |
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.2
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-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -55,8 +55,9 @@ files:
55
55
  - jekyll_draft.gemspec
56
56
  - lib/jekyll_draft.rb
57
57
  - lib/jekyll_draft/version.rb
58
- - spec/jekyll_draft_spec.rb
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
- - spec/jekyll_draft_spec.rb
93
+ - spec/jekyll/draft_spec.rb
93
94
  - spec/spec_helper.rb
95
+ - spec/status_persistence.txt
96
+ ...
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'jekyll'
4
- require 'jekyll_plugin_logger'
5
- require_relative '../lib/jekyll_draft'
6
-
7
- RSpec.describe(Jekyll::Draft) do # rubocop:disable Metrics/BlockLength
8
- include Jekyll::Draft
9
-
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
36
- end
37
- end