hud 1.0.3 → 2.0.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 +4 -4
- data/.DS_Store +0 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +6 -0
- data/lib/.DS_Store +0 -0
- data/lib/hud/.DS_Store +0 -0
- data/lib/hud/version.rb +3 -0
- data/lib/hud.rb +154 -0
- metadata +16 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7767c2ce73d0eeb9d5e916571d5c803dc7284ac205164620f078a94d15ecf858
|
4
|
+
data.tar.gz: d403a001da10478068dc7922d159b71f502be463adaf0444509a14909350f731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59117db5b855661d38e5913ef565a6e013e61ff41fca4e03a1ea3ffbe5b09f50ca5d95638973efecbba06413ee794f7dcc00bc9f3fbc90cdb396ffd5a585e912
|
7
|
+
data.tar.gz: 42d46949e940a5bbf360459412f5455cf44c5c1965df5392202ee80f40161d5de2bbe06cf78e42a35b5cbdfac4d537b1b1d416dff0e3ff6f5ab8b2794135a2d4
|
data/.DS_Store
ADDED
Binary file
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at delaney@vidtreone.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Delaney Burke
|
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,130 @@
|
|
1
|
+
# Hud
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hud`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hud'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hud
|
22
|
+
|
23
|
+
Absolutely! Here's a README documentation for the `Hud` module and its classes and methods:
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
# Hud
|
28
|
+
|
29
|
+
The `Hud` module provides a component-based rendering system integrated with the Rack framework.
|
30
|
+
|
31
|
+
## Table of Contents
|
32
|
+
|
33
|
+
- [Dependencies](#dependencies)
|
34
|
+
- [Classes and Modules](#classes-and-modules)
|
35
|
+
- [Error](#error)
|
36
|
+
- [Display](#display)
|
37
|
+
- [Helpers](#helpers)
|
38
|
+
- [Component](#component)
|
39
|
+
|
40
|
+
---
|
41
|
+
|
42
|
+
## Dependencies
|
43
|
+
|
44
|
+
- hud/version
|
45
|
+
- hud/db/entity.rb
|
46
|
+
- rack/app
|
47
|
+
- tilt
|
48
|
+
- ostruct
|
49
|
+
- tilt/erb
|
50
|
+
- rack/app/front_end
|
51
|
+
|
52
|
+
---
|
53
|
+
|
54
|
+
## Classes and Modules
|
55
|
+
|
56
|
+
### Error
|
57
|
+
|
58
|
+
A standard error class specific to `Hud`.
|
59
|
+
|
60
|
+
### Display
|
61
|
+
|
62
|
+
This class provides methods to handle the display of components.
|
63
|
+
|
64
|
+
#### Helpers
|
65
|
+
|
66
|
+
A module that provides helper methods for the display.
|
67
|
+
|
68
|
+
##### `display(name, locals: {})`
|
69
|
+
|
70
|
+
Displays a component by its name.
|
71
|
+
|
72
|
+
*Example*:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# Assuming you have a User component defined
|
76
|
+
display(:user, locals: { name: 'Alice' })
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Component
|
80
|
+
|
81
|
+
A base class for all components. Components are meant to represent parts of the UI that can be reused across different views.
|
82
|
+
|
83
|
+
##### `self.call(locals: {})`
|
84
|
+
|
85
|
+
Creates a new instance of a component with the given locals.
|
86
|
+
|
87
|
+
*Example*:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
UserComponent.call(locals: { name: 'Bob' })
|
91
|
+
```
|
92
|
+
|
93
|
+
##### `display(name, locals = {})`
|
94
|
+
|
95
|
+
Displays a partial component by its name.
|
96
|
+
|
97
|
+
*Example*:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# Inside a component's view
|
101
|
+
<%= display(:profile_picture, locals: { url: 'path/to/pic.jpg' }) %>
|
102
|
+
```
|
103
|
+
|
104
|
+
##### `to_s`
|
105
|
+
|
106
|
+
Renders the component as a string. It looks for the component's template and renders it. If the template is not found, it prompts to create a view for the component.
|
107
|
+
|
108
|
+
*Example*:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
user_component = UserComponent.new(locals: { name: 'Charlie' })
|
112
|
+
puts user_component
|
113
|
+
```
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
## Getting Started
|
118
|
+
|
119
|
+
1. Define your components by extending `Hud::Display::Component`.
|
120
|
+
2. Create a corresponding `.html.erb` template for each component inside a `components` directory.
|
121
|
+
3. Use the `display` method to render components within other components or views.
|
122
|
+
|
123
|
+
---
|
124
|
+
|
125
|
+
Note: This README assumes that you have a basic understanding of Ruby and the Rack framework. Ensure that you set up your project structure correctly, especially the `components` directory for templates.
|
126
|
+
|
127
|
+
---
|
128
|
+
|
129
|
+
|
130
|
+
Remember to include necessary libraries like `SecureRandom`, `DateTime`, `SDBM`, and `MessagePack` in your project. Ensure that the `User` class (used in the examples) is defined with appropriate attributes for the examples to work.
|
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/hud/.DS_Store
ADDED
Binary file
|
data/lib/hud/version.rb
ADDED
data/lib/hud.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require "rack/app"
|
2
|
+
require "yaml"
|
3
|
+
require "tilt"
|
4
|
+
require "ostruct"
|
5
|
+
require "tilt/erb"
|
6
|
+
require "rack/app/front_end"
|
7
|
+
|
8
|
+
require_relative "hud/version"
|
9
|
+
|
10
|
+
|
11
|
+
module Hud
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= OpenStruct.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
configuration.components_dirs = []
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
module Middleware
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.use Middleware::Version
|
24
|
+
base.use Middleware::Environment
|
25
|
+
end
|
26
|
+
|
27
|
+
class Version
|
28
|
+
def initialize(app)
|
29
|
+
@app = app
|
30
|
+
manifest_path = File.join(File.dirname(__FILE__),'config', 'manifest.yml')
|
31
|
+
@version = YAML.load_file(manifest_path)['version']
|
32
|
+
end
|
33
|
+
|
34
|
+
def call(env)
|
35
|
+
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
|
+
|
45
|
+
[status, headers, response]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
class Environment
|
49
|
+
def initialize(app)
|
50
|
+
@app = app
|
51
|
+
end
|
52
|
+
|
53
|
+
def call(env)
|
54
|
+
status, headers, response = @app.call(env)
|
55
|
+
|
56
|
+
color = 'green'
|
57
|
+
color = 'orange' if ENV['HARBR_ENV'] == "next"
|
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='height:30px; width:100%; background-color:#{color}; position:absolute; top:0; 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
|
+
|
66
|
+
response = [response_body]
|
67
|
+
|
68
|
+
|
69
|
+
[status, headers, response]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
class Display
|
77
|
+
module Helpers
|
78
|
+
def display(name, from: nil, locals: {})
|
79
|
+
klz = Display.build(name)
|
80
|
+
klz.call(locals: locals).render_template(name: name, locals: @locals, from: from)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.build(name)
|
85
|
+
symbol = name.to_sym
|
86
|
+
class_name = symbol.to_s.capitalize
|
87
|
+
Object.const_set(class_name, Class.new(Component)) unless Object.const_defined?(class_name)
|
88
|
+
Object.const_get(class_name)
|
89
|
+
end
|
90
|
+
|
91
|
+
class Component
|
92
|
+
attr_reader :locals
|
93
|
+
attr_reader :content
|
94
|
+
alias_method :args, :locals
|
95
|
+
|
96
|
+
def folders
|
97
|
+
Hud.configuration.components_dirs
|
98
|
+
end
|
99
|
+
|
100
|
+
def development?
|
101
|
+
ENV["RACK_ENV"] == "development"
|
102
|
+
end
|
103
|
+
|
104
|
+
def production?
|
105
|
+
ENV["RACK_ENV"] == "production"
|
106
|
+
end
|
107
|
+
|
108
|
+
def staging?
|
109
|
+
ENV["RACK_ENV"] == "staging"
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.call(locals: {})
|
113
|
+
new(locals: locals)
|
114
|
+
end
|
115
|
+
|
116
|
+
def render_template(name: nil, from: nil, locals: {})
|
117
|
+
name ||= self.class.to_s.downcase.gsub("::", "_")
|
118
|
+
|
119
|
+
base_path = Pathname.new(Rack::App::Utils.pwd)
|
120
|
+
|
121
|
+
paths_to_check = []
|
122
|
+
|
123
|
+
folders.each do |folder_name|
|
124
|
+
paths_to_check << base_path.join(folder_name, "components", "#{name}.html.erb")
|
125
|
+
end
|
126
|
+
|
127
|
+
root_component_path = base_path.join("components", "#{name}.html.erb")
|
128
|
+
paths_to_check << root_component_path
|
129
|
+
|
130
|
+
paths_to_check.each do |path|
|
131
|
+
if File.exist?(path)
|
132
|
+
template = Tilt::ERBTemplate.new(path)
|
133
|
+
|
134
|
+
if from.nil?
|
135
|
+
return template.render(self, locals)
|
136
|
+
else
|
137
|
+
from_path = base_path.join(from, "components")
|
138
|
+
return template.render(self, locals) if path.to_path.start_with? from_path.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
raise "cant find #{name} in #{paths_to_check.join(",")}"
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def initialize(locals: {})
|
150
|
+
@locals = OpenStruct.new(locals)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delaney Kuldvee Burke
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -156,7 +156,19 @@ email:
|
|
156
156
|
executables: []
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
|
-
files:
|
159
|
+
files:
|
160
|
+
- ".DS_Store"
|
161
|
+
- ".rspec"
|
162
|
+
- ".ruby-version"
|
163
|
+
- ".travis.yml"
|
164
|
+
- CODE_OF_CONDUCT.md
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- lib/.DS_Store
|
169
|
+
- lib/hud.rb
|
170
|
+
- lib/hud/.DS_Store
|
171
|
+
- lib/hud/version.rb
|
160
172
|
homepage: https://github.com/dekubu/hud/
|
161
173
|
licenses:
|
162
174
|
- MIT
|