jekyll_outline 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: b4d559d814621351a2af4cb4100c83f375de62f7c66c5d21efbe60e651df1564
4
+ data.tar.gz: f97c2a34d62012e1b43ea6c70980747376830f72165dd254533c7a142ac2fd5f
5
+ SHA512:
6
+ metadata.gz: 1c2056fc66da354151c7676d66e16f07de1ba445d45e88f665a32496587d5985e8a2dea33577d1d8f65dba2559d4bced9468166779214067f1ceb95f53625bcb
7
+ data.tar.gz: b923a57ea06fac9460ceb273f26fb49e441579146446b50aabbaf91dfc51cc8e6690b94a4e853fe9b4654907a9dd1d02b35757666833e51f2a6e3f89220ce0f2
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ require: rubocop-jekyll
2
+ inherit_gem:
3
+ rubocop-jekyll: .rubocop.yml
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - vendor/**/*
8
+ - Gemfile*
9
+ - '*.gemspec' # This does nothing. Why?
10
+ NewCops: enable
11
+ TargetRubyVersion: 2.6
12
+
13
+ Layout/LineLength:
14
+ Max: 150
15
+
16
+ # Gemspec/RequireMFA:
17
+ # enable: false
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,77 @@
1
+ `jekyll_outline`
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_outline.svg)](https://badge.fury.io/rb/jekyll_outline)
3
+ ===========
4
+
5
+ `jekyll_outline` Jekyll tag plugin that creates a clickable table of contents.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jekyll_outline'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jekyll_outline
23
+
24
+
25
+ ## Additional Information
26
+ More information is available on
27
+ [Mike Slinn’s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
28
+
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ Install development dependencies like this:
35
+ ```
36
+ $ BUNDLE_WITH="development" bundle install
37
+ ```
38
+
39
+ To build and install this gem onto your local machine, run:
40
+ ```shell
41
+ $ bundle exec rake install
42
+ jekyll_outline 1.0.0 built to pkg/jekyll_outline-0.1.0.gem.
43
+ jekyll_outline (1.0.0) installed.
44
+
45
+ $ gem info jekyll_outline
46
+
47
+ *** LOCAL GEMS ***
48
+
49
+ jekyll_outline (1.0.0)
50
+ Author: Mike Slinn
51
+ Homepage:
52
+ https://github.com/mslinn/jekyll_outline
53
+ License: MIT
54
+ Installed at: /home/mslinn/.gems
55
+
56
+ Generates Jekyll logger with colored output.
57
+ ```
58
+
59
+ To release a new version,
60
+ 1. Update the version number in `version.rb`.
61
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
62
+ 3. Run the following:
63
+ ```shell
64
+ $ bundle exec rake release
65
+ ```
66
+ The above creates a git tag for the version, commits the created tag,
67
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
68
+
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_outline.
73
+
74
+
75
+ ## License
76
+
77
+ 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,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll_outline/version"
4
+
5
+ # rubocop:disable Metrics/BlockLength
6
+ Gem::Specification.new do |spec|
7
+ github = "https://github.com/mslinn/jekyll_outline"
8
+
9
+ spec.authors = ["Mike Slinn"]
10
+ spec.bindir = "exe"
11
+ spec.description = <<~END_OF_DESC
12
+ Jekyll tag plugin that creates a clickable table of contents.
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#run"
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_outline"
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 = "Jekyll tag plugin that creates a clickable table of contents."
34
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
35
+ spec.version = JekyllOutlineVersion::VERSION
36
+
37
+ spec.add_dependency "jekyll", ">= 3.5.0"
38
+ spec.add_dependency "jekyll_draft"
39
+ spec.add_dependency "jekyll_plugin_logger"
40
+
41
+ # spec.add_development_dependency "debase"
42
+ # spec.add_development_dependency "rubocop-jekyll"
43
+ # spec.add_development_dependency "rake"
44
+ # spec.add_development_dependency "rubocop-rake"
45
+ # spec.add_development_dependency "rubocop-rspec"
46
+ # spec.add_development_dependency "ruby-debug-ide"
47
+ end
48
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllOutlineVersion
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
4
+
5
+ require "jekyll_draft"
6
+ require "jekyll_plugin_logger"
7
+ require 'yaml'
8
+
9
+ module Outline
10
+ PLUGIN_NAME = "outline"
11
+
12
+ # Interleaves with docs
13
+ class Header
14
+ attr_accessor :order, :title
15
+
16
+ def initialize(yaml)
17
+ @order = yaml[0]
18
+ @published = true
19
+ @title = yaml[1]
20
+ end
21
+
22
+ def to_s
23
+ <<~END_STR
24
+ <h3 id="title_#{order}">#{title}</h3>
25
+ END_STR
26
+ end
27
+ end
28
+
29
+ # Makes outlines for Jekyll pages
30
+ class OutlineTag < Liquid::Block
31
+ FIXNUM_MAX = 2**(0.size * 8 - 2) - 1
32
+
33
+ # Called by Jekyll only once to register the tag.
34
+ # @param tag_name [String] is the name of the tag, which we already know.
35
+ # @param argument_string [String] the arguments from the web page.
36
+ # @param _parse_context [Liquid::ParseContext] hash that stores Liquid options.
37
+ # By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
38
+ # a boolean parameter that determines if error messages should display the line number the error occurred.
39
+ # This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
40
+ # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
41
+ # @return [void]
42
+ def initialize(tag_name, argument_string, _parse_context)
43
+ super
44
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
45
+ @collection_name = argument_string.strip
46
+ abort "OutlineTag: collection_name was not specified" unless @collection_name
47
+ end
48
+
49
+ # Method prescribed by the Jekyll plugin lifecycle.
50
+ # @param liquid_context [Liquid::Context]
51
+ # @return [String]
52
+ def render(liquid_context)
53
+ headers = make_headers(super) # Process the block content.
54
+ @site = liquid_context.registers[:site]
55
+ collection = headers + obtain_docs(@collection_name)
56
+ <<~HEREDOC
57
+ <div class="posts">
58
+ #{make_entries(collection).join("\n")}
59
+ </div>
60
+ HEREDOC
61
+ end
62
+
63
+ private
64
+
65
+ def header?(variable)
66
+ variable.instance_of?(Header)
67
+ end
68
+
69
+ def make_headers(content)
70
+ yaml = YAML.safe_load content
71
+ yaml.map { |entry| Header.new entry }
72
+ end
73
+
74
+ def make_entries(collection) # rubocop:disable Metrics/MethodLength
75
+ sorted = collection.sort_by(&obtain_order)
76
+ pruned = remove_empty_headers(sorted)
77
+ pruned.map do |entry|
78
+ if entry.instance_of? Header
79
+ <<~END_ENTRY
80
+ <span></span> <span>#{entry}</span>
81
+ END_ENTRY
82
+ else
83
+ date = entry.data['last_modified_at'] # "%Y-%m-%d"
84
+ draft = Jekyll::Draft.draft_html(entry)
85
+ <<~END_ENTRY
86
+ <span>#{date}</span> <span><a href="#{entry.url}">#{entry.data['title']}</a>#{draft}</span>
87
+ END_ENTRY
88
+ end
89
+ end
90
+ end
91
+
92
+ # Ignores files called index.html
93
+ def obtain_docs(collection_name)
94
+ abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
95
+ @site
96
+ .collections[collection_name]
97
+ .docs
98
+ .reject { |doc| doc.path.end_with? "index.html" }
99
+ end
100
+
101
+ # Sort entries without an order property at the end
102
+ def obtain_order
103
+ proc do |entry|
104
+ if entry.respond_to? :data
105
+ entry.data.key?('order') ? entry.data['order'] : FIXNUM_MAX
106
+ else
107
+ entry.order
108
+ end
109
+ end
110
+ end
111
+
112
+ def remove_empty_headers(array)
113
+ i = 0
114
+ while i < array.length - 1
115
+ if header?(array[i]) && header?(array[i + 1])
116
+ array.delete_at(i)
117
+ else
118
+ i += 1
119
+ end
120
+ end
121
+ if header?(array.last)
122
+ array.delete_at(array.length - 1)
123
+ end
124
+ array
125
+ end
126
+ end
127
+ end
128
+
129
+ # PluginMetaLogger.instance.info { "Loaded #{JekyllPluginTagTemplate::PLUGIN_NAME} v#{JekyllPluginTemplateVersion::VERSION} plugin." }
130
+ PluginMetaLogger.instance.info { "Loaded Outline plugin." }
131
+ Liquid::Template.register_tag(Outline::PLUGIN_NAME, Outline::OutlineTag)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require_relative "../lib/jekyll_outline"
5
+
6
+ RSpec.describe(Jekyll) do
7
+ include Jekyll
8
+
9
+ it "is created properly" do
10
+ # run_tag = RunTag.new("run", "echo asdf")
11
+ # output = run_tag.render(context)
12
+ # expect(output).to eq("asdf")
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require_relative "../lib/jekyll_outline"
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run :focus
8
+ config.order = "random"
9
+ config.run_all_when_everything_filtered = true
10
+
11
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
12
+ config.example_status_persistence_file_path = "spec/status_persistence.txt"
13
+ end
@@ -0,0 +1,3 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------- | ------ | --------------- |
3
+ ./spec/jekyll_outline_spec.rb[1:1] | passed | 0.00023 seconds |
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_outline
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_draft
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
+ - !ruby/object:Gem::Dependency
42
+ name: jekyll_plugin_logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'Jekyll tag plugin that creates a clickable table of contents.
56
+
57
+ '
58
+ email:
59
+ - mslinn@mslinn.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".rubocop.yml"
65
+ - CHANGELOG.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - jekyll_run.gemspec
70
+ - lib/jekyll_outline.rb
71
+ - lib/jekyll_outline/version.rb
72
+ - spec/jekyll_outline_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/status_persistence.txt
75
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#run
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ bug_tracker_uri: https://github.com/mslinn/jekyll_outline/issues
81
+ changelog_uri: https://github.com/mslinn/jekyll_outline/CHANGELOG.md
82
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#run
83
+ source_code_uri: https://github.com/mslinn/jekyll_outline
84
+ post_install_message: |2+
85
+
86
+ Thanks for installing jekyll_outline!
87
+
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.6.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.3.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Jekyll tag plugin that creates a clickable table of contents.
106
+ test_files:
107
+ - spec/jekyll_outline_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/status_persistence.txt
110
+ ...