hud 2.1.0 → 2.3.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hud/version.rb +1 -1
  3. data/lib/hud.rb +52 -29
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 510809be4205ebd4d8af9a8a7f83948bf0040d41ca203a7ef38b27ab8f6f9318
4
- data.tar.gz: 79af03a89812d9d2b8c20b1a39edb44c5334e5abf7b9bfbac7ca0741e75f3641
3
+ metadata.gz: 1c81ae686bbd0cd97c469d98c2baaaab165e50859bcd8e40325b31d20baedf95
4
+ data.tar.gz: 7debdf245e083c85c681c058b73281a74fe3c9d82492606cce23bd6efd21312d
5
5
  SHA512:
6
- metadata.gz: 072c31cc873cb7506d8b6336251469a4f91da953902a08c3bfb6b2932d549850b62d792a62cb292a48dc96b277294c4312bcaee82d9b1c871153059bc51a3e6c
7
- data.tar.gz: e8f9666535a6597bd940136d89f5338bcd7b1a75c94362d74290925f78f48d785ed674d1cbea5b3443b4cdf0d53e5b46b2f02afe1a83334c6bf7ee27f4fed702
6
+ metadata.gz: 8a3d655457bc738523a5eb1fec70ccbbf2f79561a7751db775fe72953761a8c9e47b30045d658db04b723c7376ed25fb0f0448fca17404cce1f312f66777f5cb
7
+ data.tar.gz: 8e6f24a2ed10b1e9f0675beaa1e6b74885da602c3a0c3aa33f20fb9dec1b650b61c602758573578c84ea640c82fe65920950dac4e6660b00c8016ba710b75e0e
data/lib/hud/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hud
2
- VERSION = '2.1.0'
2
+ VERSION = '2.3.0'
3
3
  end
data/lib/hud.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "rack/app"
2
2
  require "yaml"
3
3
  require "tilt"
4
+ require "pry"
4
5
  require "ostruct"
5
6
  require "tilt/erb"
6
7
  require "rack/app/front_end"
@@ -15,33 +16,37 @@ module Hud
15
16
 
16
17
  def self.configure
17
18
  configuration.components_dirs = []
19
+ configuration.base_path = Pathname.new(Rack::App::Utils.pwd)
18
20
  yield(configuration)
19
21
  end
20
- module Middleware
22
+ module Middleware
21
23
 
22
24
  def self.included(base)
23
25
  base.use Middleware::Version
24
26
  #base.use Middleware::Environment
25
27
  end
26
-
28
+
27
29
  class Version
28
30
  def initialize(app)
29
31
  @app = app
30
32
  manifest_path = File.join('config', 'manifest.yml')
31
33
  @version = YAML.load_file(manifest_path)['version']
32
34
  end
33
-
35
+
34
36
  def call(env)
35
37
  status, headers, response = @app.call(env)
36
-
37
- response_body = ''
38
- response.each { |part| response_body << part }
39
- version_div = "<div style='position:fixed; bottom:0; right:0; z-index:9999; background-color:rgba(255, 255, 255, 0.7); padding:5px;'>Version: #{@version}</div>"
40
- response_body.sub!("</body>", "#{version_div}</body>")
41
- headers["Content-Length"] = response_body.bytesize.to_s
42
-
43
- response = [response_body]
44
-
38
+
39
+
40
+ if ENV['HUD_SHOW_VERSION']
41
+ response_body = ''
42
+ response.each { |part| response_body << part }
43
+ version_div = "<div style='position:fixed; bottom:0; right:0; z-index:9999; background-color:rgba(255, 255, 255, 0.7); padding:5px;'>Version: #{@version}</div>"
44
+ response_body.sub!("</body>", "#{version_div}</body>")
45
+ headers["Content-Length"] = response_body.bytesize.to_s
46
+
47
+ response = [response_body]
48
+ end
49
+
45
50
  [status, headers, response]
46
51
  end
47
52
  end
@@ -49,29 +54,32 @@ module Hud
49
54
  def initialize(app)
50
55
  @app = app
51
56
  end
52
-
57
+
53
58
  def call(env)
54
59
  status, headers, response = @app.call(env)
55
-
56
- color = 'green'
57
- color = 'orange' if ENV['HARBR_ENV'] == "next" or ENV['RACK_ENV'] == "staging"
58
- color = 'red' if ENV['HARBR_ENV'] == "live" && env["HTTP_HOST"].include?("harbr.zero2one.ee")
59
-
60
- response_body = ''
61
- response.each { |part| response_body << part }
62
- indicator_div = "<div style='position:fixed; top:0; z-index:9999; height:30px; width:100%; background-color:#{color}; z-index:9999;'>#{ENV['HARBR_ENV']&.upcase} ENVIRONMENT</div>"
63
- response_body.sub!("<body>", "<body>#{indicator_div}")
64
- headers["Content-Length"] = response_body.bytesize.to_s
65
-
60
+
61
+
62
+ if ENV['HUD_SHOW_ENVIROMENT']
63
+ color = 'green'
64
+ color = 'orange' if ENV['HUD_ENV'] == "next"
65
+ color = 'red' if ENV['HUD_ENV'] == "live"
66
+
67
+ response_body = ''
68
+ response.each { |part| response_body << part }
69
+ indicator_div = "<div style='position:fixed; top:0; z-index:9999; height:30px; width:100%; background-color:#{color}; z-index:9999;'>#{ENV['HARBR_ENV']&.upcase} ENVIRONMENT</div>"
70
+ response_body.sub!("<body>", "<body>#{indicator_div}")
71
+ headers["Content-Length"] = response_body.bytesize.to_s
72
+ end
73
+
66
74
  response = [response_body]
67
-
68
-
75
+
76
+
69
77
  [status, headers, response]
70
78
  end
71
79
  end
72
80
 
73
81
  end
74
-
82
+
75
83
 
76
84
  class Display
77
85
  module Helpers
@@ -79,6 +87,9 @@ module Hud
79
87
  klz = Display.build(name)
80
88
  klz.call(locals: locals).render_template(name: name, locals: @locals, from: from)
81
89
  end
90
+ alias_method :render, :display
91
+ alias_method :d, :display
92
+ alias_method :r, :display
82
93
  end
83
94
 
84
95
  def self.build(name)
@@ -92,6 +103,7 @@ module Hud
92
103
  attr_reader :locals
93
104
  attr_reader :content
94
105
  alias_method :args, :locals
106
+
95
107
 
96
108
  def folders
97
109
  Hud.configuration.components_dirs
@@ -101,6 +113,16 @@ module Hud
101
113
  ENV["RACK_ENV"] == "development"
102
114
  end
103
115
 
116
+
117
+ def display(name, locals: {})
118
+ template = Tilt::ERBTemplate.new("#{Hud.configuration.base_path}/components/#{name.to_s}.html.erb")
119
+ template.render(self, locals)
120
+ end
121
+
122
+ alias_method :render, :display
123
+ alias_method :d, :display
124
+ alias_method :r, :display
125
+
104
126
  def production?
105
127
  ENV["RACK_ENV"] == "production"
106
128
  end
@@ -131,6 +153,7 @@ module Hud
131
153
  if File.exist?(path)
132
154
  template = Tilt::ERBTemplate.new(path)
133
155
 
156
+ puts path
134
157
  if from.nil?
135
158
  return template.render(self, locals)
136
159
  else
@@ -154,14 +177,14 @@ module Hud
154
177
  class Screen < Rack::App
155
178
  include Hud::Middleware
156
179
  include Hud::Display::Helpers
157
-
180
+
158
181
  apply_extensions :logger
159
182
  apply_extensions :front_end
160
183
 
161
184
  helpers do
162
185
  include Hud::Display::Helpers
163
186
  end
164
-
187
+
165
188
  end
166
189
 
167
190
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler