jekyll_draft 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b81abf3dd2ad47f14dc0c7a5694642337e779a82e28500510f81eb72622abd8
4
+ data.tar.gz: ef24a39d682076c1d73d29dd286ce8bc5c5162af5fcc6d461aeb275f95b79598
5
+ SHA512:
6
+ metadata.gz: 3d20f8aa839be087692b4da14db1993d762d32aac95f6a6410f9cb17ee377e8516e3e218891602085eb9da1e69e95760765d2aefab370c2131f42b55c5e9ca7e
7
+ data.tar.gz: c191c1ff541451b6a6247c0974d2af7a7ef2d1d11e6aded828f124fe0ffb1167344ec8811c0b7235ce6d9e5dd10c0c7c52e6f2995041a45973715de751930d60
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ require: rubocop-jekyll
2
+ inherit_gem:
3
+ rubocop-jekyll: .rubocop.yml
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - vendor/**/*
8
+ - Gemfile*
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.6
11
+
12
+ Layout/LineLength:
13
+ Max: 150
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 1.0.0 / 2022-04-02
2
+ * Initial version
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Mike Slinn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ jekyll_draft
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_draft.svg)](https://badge.fury.io/rb/jekyll_draft)
3
+ ===========
4
+
5
+ This is a Jekyll plugin that provides two Liquid filters called `is_draft` and `draft_html`.
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).
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
13
+
14
+ ```ruby
15
+ group :jekyll_plugins do
16
+ gem 'jekyll_draft'
17
+ end
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install jekyll_draft
27
+
28
+
29
+ ## Usage
30
+
31
+ ### is_draft
32
+
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.
35
+ ```
36
+ {{ page | is_draft }} => true
37
+ ```
38
+
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ Install development dependencies like this:
45
+ ```
46
+ $ BUNDLE_WITH="development" bundle install
47
+ ```
48
+
49
+ To install this gem onto your local machine, run:
50
+ ```shell
51
+ $ bundle exec rake install
52
+ ```
53
+
54
+ To release a new version,
55
+ 1. Update the version number in `version.rb`.
56
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
57
+ 3. Run the following:
58
+ ```shell
59
+ $ bundle exec rake release
60
+ ```
61
+ The above creates a git tag for the version, commits the created tag,
62
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
63
+
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_draft.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll_draft/version"
4
+
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"
11
+ spec.description = <<~END_OF_DESC
12
+ This Jekyll filter detects draft documents.
13
+ 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"
18
+ 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,
24
+ }
25
+ spec.name = "jekyll_draft"
26
+ spec.post_install_message = <<~END_MESSAGE
27
+
28
+ Thanks for installing #{spec.name}!
29
+
30
+ 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)/!)
35
+ spec.version = JekyllDraftVersion::VERSION
36
+
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"
45
+ end
46
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllDraftVersion
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
4
+
5
+ require "jekyll_plugin_logger"
6
+ require 'yaml'
7
+
8
+ # Detects draft documents
9
+ module Jekyll
10
+ # Define these methods outside of the filter module so they can be invoked externally
11
+ module Draft
12
+ 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)
19
+
20
+ return doc['published']==false if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('published'))
21
+
22
+ return doc.draft if doc.respond_to?(:draft)
23
+
24
+ return doc['draft'] if doc.respond_to?(:[]) || (doc.respond_to?(:key) && doc.key?('draft'))
25
+
26
+ false
27
+ end
28
+
29
+ def draft_html(doc)
30
+ # puts "draft_html invoked from #{doc.path}"
31
+ return '' unless draft?(doc)
32
+
33
+ " <i class='bg_light_yellow' style='padding-left: 0.5em; padding-right: 0.5em;'>Draft</i>"
34
+ end
35
+
36
+ def root(doc, site)
37
+ # puts "root invoked from #{doc.path}"
38
+ return "/index.html" unless doc.respond_to?(:collection)
39
+
40
+ collection_name = doc.collection
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" }
43
+ return index.url if index
44
+
45
+ docs.min.url
46
+ end
47
+
48
+ module_function :draft?, :draft_html, :root
49
+ end
50
+
51
+ module DraftFilter
52
+ def is_draft(doc)
53
+ Draft::draft?(doc)
54
+ end
55
+
56
+ def draft_html(doc)
57
+ Draft::draft_html(doc)
58
+ end
59
+
60
+ # DraftFilter.singleton_class.included_modules
61
+ # [JSON::Ext::Generator::GeneratorMethods::Object, PP::ObjectMixin, Kernel]
62
+ def root(doc, site)
63
+ Draft::root(doc, site)
64
+ end
65
+ end
66
+
67
+ Liquid::Template.register_filter(DraftFilter)
68
+ PluginMetaLogger.instance.info { "Loaded DraftFilter plugin." }
69
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require_relative "../lib/jekyll_draft"
5
+
6
+ RSpec.describe(jekyllDraftName) do
7
+ include jekyllDraftName
8
+
9
+ it "verifies basename" do
10
+ expect(basename("a/b/c/d/e.html")).to be_true
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "liquid"
4
+ require "fileutils"
5
+ require_relative "../lib/jekyll_draft"
6
+
7
+ RSpec.configure do |config|
8
+ config.filter_run :focus
9
+ config.order = "random"
10
+ config.run_all_when_everything_filtered = true
11
+
12
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
13
+ config.example_status_persistence_file_path = "spec/status_persistence.txt"
14
+ end
@@ -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 ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_draft
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Slinn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll_plugin_logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'This Jekyll filter detects draft documents.
42
+
43
+ '
44
+ email:
45
+ - mslinn@mslinn.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - jekyll_draft.gemspec
56
+ - lib/jekyll_draft.rb
57
+ - lib/jekyll_draft/version.rb
58
+ - spec/jekyll_draft_spec.rb
59
+ - spec/spec_helper.rb
60
+ - spec/status_persistence.txt
61
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ allowed_push_host: https://rubygems.org
66
+ bug_tracker_uri: https://github.com/mslinn/jekyll_draft/issues
67
+ changelog_uri: https://github.com/mslinn/jekyll_draft/CHANGELOG.md
68
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#basename
69
+ source_code_uri: https://github.com/mslinn/jekyll_draft
70
+ post_install_message: |2+
71
+
72
+ Thanks for installing jekyll_draft!
73
+
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.6.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.3.3
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: This Jekyll filter detects draft documents.
92
+ test_files:
93
+ - spec/jekyll_draft_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/status_persistence.txt
96
+ ...