gryphon_nest 4.2.0 → 4.2.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 +4 -4
- data/bin/nest +1 -2
- data/lib/gryphon_nest/compressors/brotli_compressor.rb +22 -0
- data/lib/gryphon_nest/compressors/gzip_compressor.rb +24 -0
- data/lib/gryphon_nest/compressors.rb +41 -0
- data/lib/gryphon_nest/version.rb +1 -1
- data/lib/gryphon_nest.rb +17 -18
- metadata +5 -3
- data/lib/gryphon_nest/gzip_compressor.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd5e55ab64ee1c053587293099a0423628f1d9075e4c73e6257fc029feefd47
|
4
|
+
data.tar.gz: b151fc9e7d09114ea9d47c1118f6b275658296f970cd0982a6145ff8c00b0c24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee54f2a45e67a122f2fa2416e2c26500a852f9e729060d7adff553a6e44b0bd897232f09aaef6224f44f102ac861918ced09aecdea0c4084604a867aa669dbb1
|
7
|
+
data.tar.gz: 2cd88219d657d3cd7d8e8d526e8d02a094ea89c684129e644c139d9dce0f2003eaa37b208d86f83086cfa67f65589bded6b71ec0ae8511bd323de1100b98cea6
|
data/bin/nest
CHANGED
@@ -48,8 +48,7 @@ begin
|
|
48
48
|
|
49
49
|
command = ARGV.fetch(0, 'build')
|
50
50
|
|
51
|
-
nest = GryphonNest::Nest.new(options[:force])
|
52
|
-
nest.compressor = GryphonNest::GzipCompressor.new if options[:compress]
|
51
|
+
nest = GryphonNest::Nest.new(options[:compress], options[:force])
|
53
52
|
|
54
53
|
case command
|
55
54
|
when 'clean'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module GryphonNest
|
4
|
+
module Compressors
|
5
|
+
class BrotliCompressor
|
6
|
+
def extname
|
7
|
+
'.br'
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param file [Pathname]
|
11
|
+
def compress(file)
|
12
|
+
compressed = "#{file}#{extname}"
|
13
|
+
|
14
|
+
File.open(compressed, 'wb') do |br|
|
15
|
+
writer = Brotli::Writer.new(br)
|
16
|
+
writer.write(IO.binread(file))
|
17
|
+
writer.close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zlib'
|
4
|
+
|
5
|
+
module GryphonNest
|
6
|
+
module Compressors
|
7
|
+
class GzipCompressor
|
8
|
+
def extname
|
9
|
+
'.gz'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param file [Pathname]
|
13
|
+
def compress(file)
|
14
|
+
compressed = "#{file}#{extname}"
|
15
|
+
|
16
|
+
Zlib::GzipWriter.open(compressed, Zlib::BEST_COMPRESSION) do |gz|
|
17
|
+
gz.mtime = file.mtime
|
18
|
+
gz.orig_name = file.to_s
|
19
|
+
gz.write IO.binread(file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GryphonNest
|
4
|
+
module Compressors
|
5
|
+
autoload :BrotliCompressor, 'gryphon_nest/compressors/brotli_compressor'
|
6
|
+
autoload :GzipCompressor, 'gryphon_nest/compressors/gzip_compressor'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
COMPRESSABLE_FILETYPES = %w[
|
10
|
+
.html
|
11
|
+
.htm
|
12
|
+
.xhtml
|
13
|
+
.txt
|
14
|
+
.csv
|
15
|
+
.css
|
16
|
+
.js
|
17
|
+
.mjs
|
18
|
+
.md
|
19
|
+
.xml
|
20
|
+
.svg
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
# @param file [Pathname]
|
24
|
+
# @return [Boolean]
|
25
|
+
def can_compress?(file)
|
26
|
+
file.size >= 20 && COMPRESSABLE_FILETYPES.include?(file.extname)
|
27
|
+
end
|
28
|
+
|
29
|
+
# return [Array<Object>]
|
30
|
+
def create
|
31
|
+
compressors = [GzipCompressor.new]
|
32
|
+
|
33
|
+
require 'brotli'
|
34
|
+
compressors.append(BrotliCompressor.new)
|
35
|
+
compressors
|
36
|
+
rescue LoadError
|
37
|
+
compressors
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/gryphon_nest/version.rb
CHANGED
data/lib/gryphon_nest.rb
CHANGED
@@ -6,8 +6,8 @@ require 'pathname'
|
|
6
6
|
require 'webrick'
|
7
7
|
|
8
8
|
module GryphonNest
|
9
|
+
autoload :Compressors, 'gryphon_nest/compressors'
|
9
10
|
autoload :Errors, 'gryphon_nest/errors'
|
10
|
-
autoload :GzipCompressor, 'gryphon_nest/gzip_compressor'
|
11
11
|
autoload :LayoutFile, 'gryphon_nest/layout_file'
|
12
12
|
autoload :Logging, 'gryphon_nest/logging'
|
13
13
|
autoload :Processors, 'gryphon_nest/processors'
|
@@ -21,15 +21,13 @@ module GryphonNest
|
|
21
21
|
LAYOUT_FILE = 'layout.mustache'
|
22
22
|
|
23
23
|
class Nest
|
24
|
-
# @
|
25
|
-
attr_writer :compressor
|
26
|
-
|
24
|
+
# @param compress [Boolean]
|
27
25
|
# @param force [Boolean]
|
28
|
-
def initialize(force)
|
26
|
+
def initialize(compress, force)
|
29
27
|
@processors = Processors.create
|
30
28
|
@logger = Logging.create
|
31
29
|
@force = force
|
32
|
-
@
|
30
|
+
@compressors = compress ? Compressors.create : []
|
33
31
|
@modifications = 0
|
34
32
|
end
|
35
33
|
|
@@ -41,7 +39,7 @@ module GryphonNest
|
|
41
39
|
|
42
40
|
Dir.mkdir(BUILD_DIR) unless Dir.exist?(BUILD_DIR)
|
43
41
|
|
44
|
-
existing_files = glob(BUILD_DIR, '
|
42
|
+
existing_files = glob(BUILD_DIR, '{!.gz,!.br}')
|
45
43
|
content_files = glob(CONTENT_DIR)
|
46
44
|
processed_files = content_files.collect { |src| process_file(src) }
|
47
45
|
files_to_delete = existing_files.difference(processed_files)
|
@@ -99,15 +97,12 @@ module GryphonNest
|
|
99
97
|
|
100
98
|
# @param file [Pathname]
|
101
99
|
def compress_file(file)
|
102
|
-
return
|
100
|
+
return if @compressors.empty?
|
103
101
|
|
104
|
-
|
105
|
-
unless @compressor.can_compress?(file)
|
106
|
-
@logger.info("Skipping #{file}")
|
107
|
-
return
|
108
|
-
end
|
102
|
+
return unless Compressors.can_compress?(file)
|
109
103
|
|
110
|
-
@
|
104
|
+
@logger.info("Compressing #{file}")
|
105
|
+
@compressors.each { |compressor| compressor.compress(file) }
|
111
106
|
end
|
112
107
|
|
113
108
|
# @param src [String]
|
@@ -150,11 +145,15 @@ module GryphonNest
|
|
150
145
|
|
151
146
|
# @param file [Pathname]
|
152
147
|
def delete_file(file)
|
153
|
-
|
154
|
-
|
148
|
+
@logger.info("Deleting #{file}")
|
149
|
+
file.delete
|
150
|
+
|
151
|
+
@compressors.each do |compressor|
|
152
|
+
compressed_file = "#{file}#{compressor.extname}"
|
153
|
+
next unless compressed_file.exist?
|
155
154
|
|
156
|
-
@logger.info("Deleting #{
|
157
|
-
|
155
|
+
@logger.info("Deleting #{compressed_file}")
|
156
|
+
compressed_file.delete
|
158
157
|
end
|
159
158
|
end
|
160
159
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gryphon_nest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Birmingham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlbeautifier
|
@@ -120,8 +120,10 @@ files:
|
|
120
120
|
- LICENSE
|
121
121
|
- bin/nest
|
122
122
|
- lib/gryphon_nest.rb
|
123
|
+
- lib/gryphon_nest/compressors.rb
|
124
|
+
- lib/gryphon_nest/compressors/brotli_compressor.rb
|
125
|
+
- lib/gryphon_nest/compressors/gzip_compressor.rb
|
123
126
|
- lib/gryphon_nest/errors.rb
|
124
|
-
- lib/gryphon_nest/gzip_compressor.rb
|
125
127
|
- lib/gryphon_nest/layout_file.rb
|
126
128
|
- lib/gryphon_nest/logging.rb
|
127
129
|
- lib/gryphon_nest/processors.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zlib'
|
4
|
-
|
5
|
-
module GryphonNest
|
6
|
-
class GzipCompressor
|
7
|
-
# @param file [Pathname]
|
8
|
-
# @return [Boolean]
|
9
|
-
def can_compress?(file)
|
10
|
-
file.size >= 20
|
11
|
-
end
|
12
|
-
|
13
|
-
# @param file [Pathname]
|
14
|
-
def compress(file)
|
15
|
-
compressed = "#{file}.gz"
|
16
|
-
|
17
|
-
Zlib::GzipWriter.open(compressed, Zlib::BEST_COMPRESSION) do |gz|
|
18
|
-
gz.mtime = file.mtime
|
19
|
-
gz.orig_name = file.to_s
|
20
|
-
gz.write IO.binread(file)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|