jekyll_draft 2.1.0 → 3.0.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: 86ee1458ee28aab9d7f99d46deeff46e98a795cb6d3737a84b2e0e9f17f68632
4
- data.tar.gz: a1abc81b94ccfdc3ee46ec312324d0d086567bbabcaa40784fca3d8d1c8415e4
3
+ metadata.gz: d19e46e62c8e1d7cf29a6337023ea875a6497040f773c2b416f9798488820199
4
+ data.tar.gz: c4e3f0ae938781b77a267b3681640234c15dffa3349cf966fff74836bbe4234e
5
5
  SHA512:
6
- metadata.gz: a70c60fa72cfb2dc9a8842e5b54ec9f0dec2746976edd90ed174990dcf24a14aadf801246258c257ac375c68fd72a518c9e9bc55bbbf975498c43d09a5a94774
7
- data.tar.gz: 030ef794350d158b43395d957ce6f080c8497dde0db7005dacc96dd2900cacbc712c353addf1cb2443f8261e2e2fee471d9e1f39c7f7c9a758776f23a7ca56d5
6
+ metadata.gz: b192fb472d77c23932160650cdfe68eacfb1f52b1ccf9d0f84c6e19642e4471eeb82d3ffcba920dc3e1ae6d5ba42a04ae8372361b873bae6386521c96eacab2f
7
+ data.tar.gz: b7e2bfbdd778dfe7dd89846c7c7fb0d57fdb1b7d6a1c2688278c32cf9f17edaf28707749fdb90b7698820ae713f3900afb0e93d4fce41c4fea2ff4d433515b51
data/.rubocop.yml CHANGED
@@ -55,7 +55,7 @@ Metrics/BlockLength:
55
55
  Metrics/ClassLength:
56
56
  Exclude:
57
57
  - spec/**/*
58
- Max: 60
58
+ Max: 100
59
59
 
60
60
  Metrics/CyclomaticComplexity:
61
61
  Max: 20
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0.1 / 2025-08-26
4
+
5
+ * Now requires [Jekyll 4.4.1](https://jekyllrb.com/news/2025/01/29/jekyll-4-4-1-released/) or later, and Ruby 3.2.0 or later
6
+
7
+
3
8
  ## 2.1.0 / 2025-02-07
4
9
 
5
10
  * Added ability to return a page in any collection, or those not in a collection,
data/README.md CHANGED
@@ -5,6 +5,9 @@ visible when the website is published in `production` mode.
5
5
  The Jekyll documentation is scattered and incomplete regarding detecting draft pages and documents.
6
6
  This plugin provides standard ways for detecting draft pages and documents.
7
7
 
8
+ You can display the Jekyll mode that was active when a page was
9
+ generated with `{{jekyll.environment}}`.
10
+
8
11
  `Jekyll_draft` provides the following:
9
12
 
10
13
  * Jekyll block tags: `if_draft`, `if_page_draft`, `unless_draft`, and `unless_page_draft`.
@@ -93,8 +96,8 @@ so you can learn how to write Jekyll pages that include this functionality.
93
96
 
94
97
  ```ruby
95
98
  group :jekyll_plugins do
96
- gem 'jekyll_all_collections', '>= 0.3.8'
97
- gem 'jekyll_draft', '>=2.1.0'
99
+ gem 'jekyll_plugin_support', '>= 3.0.0'
100
+ gem 'jekyll_draft', '>=3.0.0'
98
101
  end
99
102
  ```
100
103
 
@@ -112,8 +115,8 @@ so you can learn how to write Jekyll pages that include this functionality.
112
115
  1. Add the following to your gem’s `.gemspec`:
113
116
 
114
117
  ```ruby
115
- spec.add_dependency 'jekyll_all_collections', '>= 0.3.8'
116
- spec.add_dependency 'jekyll_draft', '>=2.1.0'
118
+ spec.add_dependency 'jekyll_plugin_support', '>= 3.0.0'
119
+ spec.add_dependency 'jekyll_draft', '>=3.0.0'
117
120
  ```
118
121
 
119
122
  2. Type:
@@ -312,7 +315,7 @@ Here is an example of embedding the `draft_html` inline tag into an HTML documen
312
315
  ```
313
316
 
314
317
  By default, if the document is a draft, and the Jekyll website generation was performed in development mode,
315
- `draft_html` emits ` <i class='jekyll_draft>Draft</i>`,
318
+ `draft_html` emits ` <i class='jekyll_draft'>Draft</i>`,
316
319
  otherwise it does not emit anything.
317
320
 
318
321
  <p>You can change this behavior in several ways:</p>
data/jekyll_draft.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative 'lib/jekyll_draft/version'
2
2
 
3
- Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
3
+ Gem::Specification.new do |spec|
4
4
  github = 'https://github.com/mslinn/jekyll_draft'
5
5
 
6
6
  spec.authors = ['Mike Slinn']
@@ -27,11 +27,12 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
27
27
 
28
28
  END_MESSAGE
29
29
  spec.require_paths = ['lib']
30
- spec.required_ruby_version = '>= 2.6.0'
30
+ spec.required_ruby_version = '>= 3.2.0'
31
31
  spec.summary = 'This Jekyll filter detects draft documents.'
32
32
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
33
  spec.version = DraftVersion::VERSION
34
34
 
35
- spec.add_dependency 'jekyll', '>= 3.5.0'
36
- spec.add_dependency 'jekyll_plugin_support', '>=1.1.0'
35
+ spec.add_dependency 'jekyll', '>= 4.4.0'
36
+ spec.add_dependency 'jekyll_plugin_support', '>=3.0.0'
37
+ spec.add_dependency 'sorted_set'
37
38
  end
@@ -1,5 +1,3 @@
1
- require 'jekyll_plugin_support'
2
-
3
1
  class ElseBase < JekyllSupport::JekyllTag
4
2
  VERSION = '0.1.0'.freeze
5
3
 
@@ -24,7 +24,12 @@ module Jekyll
24
24
 
25
25
  false
26
26
  rescue StandardError => e
27
- Draft.logger.error { e.full_message }
27
+ msg = e.full_message
28
+ if msg.length < 250
29
+ Draft.logger.error { msg }
30
+ else
31
+ Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" }
32
+ end
28
33
  false
29
34
  end
30
35
 
@@ -35,25 +40,27 @@ module Jekyll
35
40
 
36
41
  " <i class='jekyll_draft'>Draft</i>"
37
42
  rescue StandardError => e
38
- Draft.logger.error { e.full_message }
43
+ msg = e.full_message
44
+ if msg.length < 250
45
+ Draft.logger.error { msg }
46
+ else
47
+ Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" }
48
+ end
39
49
  ''
40
50
  end
41
51
 
42
- # This is a computationally intense method, and really slows down site generation.
43
- # TODO: implement cache in front of sorted objects containing paths and page reference
44
- # This cache is also needed by compute_link_and_text in jekyll_href
45
52
  # @return APage whose href uniquely contains path_portion,
46
53
  # or `path_portion` as a String for non-local URLs.
47
54
  def page_match(path_portion, error_if_no_match: true, verify_unique_match: false)
48
55
  return :non_local_url if path_portion.start_with? 'http:', 'https:', 'mailto'
49
56
 
50
57
  matching_pages = if verify_unique_match
51
- ::AllCollectionsHooks.sorted_lru_files.select path_portion
58
+ ::AllCollectionsHooks.sorted_lru_files.find(path_portion)
52
59
  else
53
- match = ::AllCollectionsHooks.sorted_lru_files.find path_portion
60
+ match = ::AllCollectionsHooks.sorted_lru_files.find(path_portion)
54
61
  match.nil? ? [] : [match]
55
62
  end
56
- case matching_pages.length
63
+ case matching_pages.size
57
64
  when 0
58
65
  return '' unless error_if_no_match
59
66
 
@@ -70,7 +77,12 @@ module Jekyll
70
77
  exit! 2 # The user should fix this problem before allowing the website to generate
71
78
  end
72
79
  rescue StandardError => e
73
- puts e.full_message
80
+ msg = e.full_message
81
+ if msg.length < 250
82
+ Draft.logger.error { msg }
83
+ else
84
+ Draft.logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" }
85
+ end
74
86
  end
75
87
 
76
88
  # @return path to root of the collection that doc is a member of
@@ -83,6 +95,13 @@ module Jekyll
83
95
  return index.href if index
84
96
 
85
97
  docs.min.href
98
+ rescue StandardError => e
99
+ msg = e.full_message
100
+ if msg.length < 250
101
+ Draft.logger.error { msg }
102
+ else
103
+ Draft.logger.error { "#{msg[0..150]} ... #{msg[-150..msg.length]}" }
104
+ end
86
105
  end
87
106
 
88
107
  module_function :draft?, :draft_html, :page_match, :root
@@ -34,7 +34,12 @@ class DraftPageBase < JekyllSupport::JekyllBlock
34
34
  end
35
35
  process_variables clause_value
36
36
  rescue StandardError => e
37
- puts e.full_message
37
+ msg = e.full_message
38
+ if msg.length < 250
39
+ @logger.error { msg }
40
+ else
41
+ @logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" }
42
+ end
38
43
  exit!
39
44
  end
40
45
 
@@ -46,7 +51,7 @@ class DraftPageBase < JekyllSupport::JekyllBlock
46
51
  @error_if_no_match = tag_config['error_if_no_match'] # defaults true
47
52
  @error_if_no_match = @error_if_no_match ? @error_if_no_match == true : true
48
53
 
49
- @verify_unique_match = tag_config['verify_unique_match'] == true # defaults false
54
+ @verify_unique_match = true # tag_config['verify_unique_match'] == true # defaults false
50
55
  else
51
56
  @logger.warn { "There is no entry for #{@tag_name} in _config.yml; default values were applied." }
52
57
  end
@@ -58,31 +63,55 @@ class DraftPageBase < JekyllSupport::JekyllBlock
58
63
  @verify_unique_match = env_var != 'false' if env_var
59
64
  end
60
65
 
66
+ # @param markup [String] might contain <<path_portion>> or <<matched_page.url>>
61
67
  def process_variables(markup)
62
68
  return '' unless markup
63
69
 
64
70
  path_portion = @path_portion # add this to the binding
65
- matched_page = @matched_page # add this to the binding
71
+ matched_page = @matched_page.instance_of?(Enumerator) ? @matched_page.first : @matched_page # add this to the binding
66
72
  _ = path_portion == matched_page # Just to keep the lint checker happy
67
- markup.gsub!(/(<<([^<>]*)>>)/) do
68
- token = Regexp.last_match[1] # gsub replaces token with the return value of this block
69
- expression = Regexp.last_match[2]
70
- if expression == 'matched_page' && matched_page.class != String
71
- @logger.warn do
72
- expression = 'matched_page.href'
73
- <<~END_MSG
74
- The expression #{token} should either specify a property, for example <<matched_page.href>>,
75
- or a hash value, for example <<matched_page['title']>>.
76
- The expression was modified to <<matched_page.href>> for you.
77
- END_MSG
78
- end
79
- end
80
- result = eval expression, binding # rubocop:disable Security/Eval
81
- result.to_s
73
+ markup.gsub!(/(<<([^<>]*)>>)/) do # gsub replaces token with the return value of this block
74
+ replace_token Regexp.last_match[1], Regexp.last_match[2], binding
82
75
  end
83
76
  markup
84
77
  rescue StandardError => e
85
- @logger.error { e.full_message }
78
+ msg = e.full_message
79
+ if msg.length < 250
80
+ @logger.error { msg }
81
+ else
82
+ @logger.error { "#{msg[0..125]} ... #{msg[-125..msg.length]}" }
83
+ end
84
+ end
85
+
86
+ def replace_token(token, expression, binding)
87
+ if expression == 'matched_page'
88
+ expression = case matched_page
89
+ when String
90
+ matched_page
91
+ when APage
92
+ 'matched_page&.href'
93
+ when LruFile
94
+ 'matched_page&.url'
95
+ else
96
+ @logger.warn do
97
+ <<~END_MSG
98
+ The type #{matched_page.class} has an invalid valueexpression #{token}.
99
+ END_MSG
100
+ end
101
+ exit!
102
+ end
103
+ @logger.warn do
104
+ <<~END_MSG
105
+ The expression #{token} should either specify a property, for example <<matched_page&.href>>,
106
+ or a hash value, for example <<matched_page['title']>>.
107
+ The expression was modified to <<#{expression}>> for you.
108
+ END_MSG
109
+ end
110
+ else
111
+ puts expression
112
+ end
113
+ result = eval expression, binding # rubocop:disable Security/Eval
114
+ result.to_s
86
115
  end
87
116
  end
88
117
 
@@ -1,3 +1,3 @@
1
1
  module DraftVersion
2
- VERSION = '2.1.0'.freeze
2
+ VERSION = '3.0.1'.freeze unless defined?(VERSION)
3
3
  end
data/lib/jekyll_draft.rb CHANGED
@@ -1,6 +1,8 @@
1
- # @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
2
-
3
- require 'jekyll_plugin_support'
1
+ if ENV['USE_JPS_SOURCE']
2
+ require_relative "#{ENV.fetch('jekyll_plugin_support')}/lib/jekyll_plugin_support"
3
+ else
4
+ require 'jekyll_plugin_support'
5
+ end
4
6
  require 'yaml'
5
7
  require_relative 'jekyll_draft/version' unless defined?(VERSION)
6
8
 
@@ -11,7 +11,8 @@ RSpec.describe(Jekyll::Draft) do
11
11
  PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
12
12
  end
13
13
 
14
- let(:parse_context) { TestParseContext.new }
14
+ let(:parse_context_published) { TestParseContext.new(published: true) }
15
+ let(:parse_context_draft) { TestParseContext.new(published: false) }
15
16
 
16
17
  it 'detects drafts' do
17
18
  # expect(result).to match_ignoring_whitespace <<-END_RESULT
data/spec/jekyll/mocks.rb CHANGED
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  # Mock for Liquid::Context
25
25
  class TestLiquidContext < Liquid::Context
26
- def initialize
26
+ def initialize(published: false)
27
27
  super
28
28
 
29
29
  page = {
@@ -35,6 +35,7 @@ class TestLiquidContext < Liquid::Context
35
35
  "layout" => "default",
36
36
  "name" => "index.html",
37
37
  "path" => "index.html",
38
+ "published" => published,
38
39
  "title" => "Welcome",
39
40
  "url" => "/",
40
41
  }
@@ -1,3 +1,3 @@
1
1
  example_id | status | run_time |
2
2
  -------------------------------- | ------ | --------------- |
3
- ./spec/jekyll/draft_spec.rb[1:1] | passed | 0.00007 seconds |
3
+ ./spec/jekyll/draft_spec.rb[1:1] | passed | 0.00041 seconds |
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_draft
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: jekyll
@@ -15,28 +15,42 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 3.5.0
18
+ version: 4.4.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 3.5.0
25
+ version: 4.4.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jekyll_plugin_support
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.1.0
32
+ version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 1.1.0
39
+ version: 3.0.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: sorted_set
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  description: 'This Jekyll filter detects draft documents.
41
55
 
42
56
  '
@@ -86,14 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: 2.6.0
103
+ version: 3.2.0
90
104
  required_rubygems_version: !ruby/object:Gem::Requirement
91
105
  requirements:
92
106
  - - ">="
93
107
  - !ruby/object:Gem::Version
94
108
  version: '0'
95
109
  requirements: []
96
- rubygems_version: 3.6.3
110
+ rubygems_version: 3.7.1
97
111
  specification_version: 4
98
112
  summary: This Jekyll filter detects draft documents.
99
113
  test_files: