jekyll_archive_create 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: b486efbfa5c71cc654c2615b370ee68033e121ab7a4cdee0a74ce6ad6d00a1ba
4
+ data.tar.gz: 58f743530dd3c2b6e3a68e06bb0c7e3d2ab831e42d82d060eec9f16ceb7d9827
5
+ SHA512:
6
+ metadata.gz: cb2334d5cd6ecf52c89fa242f8e521ef2e8214195935a8e3dc41a7cf25d44a5d1fa94885bfc65a2b952d6baf02fc75bd6dfcd7d3fceb0e94dcf13f43c830156b
7
+ data.tar.gz: c63208486b129490beeabffedbc67ed3b7e5550db9f93286af18c21c786add9fc7290bdcf6953bf8146081ae6a5ede9ba056aef330f2aa081db25f1e97cf6419
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ inherit_gem:
2
+ rubocop-jekyll: .rubocop.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - vendor/**/*
7
+ - Gemfile*
8
+ NewCops: enable
9
+ TargetRubyVersion: 2.6
10
+
11
+ Layout/LineLength:
12
+ Max: 150
13
+
14
+ Metrics/AbcSize:
15
+ Max: 20
16
+ Exclude:
17
+ - "test/**/*"
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - "*.gemspec"
22
+ - "Rakefile"
23
+
24
+ Metrics/ClassLength:
25
+ Max: 50
26
+ Exclude:
27
+ - "test/**/*"
28
+
29
+ Metrics/MethodLength:
30
+ Exclude:
31
+ - "test/**/*"
32
+
33
+ Style/CommandLiteral:
34
+ Enabled: false
35
+
36
+ Style/StringLiterals:
37
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 1.0.0 / 2022-03-13
2
+ * Made into a Ruby gem and published on RubyGems.org as [jekyll_archive_create](https://rubygems.org/gems/jekyll_archive_create).
3
+ * `bin/attach` script added for debugging
4
+ * Rubocop standards added
5
+ * Proper versioning and CHANGELOG.md added
6
+
7
+ ## 2020-12-29
8
+ * Initial version published
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 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,113 @@
1
+ jekyll_archive_create
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_archive_create.svg)](https://badge.fury.io/rb/jekyll_archive_create)
3
+ ===========
4
+
5
+ This is a Jekyll plugin that makes tar or zip files based on `_config.yml` entries.
6
+
7
+ In production mode, the archives are built each time Jekyll generates the web site. In development mode, the archives are only built if they do not already exist, or if `delete: true` is set for that archive in `_config.yml`. Archives are placed in the top-level of the Jekyll project, and are copied to `_site` by Jekyll's normal build process. Entries are created in `.gitignore` for each of the generated archives.
8
+
9
+ ## Usage
10
+ This plugin supports 4 types of file specifications:
11
+
12
+ * Absolute filenames (start with /).
13
+ * Filenames relative to the top-level directory of the Jekyll web site (do not preface with . or /).
14
+ * Filenames relative to the user home directory (preface with ~).
15
+ * Executable filenames on the PATH (preface with !).
16
+
17
+ ## `_config.yml` Syntax
18
+ Any number of archives can be specified. Each archive has 3 properties: `archive_name`, `delete` (defaults to true) and `files`. Take care that the dashes have exactly 2 spaces before them, and that the 2 lines following each dash have exactly 4 spaces in front.
19
+
20
+ ```
21
+ make_archive:
22
+ -
23
+ archive_name: cloud9.zip
24
+ delete: true # This is the default, and need not be specified.
25
+ files: [ index.html, 404.html, ~/.ssh/config, /etc/passwd, '!update' ]
26
+ -
27
+ archive_name: cloud9.tar
28
+ delete: false # Do not overwrite the archive if it already exists
29
+ files: [ index.html, 404.html, ~/.ssh/config, /etc/passwd, '!update' ]
30
+ ```
31
+
32
+
33
+ ## Additional Information
34
+ More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
35
+
36
+
37
+ ## Installation
38
+
39
+ Add this line to your Jekyll project's Gemfile, within the `jekyll_plugins` group:
40
+
41
+ ```ruby
42
+ group :jekyll_plugins do
43
+ gem 'jekyll_archive_create'
44
+ end
45
+ ```
46
+
47
+ And then execute:
48
+
49
+ $ bundle install
50
+
51
+ Or install it yourself as:
52
+
53
+ $ gem install jekyll_archive_create
54
+
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies.
59
+
60
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+
63
+ ### Build and Install Locally
64
+ To build and install this gem onto your local machine, run:
65
+ ```shell
66
+ $ rake install:local
67
+ ```
68
+
69
+ The following also does the same thing:
70
+ ```shell
71
+ $ bundle exec rake install
72
+ ```
73
+
74
+ Examine the newly built gem:
75
+ ```shell
76
+ $ gem info jekyll_archive_create
77
+
78
+ *** LOCAL GEMS ***
79
+
80
+ jekyll_archive_create (1.0.0)
81
+ Author: Mike Slinn
82
+ Homepage:
83
+ https://github.com/mslinn/jekyll_archive_create
84
+ License: MIT
85
+ Installed at: /home/mslinn/.gems
86
+
87
+ Generates Jekyll logger with colored output.
88
+ ```
89
+
90
+
91
+ ### Build and Push to RubyGems
92
+ To release a new version,
93
+ 1. Update the version number in `version.rb`.
94
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
95
+ 3. Run the following:
96
+ ```shell
97
+ $ bundle exec rake release
98
+ ```
99
+ The above creates a git tag for the version, commits the created tag,
100
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
101
+
102
+
103
+ ## Contributing
104
+
105
+ 1. Fork the project
106
+ 2. Create a descriptively named feature branch
107
+ 3. Add your feature
108
+ 4. Submit a pull request
109
+
110
+
111
+ ## License
112
+
113
+ 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,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll_archive_create/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ github = "https://github.com/mslinn/jekyll_archive_create"
7
+
8
+ spec.authors = ["Mike Slinn"]
9
+ spec.bindir = "exe"
10
+ spec.description = <<~END_OF_DESC
11
+ Jekyll generator for creating tar and zip files.
12
+ END_OF_DESC
13
+ spec.email = ["mslinn@mslinn.com"]
14
+ spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
15
+ spec.homepage = "https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#make_archive"
16
+ spec.license = "MIT"
17
+ spec.metadata = {
18
+ "allowed_push_host" => "https://rubygems.org",
19
+ "bug_tracker_uri" => "#{github}/issues",
20
+ "changelog_uri" => "#{github}/CHANGELOG.md",
21
+ "homepage_uri" => spec.homepage,
22
+ "source_code_uri" => github,
23
+ }
24
+ spec.name = "jekyll_archive_create"
25
+ spec.post_install_message = <<~END_MESSAGE
26
+
27
+ Thanks for installing #{spec.name}!
28
+
29
+ END_MESSAGE
30
+ spec.require_paths = ["lib"]
31
+ spec.required_ruby_version = ">= 2.6.0"
32
+ spec.summary = "Jekyll generator for creating tar and zip files."
33
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
34
+ spec.version = JekyllArchiveCreate::VERSION
35
+
36
+ spec.add_dependency "jekyll", ">= 3.5.0"
37
+ spec.add_dependency "jekyll_plugin_logger", "~> 2.0.0"
38
+
39
+ spec.add_development_dependency "debase"
40
+ # spec.add_development_dependency "rubocop-jekyll"
41
+ # spec.add_development_dependency "rubocop-rake"
42
+ # spec.add_development_dependency "rubocop-rspec"
43
+ spec.add_development_dependency "ruby-debug-ide"
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllArchiveCreate
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "jekyll_plugin_logger"
5
+ require "ptools"
6
+ require "rubygems"
7
+ require "rubygems/package"
8
+ require "tmpdir"
9
+ require "zlib"
10
+ require "zip"
11
+ require_relative "jekyll_archive_create/version"
12
+
13
+ module Jekyll
14
+ # Makes tar or zip file based on _config.yml entry
15
+ class MakeArchive < Jekyll::Generator # rubocop:disable Metrics/ClassLength
16
+ priority :high
17
+
18
+ # Method prescribed by the Jekyll plugin lifecycle.
19
+ # @param site [Jekyll.Site] Automatically provided by Jekyll plugin mechanism
20
+ # @return [void]
21
+ def generate(site)
22
+ @logger = PluginMetaLogger.instance.new_logger(self)
23
+ @live_reload = site.config["livereload"]
24
+
25
+ archive_config = site.config["make_archive"]
26
+ return if archive_config.nil?
27
+
28
+ archive_config.each do |config|
29
+ setup_instance_variables config
30
+ create_archive site.source
31
+ site.keep_files << @archive_name
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def setup_instance_variables(config)
38
+ @archive_name = config["archive_name"] # Relative to _site
39
+ abort "Error: archive_name was not specified in _config.yml." if @archive_name.nil?
40
+
41
+ @archive_type = archive_type(@archive_name)
42
+
43
+ @archive_files = config["files"].compact
44
+ abort "Error: archive files were not specified in _config.yml." if @archive_files.nil?
45
+
46
+ delete_archive = config["delete"]
47
+ @force_delete = delete_archive.nil? ? !@live_reload : delete_archive
48
+
49
+ @logger.debug { "@archive_name=#{@archive_name}; @live_reload=#{@live_reload}; @force_delete=#{@force_delete}; @archive_files=#{@archive_files}" }
50
+ end
51
+
52
+ def archive_type(archive_name)
53
+ if archive_name.end_with? ".zip"
54
+ :zip
55
+ elsif archive_name.end_with? ".tar"
56
+ :tar
57
+ else
58
+ abort "Error: archive must be zip or tar; #{archive_name} is of an unknown archive type."
59
+ end
60
+ end
61
+
62
+ def create_archive(source)
63
+ archive_name_full = "#{source}/#{@archive_name}"
64
+ archive_exists = File.exist?(archive_name_full)
65
+ return if archive_exists && @live_reload
66
+
67
+ @logger.debug { "#{archive_name_full} exists? #{archive_exists}" }
68
+ if archive_exists && @force_delete
69
+ @logger.debug "Deleting old #{archive_name_full}"
70
+ File.delete(archive_name_full)
71
+ end
72
+
73
+ make_tar_or_zip(archive_exists, archive_name_full, source)
74
+
75
+ @logger.debug { "Looking for #{@archive_name} in .gitignore..." }
76
+ return if File.foreach(".gitignore").grep(%r!^#{@archive_name}\n?!).any?
77
+
78
+ warn "#{@archive_name} not found in .gitignore, adding entry."
79
+ File.open(".gitignore", "a") do |f|
80
+ f.puts File.basename(@archive_name)
81
+ end
82
+ end
83
+
84
+ def make_tar(tar_name, source)
85
+ Dir.mktmpdir do |dirname|
86
+ @archive_files.each do |filename|
87
+ fn, filename_full = qualify_file_name(filename, source)
88
+ @logger.debug { "Copying #{filename_full} to temporary directory #{dirname}; filename=#{filename}; fn=#{fn}" }
89
+ FileUtils.copy(filename_full, dirname)
90
+ end
91
+ write_tar(tar_name, dirname)
92
+ end
93
+ end
94
+
95
+ def make_tar_or_zip(archive_exists, archive_name_full, source)
96
+ if !archive_exists || @force_delete
97
+ @logger.debug { "Making #{archive_name_full}" }
98
+ case @archive_type
99
+ when :tar
100
+ make_tar(archive_name_full, source)
101
+ when :zip
102
+ make_zip(archive_name_full, source)
103
+ end
104
+ end
105
+ end
106
+
107
+ def make_zip(zip_name, source)
108
+ Zip.default_compression = Zlib::DEFAULT_COMPRESSION
109
+ Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
110
+ @archive_files.each do |filename|
111
+ filename_in_archive, filename_original = qualify_file_name(filename, source)
112
+ @logger.debug { "make_zip: adding #{filename_original} to #{zip_name} as #{filename_in_archive}" }
113
+ zipfile.add(filename_in_archive, filename_original)
114
+ end
115
+ end
116
+ end
117
+
118
+ def write_tar(tar_name, dirname)
119
+ # Modified from https://gist.github.com/sinisterchipmunk/1335041/5be4e6039d899c9b8cca41869dc6861c8eb71f13
120
+ File.open(tar_name, "wb") do |tarfile|
121
+ Gem::Package::TarWriter.new(tarfile) do |tar|
122
+ Dir[File.join(dirname, "**/*")].each do |filename|
123
+ write_tar_entry(tar, dirname, filename)
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ def write_tar_entry(tar, dirname, filename)
130
+ mode = File.stat(filename).mode
131
+ relative_file = filename.sub(%r!^#{Regexp.escape dirname}/?!, "")
132
+ if File.directory?(filename)
133
+ tar.mkdir relative_file, mode
134
+ else
135
+ tar.add_file relative_file, mode do |tf|
136
+ File.open(filename, "rb") { |f| tf.write f.read }
137
+ end
138
+ end
139
+ end
140
+
141
+ # @return tuple of filename (without path) and fully qualified filename
142
+ def qualify_file_name(path, source)
143
+ case path[0]
144
+ when "/" # Is the file absolute?
145
+ @logger.debug { "Absolute filename: #{path}" }
146
+ [File.basename(path), path]
147
+ when "!" # Should the file be found on the PATH?
148
+ clean_path = path[1..-1]
149
+ filename_full = File.which(clean_path)
150
+ abort "Error: #{clean_path} is not on the PATH." if filename_full.nil?
151
+
152
+ @logger.debug { "File on PATH: #{clean_path} -> #{filename_full}" }
153
+ [File.basename(clean_path), filename_full]
154
+ when "~" # Is the file relative to user's home directory?
155
+ clean_path = path[2..-1]
156
+ filename_full = File.join(ENV["HOME"], clean_path)
157
+ @logger.debug { "File in home directory: #{clean_path} -> #{filename_full}" }
158
+ [File.basename(clean_path), filename_full]
159
+ else # The file is relative to the Jekyll website top-level directory
160
+ @logger.debug { "Relative filename: #{path}" }
161
+ [File.basename(path), File.join(source, path)] # join yields the fully qualified path
162
+ end
163
+ end
164
+
165
+ PluginMetaLogger.instance.logger.info { "Loaded jekyll_archive_create v#{JekyllArchiveCreate::VERSION} plugin." }
166
+ end
167
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_archive_create
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: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: debase
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-debug-ide
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'Jekyll generator for creating tar and zip files.
70
+
71
+ '
72
+ email:
73
+ - mslinn@mslinn.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - jekyll_archive_create.gemspec
84
+ - lib/jekyll_archive_create.rb
85
+ - lib/jekyll_archive_create/version.rb
86
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#make_archive
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org
91
+ bug_tracker_uri: https://github.com/mslinn/jekyll_archive_create/issues
92
+ changelog_uri: https://github.com/mslinn/jekyll_archive_create/CHANGELOG.md
93
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#make_archive
94
+ source_code_uri: https://github.com/mslinn/jekyll_archive_create
95
+ post_install_message: |2+
96
+
97
+ Thanks for installing jekyll_archive_create!
98
+
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.6.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.1.4
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Jekyll generator for creating tar and zip files.
117
+ test_files: []