rack-http_router 0.0.35 → 0.0.37
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/lib/rack-http_router/action.rb +45 -25
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8116a8bf789a572ba51ac9b1644a88bcf7cffdd5d47533afccea57040d48556
|
4
|
+
data.tar.gz: 2c8f9d461996645b791e8087921d03d577576f56778669e8851c2cf2c3de9a70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 932d5f2c0b87140b7b0f6f9fb8bdf897af1335fd950af076204449153312013cbd0d866331b3a36dd4dde5563c57ebcbd99c4d213e7fd2f7100ab8729eebc7db
|
7
|
+
data.tar.gz: 460cf2a15bfb6e3f2837f59470127a77c15cd83abb0df2c264bd9c1c70db13b733351e5534d689dbcbad3285053c1ab2bcd7e5d5159a98b14480ebd352b9a034
|
@@ -44,8 +44,8 @@ module Rack
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
Rack::HttpRouter::Action.
|
47
|
+
def layout(layout_path, file_path)
|
48
|
+
Rack::HttpRouter::Action.layout(layout_path, file_path)
|
49
49
|
end
|
50
50
|
|
51
51
|
def html(content, status: 200)
|
@@ -89,22 +89,6 @@ module Rack
|
|
89
89
|
end
|
90
90
|
|
91
91
|
class << self
|
92
|
-
def assign(obj, hash)
|
93
|
-
hash.each do |k, v|
|
94
|
-
obj.define_singleton_method(k) { v }
|
95
|
-
end
|
96
|
-
|
97
|
-
obj
|
98
|
-
end
|
99
|
-
|
100
|
-
def html(content, status: 200)
|
101
|
-
[status, { 'Content-Type' => 'text/html' }, [content]]
|
102
|
-
end
|
103
|
-
|
104
|
-
def html_response(content, status: 200)
|
105
|
-
Rack::Response.new(content, status, { 'Content-Type' => 'text/html' })
|
106
|
-
end
|
107
|
-
|
108
92
|
def view_response(
|
109
93
|
paths,
|
110
94
|
view_params = {},
|
@@ -133,11 +117,31 @@ module Rack
|
|
133
117
|
db: nil,
|
134
118
|
response_instance: false
|
135
119
|
)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
120
|
+
base_path = config.dig(:views, :path) || "views"
|
121
|
+
|
122
|
+
file_or_nil = lambda do |path|
|
123
|
+
::File.read(path)
|
124
|
+
rescue Errno::ENOENT
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
|
128
|
+
file_content = if paths.is_a?(Array)
|
129
|
+
paths.map { |path| ::File.read("#{base_path}/#{path}.html.erb") }.join
|
130
|
+
else
|
131
|
+
::File.read("#{base_path}/#{paths}.html.erb")
|
132
|
+
end
|
133
|
+
|
134
|
+
erb = erb(
|
135
|
+
[
|
136
|
+
file_or_nil.call("#{base_path}/layout/_header.html.erb"),
|
137
|
+
file_content,
|
138
|
+
file_or_nil.call("#{base_path}/layout/_footer.html.erb")
|
139
|
+
].join,
|
140
|
+
config,
|
141
|
+
route,
|
142
|
+
db,
|
143
|
+
view_params
|
144
|
+
)
|
141
145
|
|
142
146
|
if response_instance
|
143
147
|
return Rack::Response.new(
|
@@ -150,6 +154,22 @@ module Rack
|
|
150
154
|
[status, { 'Content-Type' => 'text/html' }, [erb]]
|
151
155
|
end
|
152
156
|
|
157
|
+
def layout(layout_path, file_path)
|
158
|
+
[
|
159
|
+
"layout/#{layout_path}/_header",
|
160
|
+
file_path,
|
161
|
+
"layout/#{layout_path}/_footer"
|
162
|
+
]
|
163
|
+
end
|
164
|
+
|
165
|
+
def html(content, status: 200)
|
166
|
+
[status, { 'Content-Type' => 'text/html' }, [content]]
|
167
|
+
end
|
168
|
+
|
169
|
+
def html_response(content, status: 200)
|
170
|
+
Rack::Response.new(content, status, { 'Content-Type' => 'text/html' })
|
171
|
+
end
|
172
|
+
|
153
173
|
def json(content = {}, status: 200)
|
154
174
|
[status, { 'Content-Type' => 'application/json' }, [Oj.dump(content, mode: :compat)]]
|
155
175
|
end
|
@@ -175,10 +195,10 @@ module Rack
|
|
175
195
|
end
|
176
196
|
|
177
197
|
# rubocop:disable Lint/UnusedMethodArgument
|
178
|
-
def erb(
|
198
|
+
def erb(content, config, route, db, view_params = {})
|
179
199
|
@view = OpenStruct.new(view_params)
|
180
200
|
|
181
|
-
eval(Erubi::Engine.new(
|
201
|
+
eval(Erubi::Engine.new(content).src)
|
182
202
|
end
|
183
203
|
# rubocop:enable Lint/UnusedMethodArgument
|
184
204
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-http_router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique F. Teixeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '4.0'
|
61
|
-
description: A complete http router solution that fit well with pure rack apps
|
61
|
+
description: A complete http router solution that fit well with pure rack apps.
|
62
62
|
email: hriqueft@gmail.com
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
@@ -91,6 +91,5 @@ requirements: []
|
|
91
91
|
rubygems_version: 3.4.3
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
|
-
summary:
|
95
|
-
Rack projects.'
|
94
|
+
summary: A complete http router solution that fit well with pure rack apps.
|
96
95
|
test_files: []
|