gryphon_nest 4.0.0 → 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: 11bbaedf3fbca0e216d16bd03a8452ee6ffc57930dac0ab8a30c3d02fef15f2e
4
- data.tar.gz: 63ed7c032ef8478697ee0372ff569c54f3408a92dc68728f892c7a938e7e4955
3
+ metadata.gz: 0d12483d4aed715c91f61d5a9979563fca19c11816367ed746688dd574f2389a
4
+ data.tar.gz: bb86f4d32b8fc8508e76df99d7da05da883ab2c8abcb8cff6ddfd0742a513d09
5
5
  SHA512:
6
- metadata.gz: 865a4ed653820f359cd8d608e38e7f1c9c1697def2f4958ea18b11e4f4df84b701663571b10bf03eb06a2a1f9cd530a0c1f7579c613b710611b7014cd93c9851
7
- data.tar.gz: 16838330ada34079d02f4ef629a878c2f6afdd55fa288e180a44e17b9fc8425fe3c6c5eaa27883ebb7ec900d30ce0ae2e82dd84525384e7dbbe464732f976fa6
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
@@ -27,7 +27,7 @@ module GryphonNest
27
27
 
28
28
  processor
29
29
  rescue LoadError
30
- @processors[key] = nil
30
+ @processors.delete(key)
31
31
  @asset_processor
32
32
  end
33
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GryphonNest
4
- VERSION = '4.0.0'
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,38 +37,38 @@ 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
- listener = Listen.to(CONTENT_DIR, DATA_DIR, relative: true) do |modified, added, removed|
53
+ Listen.to(CONTENT_DIR, relative: true) do |modified, added, removed|
41
54
  modified.union(added).each do |file|
42
55
  path = Pathname(file)
43
-
44
- if file.start_with?(DATA_DIR)
45
- process_data_file(path)
46
- else
47
- process_file(path)
48
- end
56
+ process_file(path)
49
57
  end
50
58
 
51
59
  removed.each do |file|
52
60
  path = Pathname(file)
53
-
54
- if file.start_with?(DATA_DIR)
55
- process_data_file(path)
56
- else
57
- path = @processors[path.extname].dest_name(path)
58
- delete_file(path)
59
- end
61
+ path = @processors[path.extname].dest_name(path)
62
+ delete_file(path)
60
63
  end
61
- end
64
+ end.start
62
65
 
63
- listener.start
66
+ Listen.to(DATA_DIR, relative: true) do |modified, added, removed|
67
+ modified.union(added, removed).each do |file|
68
+ path = Pathname(file)
69
+ process_data_file(path)
70
+ end
71
+ end.start
64
72
  end
65
73
 
66
74
  # @param port [Integer]
@@ -80,15 +88,29 @@ module GryphonNest
80
88
  processor = @processors[src.extname]
81
89
  dest = processor.dest_name(src)
82
90
 
83
- if processor.file_modified?(src, dest)
91
+ if @force || processor.file_modified?(src, dest)
84
92
  msg = File.exist?(dest) ? 'Recreating' : 'Creating'
85
93
  @logger.info("#{msg} #{dest}")
86
94
  processor.process(src, dest)
95
+ compress_file(dest)
87
96
  end
88
97
 
89
98
  dest
90
99
  end
91
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
+
92
114
  # @param src [Pathname]
93
115
  # @return [Pathname]
94
116
  def process_data_file(src)
@@ -109,6 +131,13 @@ module GryphonNest
109
131
  def delete_file(file)
110
132
  @logger.info("Deleting #{file}")
111
133
  file.delete
134
+
135
+ compressed = Pathname("#{file}.gz")
136
+
137
+ return unless compressed.exist?
138
+
139
+ @logger.info("Deleting #{compressed}")
140
+ compressed.delete
112
141
  end
113
142
  end
114
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.0
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-12 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