gryphon_nest 4.0.1 → 4.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebc3be5da99292952a7e447920e092a23df21940c045b5b04e9c606ab41f1f90
4
- data.tar.gz: '08d4e67a95b76b98ca48ab20cd4926e2227fabeafd6f6f0dc05b2c91bef2e579'
3
+ metadata.gz: 0d12483d4aed715c91f61d5a9979563fca19c11816367ed746688dd574f2389a
4
+ data.tar.gz: bb86f4d32b8fc8508e76df99d7da05da883ab2c8abcb8cff6ddfd0742a513d09
5
5
  SHA512:
6
- metadata.gz: 5166f66ccab09e8cb108b308b9e79681318f595d5faf8210cf783ccc714b2f0b3533a161c92eb92f94e102b6f9954ea7519c4da285a0330951340e8c61030bbb
7
- data.tar.gz: 58566f847efb6ddbc5e782e78b12b27672fcf08f44a897b68947621620b1c01a0ccb198d79f584fd3f1c41eaf68bf371c61fc65338df73933b496010c4068118
6
+ metadata.gz: 9d0fd32f0b95d06b21957abfe480bbc1e5ad49c160e98fb929c106d94f3da646dff0033c5207fb760975676c1a650b9c87c31844a8132bb73fa0f9971c92df13
7
+ data.tar.gz: d110a25bd9513be044ac745cafd39600d096053d16e96968c2ace112cc6b7fa8ad675047eca2b30eaba34eead3da46d929d5dd6d89bd56191f34001287bd10b3
data/bin/nest CHANGED
@@ -8,6 +8,8 @@ DEFAULT_PORT = 8000
8
8
  EXIT_FAILURE = 1
9
9
 
10
10
  options = {
11
+ compress: false,
12
+ force: false,
11
13
  port: DEFAULT_PORT,
12
14
  watch: false
13
15
  }
@@ -21,7 +23,11 @@ end
21
23
 
22
24
  begin
23
25
  parser = OptionParser.new do |opts|
24
- opts.banner = 'Usage: nest [build|serve] [options]'
26
+ opts.banner = 'Usage: nest [build|serve|clean] [options]'
27
+
28
+ opts.on('-c', '--compress', 'Create gzipped compressed versions of each file')
29
+
30
+ opts.on('-f', '--force', 'Force (re)build all files')
25
31
 
26
32
  opts.on('-p', '--port [PORT]', Integer, 'Port to run dev server on')
27
33
 
@@ -42,15 +48,22 @@ begin
42
48
 
43
49
  command = ARGV.fetch(0, 'build')
44
50
 
45
- usage_error("Unknown command #{command}", parser) unless %w[build serve].include?(command)
51
+ nest = GryphonNest::Nest.new(options[:force])
52
+ nest.compressor = GryphonNest::GzipCompressor.new if options[:compress]
46
53
 
47
- nest = GryphonNest::Nest.new
48
- nest.build
54
+ case command
55
+ when 'clean'
56
+ nest.clean
57
+ when 'build'
58
+ nest.build
59
+ when 'serve'
60
+ nest.build
49
61
 
50
- if command == 'serve'
51
62
  nest.watch if options[:watch]
52
63
 
53
64
  nest.serve(options[:port])
65
+ else
66
+ usage_error("Unknown command #{command}", parser)
54
67
  end
55
68
  rescue OptionParser::ParseError => e
56
69
  usage_error(e.message, parser)
@@ -0,0 +1,24 @@
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GryphonNest
4
- VERSION = '4.0.1'
4
+ VERSION = '4.1.0'
5
5
  end
data/lib/gryphon_nest.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
3
4
  require 'listen'
4
5
  require 'pathname'
5
6
  require 'webrick'
6
7
 
7
8
  module GryphonNest
8
9
  autoload :Errors, 'gryphon_nest/errors'
10
+ autoload :GzipCompressor, 'gryphon_nest/gzip_compressor'
9
11
  autoload :Logging, 'gryphon_nest/logging'
10
12
  autoload :Processors, 'gryphon_nest/processors'
11
13
  autoload :Renderers, 'gryphon_nest/renderers'
@@ -18,9 +20,15 @@ module GryphonNest
18
20
  LAYOUT_FILE = 'layout.mustache'
19
21
 
20
22
  class Nest
21
- def initialize
23
+ # @return [GzipCompressor, nil]
24
+ attr_writer :compressor
25
+
26
+ # @param force [Boolean]
27
+ def initialize(force)
22
28
  @processors = Processors.create
23
29
  @logger = Logging.create
30
+ @force = force
31
+ @compressor = nil
24
32
  end
25
33
 
26
34
  # @raise [Errors::NotFoundError]
@@ -29,12 +37,17 @@ module GryphonNest
29
37
 
30
38
  Dir.mkdir(BUILD_DIR) unless Dir.exist?(BUILD_DIR)
31
39
 
32
- existing_files = glob("#{BUILD_DIR}/**/*")
40
+ existing_files = glob("#{BUILD_DIR}/**/*").reject { |file| file.to_s.end_with?('.gz') }
33
41
  content_files = glob("#{CONTENT_DIR}/**/*")
34
42
  processed_files = content_files.collect { |src| process_file(src) }
35
43
  existing_files.difference(processed_files).each { |file| delete_file(file) }
36
44
  end
37
45
 
46
+ def clean
47
+ FileUtils.remove_dir(BUILD_DIR, true)
48
+ @logger.info('Removed build dir')
49
+ end
50
+
38
51
  def watch
39
52
  @logger.info('Watching for content changes')
40
53
  Listen.to(CONTENT_DIR, relative: true) do |modified, added, removed|
@@ -75,15 +88,29 @@ module GryphonNest
75
88
  processor = @processors[src.extname]
76
89
  dest = processor.dest_name(src)
77
90
 
78
- if processor.file_modified?(src, dest)
91
+ if @force || processor.file_modified?(src, dest)
79
92
  msg = File.exist?(dest) ? 'Recreating' : 'Creating'
80
93
  @logger.info("#{msg} #{dest}")
81
94
  processor.process(src, dest)
95
+ compress_file(dest)
82
96
  end
83
97
 
84
98
  dest
85
99
  end
86
100
 
101
+ # @param file [Pathname]
102
+ def compress_file(file)
103
+ return unless @compressor.is_a?(GzipCompressor)
104
+
105
+ @logger.info("Compressing #{file}")
106
+ unless @compressor.can_compress?(file)
107
+ @logger.info("Skipping #{file}")
108
+ return
109
+ end
110
+
111
+ @compressor.compress(file)
112
+ end
113
+
87
114
  # @param src [Pathname]
88
115
  # @return [Pathname]
89
116
  def process_data_file(src)
@@ -104,6 +131,13 @@ module GryphonNest
104
131
  def delete_file(file)
105
132
  @logger.info("Deleting #{file}")
106
133
  file.delete
134
+
135
+ compressed = Pathname("#{file}.gz")
136
+
137
+ return unless compressed.exist?
138
+
139
+ @logger.info("Deleting #{compressed}")
140
+ compressed.delete
107
141
  end
108
142
  end
109
143
  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.0.1
4
+ version: 4.1.0
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-05-22 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlbeautifier
@@ -121,6 +121,7 @@ files:
121
121
  - bin/nest
122
122
  - lib/gryphon_nest.rb
123
123
  - lib/gryphon_nest/errors.rb
124
+ - lib/gryphon_nest/gzip_compressor.rb
124
125
  - lib/gryphon_nest/logging.rb
125
126
  - lib/gryphon_nest/processors.rb
126
127
  - lib/gryphon_nest/processors/asset_processor.rb