jekyll_archive_display 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: 37451a8e360f75ae492f4963417d64a1ea18119ec7102f2c14e37852444c2b30
4
+ data.tar.gz: e9014b204916062edc00fcd57e60d835f73e9770108ceca09437ce94ac9ed2c9
5
+ SHA512:
6
+ metadata.gz: ed9d3c414acf0d055a2a583f4bcc8018425b680115c35398f63990c78f1013675fe708a53cbfe6906c4ca3be3bcb85a23f4fa3ec7798c99357b722d7efb8754b
7
+ data.tar.gz: f0cf471adf5afc40c04706c5182d1a1f4b0737a7f15b82e84f45e3a717f7eaad4fe8a45226722af1ae591a702bc6d624ab32d52545e194dc9a0e4524ba695856
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
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/BlockAlignment:
14
+ Enabled: false
15
+
16
+ Layout/LineLength:
17
+ Max: 150
18
+
19
+ Layout/MultilineMethodCallIndentation:
20
+ Enabled: false
21
+
22
+ # Gemspec/RequireMFA:
23
+ # Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 1.0.0 / 2022-03-18
2
+ * Published as a gem
3
+
4
+ ## 2020-10-03
5
+ * Initial version published at https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html
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,129 @@
1
+ `jekyll_archive_display`
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_archive_display.svg)](https://badge.fury.io/rb/jekyll_archive_display)
3
+ ===========
4
+
5
+ `jekyll_archive_display` is a Jekyll plugin, packaged as a Ruby gem, that lists the names and contents of each entry in a `tar` file.
6
+
7
+ The following HTML is emitted for each text file within the `tar`:
8
+ ```HTML
9
+ <div class='codeLabel'>{tar_entry.full_name}</div>
10
+ <pre data-lt-active='false'>{file_contents}</pre>
11
+ ```
12
+
13
+
14
+ Binary files are displayed like this:
15
+
16
+ **`usr/bin/ruby2.7 (application/x-sharedlib; charset=binary)`**<br>
17
+ *Binary file*
18
+
19
+
20
+ ## Syntax
21
+ ```
22
+ {% archive_display filename.tar %}
23
+ ```
24
+
25
+ ## Additional Information
26
+ More information is available on Mike Slinn's web site about
27
+ [Jekyll plugins](https://www.mslinn.com/blog/index.html#Jekyll).
28
+
29
+
30
+ ## Installation
31
+
32
+ ### Install dependencies:
33
+ - Ubuntu:
34
+ ```shell
35
+ sudo apt install libmagic-dev
36
+ ```
37
+ - Mac:
38
+ ```shell
39
+ brew install libmagic
40
+ ```
41
+
42
+ ### Gems
43
+ Add this line to your Jekyll website's `_config.yml`:
44
+
45
+ ```ruby
46
+ group :jekyll_plugins do
47
+ gem 'jekyll_archive_display'
48
+ end
49
+ ```
50
+
51
+ Also add it to `_config.yml`:
52
+ ```yaml
53
+ plugins:
54
+ - jekyll_archive_display
55
+ ```
56
+
57
+ Install all of the dependent gems of your Jekyll website by typing:
58
+
59
+ $ bundle install
60
+
61
+ Or install just this one gem by typing:
62
+
63
+ $ gem install jekyll_archive_display
64
+
65
+
66
+ ## Additional Information
67
+ More information is available on
68
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
69
+
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies.
74
+
75
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+
78
+ ### Build and Install Locally
79
+ To build and install this gem onto your local machine, run:
80
+ ```shell
81
+ $ rake install:local
82
+ ```
83
+
84
+ The following also does the same thing:
85
+ ```shell
86
+ $ bundle exec rake install
87
+ jekyll_archive_display 1.0.0 built to pkg/jekyll_archive_display-0.1.0.gem.
88
+ jekyll_archive_display (1.0.0) installed.
89
+ ```
90
+
91
+ Examine the newly built gem:
92
+ ```shell
93
+ $ gem info jekyll_archive_display
94
+
95
+ *** LOCAL GEMS ***
96
+
97
+ jekyll_archive_display (1.0.0)
98
+ Author: Mike Slinn
99
+ Homepage:
100
+ https://github.com/mslinn/jekyll_archive_display
101
+ License: MIT
102
+ Installed at: /home/mslinn/.gems
103
+
104
+ Jekyll tag plugin that lists the names and contents of each entry in a tar file.
105
+ ```
106
+
107
+ ### Build and Push to RubyGems
108
+ To release a new version,
109
+ 1. Update the version number in `version.rb`.
110
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
111
+ 3. Run the following:
112
+ ```shell
113
+ $ bundle exec rake release
114
+ ```
115
+ The above creates a git tag for the version, commits the created tag,
116
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
117
+
118
+
119
+ ## Contributing
120
+
121
+ 1. Fork the project
122
+ 2. Create a descriptively named feature branch
123
+ 3. Add your feature
124
+ 4. Submit a pull request
125
+
126
+
127
+ ## License
128
+
129
+ 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,10 @@
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
8
+
9
+ require "bundler/gem_tasks"
10
+ task :default => %i[]
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/archive_display/version"
4
+
5
+ # rubocop:disable Metrics/BlockLength
6
+ Gem::Specification.new do |spec|
7
+ github = "https://github.com/mslinn/jekyll_archive_display"
8
+
9
+ spec.authors = ["Mike Slinn"]
10
+ spec.bindir = "exe"
11
+ spec.description = <<~END_OF_DESC
12
+ Jekyll tag plugin that lists the names and contents of each entry in a tar file.
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#archiveDisplay"
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_archive_display"
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 lists the names and contents of each entry in a tar file."
34
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
35
+ spec.version = JekyllArchiveDisplay::VERSION
36
+
37
+ spec.add_dependency "jekyll", ">= 3.5.0"
38
+ spec.add_dependency "jekyll_plugin_logger"
39
+ spec.add_dependency "ruby-filemagic", "= 0.7.3"
40
+ spec.add_dependency "rubyzip"
41
+
42
+ spec.add_development_dependency "debase"
43
+ # spec.add_development_dependency "rubocop-jekyll"
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 JekyllArchiveDisplay
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll_plugin_logger"
4
+ require "rubygems/package"
5
+ require "ruby-filemagic"
6
+ require_relative "archive_display/version"
7
+
8
+ module JekyllPluginArchiveDisplayName
9
+ PLUGIN_NAME = "archive_display"
10
+ end
11
+
12
+ # Jekyll tag plugin that displays information about the contents of tar files
13
+ module Jekyll
14
+ # Executes a program and returns the output from STDOUT.
15
+ class ArchiveDisplayTag < Liquid::Tag
16
+ # @param tag_name [String] is the name of the tag, which we already know.
17
+ # @param command_line [Hash, String, Liquid::Tag::Parser] the arguments from the web page.
18
+ # @param tokens [Liquid::ParseContext] tokenized command line
19
+ # @return [void]
20
+ def initialize(tag_name, archive_name, tokens)
21
+ super(tag_name, archive_name, tokens)
22
+ @logger = PluginMetaLogger.instance.new_logger(self)
23
+ @archive_name = archive_name.strip
24
+ end
25
+
26
+ # Method prescribed by the Jekyll plugin lifecycle.
27
+ # @return [String]
28
+ def render(context)
29
+ source = context.registers[:site].config["source"]
30
+ tar_name = "#{source}/#{@archive_name}"
31
+ @logger.debug "tar_name=#{tar_name}"
32
+ traverse_tar(tar_name)
33
+ end
34
+
35
+ private
36
+
37
+ def display_entry(entry)
38
+ heading = "<div class='codeLabel'>#{entry[:name]} <span style='font-size: smaller'>(#{entry[:fm_type]})</span></div>"
39
+ if entry[:is_text]
40
+ "#{heading}\n<pre data-lt-active='false'>#{entry[:content]}</pre>"
41
+ else
42
+ "#{heading}\n<p><i>Binary file</i></pre>"
43
+ end
44
+ end
45
+
46
+ # Process one tar entry
47
+ def tar_entry(entry, file_magic)
48
+ content = entry.read
49
+ fm_type = file_magic.buffer(content)
50
+ {
51
+ :name => entry.full_name,
52
+ :content => content.strip,
53
+ :is_text => (fm_type.start_with? "text"),
54
+ :fm_type => fm_type,
55
+ }
56
+ end
57
+
58
+ # Walk through a `tar` file.
59
+ #
60
+ # Modified from this {https://gist.github.com/sinisterchipmunk/1335041/5be4e6039d899c9b8cca41869dc6861c8eb71f13 gist by sinisterchipmunk }.
61
+ # See https://docs.ruby-lang.org/en/2.6.0/Gem/Package/TarReader.html
62
+ #
63
+ # @param tar_name [String] Name of tar file to examine.
64
+ # @return [String] containing HTML describing the contents of the `tar`.
65
+ def traverse_tar(tar_name)
66
+ file_magic = FileMagic.new(FileMagic::MAGIC_MIME)
67
+ result = ""
68
+ File.open(tar_name, "rb") do |file|
69
+ Gem::Package::TarReader.new(file) do |tar|
70
+ contents = tar.each.map do |entry|
71
+ next unless entry.file?
72
+
73
+ tar_entry(entry, file_magic)
74
+ end
75
+ result = contents
76
+ .compact
77
+ .sort_by { |entry| entry[:name] }
78
+ .map { |entry| display_entry entry }
79
+ .join("\n")
80
+ end
81
+ end
82
+ @logger.debug { "traverse_tar: result = #{result}" }
83
+ result
84
+ end
85
+ end
86
+ end
87
+
88
+ PluginMetaLogger.instance.info { "Loaded #{JekyllPluginArchiveDisplayName::PLUGIN_NAME} v#{JekyllArchiveDisplay::VERSION} plugin." }
89
+ Liquid::Template.register_tag(JekyllPluginArchiveDisplayName::PLUGIN_NAME, Jekyll::ArchiveDisplayTag)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/archive_display"
4
+
5
+ RSpec.describe Jekyll do
6
+ include Jekyll
7
+
8
+ let(:config) { instance_double("Configuration") }
9
+ let(:context) {
10
+ context_ = instance_double("Liquid::Context")
11
+ context_.config = config
12
+ context_
13
+ }
14
+
15
+ it "works" do
16
+ # expect(output).to eq("asdf")
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "liquid"
4
+ require "jekyll_plugin_logger"
5
+
6
+ require_relative "../lib/archive_display"
7
+
8
+ RSpec.configure do |config|
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ config.order = "random"
12
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_archive_display
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-03-25 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
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-filemagic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyzip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: debase
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-debug-ide
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: 'Jekyll tag plugin that lists the names and contents of each entry in
98
+ a tar file.
99
+
100
+ '
101
+ email:
102
+ - mslinn@mslinn.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".rubocop.yml"
108
+ - CHANGELOG.md
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - jekyll_archive_display.gemspec
113
+ - lib/archive_display.rb
114
+ - lib/archive_display/version.rb
115
+ - spec/archive_display.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#archiveDisplay
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ allowed_push_host: https://rubygems.org
122
+ bug_tracker_uri: https://github.com/mslinn/jekyll_archive_display/issues
123
+ changelog_uri: https://github.com/mslinn/jekyll_archive_display/CHANGELOG.md
124
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#archiveDisplay
125
+ source_code_uri: https://github.com/mslinn/jekyll_archive_display
126
+ post_install_message: |2+
127
+
128
+ Thanks for installing jekyll_archive_display!
129
+
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 2.6.0
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubygems_version: 3.1.4
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Jekyll tag plugin that lists the names and contents of each entry in a tar
148
+ file.
149
+ test_files:
150
+ - spec/archive_display.rb
151
+ - spec/spec_helper.rb