rack-http_router 0.0.35 → 0.0.36
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 +55 -23
- 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: d815663c5e328d7c57d595fa667bf3137e780388ec74e59ef1ff607120ba9c8d
|
4
|
+
data.tar.gz: fa7cbeb64c3ca10814cbabaeabebfd97cd4c90973d837e46534d50d37d0b355d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a13a2597ac73c3dc785b63cc8c0b0fa1de86a3437e3fc6f48bf2eaf56de71a1070a8a5efd630ae34f867196bb91176a30cc7c84d87c7ea4363e41d27122c489
|
7
|
+
data.tar.gz: b614c1cf570854cffdf80f99b2bd2a2f1da1e1fc34b56e51d7043e6011f9183a83bc36391a12f57a7bf249839576de08e1a4dd7d209b2be3cdb06ef1b7d5d1b6
|
@@ -44,6 +44,10 @@ module Rack
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def layout(layout_path, file_path)
|
48
|
+
Rack::HttpRouter::Action.layout(layout_path, file_path)
|
49
|
+
end
|
50
|
+
|
47
51
|
def assign(obj, hash)
|
48
52
|
Rack::HttpRouter::Action.assign(obj, hash)
|
49
53
|
end
|
@@ -89,22 +93,6 @@ module Rack
|
|
89
93
|
end
|
90
94
|
|
91
95
|
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
96
|
def view_response(
|
109
97
|
paths,
|
110
98
|
view_params = {},
|
@@ -133,11 +121,31 @@ module Rack
|
|
133
121
|
db: nil,
|
134
122
|
response_instance: false
|
135
123
|
)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
124
|
+
base_path = config.dig(:views, :path) || "views"
|
125
|
+
|
126
|
+
file_or_nil = lambda do |path|
|
127
|
+
::File.read(path)
|
128
|
+
rescue Errno::ENOENT
|
129
|
+
nil
|
130
|
+
end
|
131
|
+
|
132
|
+
file_content = if paths.is_a?(Array)
|
133
|
+
paths.map { |path| ::File.read("#{base_path}/#{path}.html.erb") }.join
|
134
|
+
else
|
135
|
+
::File.read("#{base_path}/#{paths}.html.erb")
|
136
|
+
end
|
137
|
+
|
138
|
+
erb = erb(
|
139
|
+
[
|
140
|
+
file_or_nil.call("#{base_path}/layout/_header.html.erb"),
|
141
|
+
file_content,
|
142
|
+
file_or_nil.call("#{base_path}/layout/_footer.html.erb")
|
143
|
+
].join,
|
144
|
+
config,
|
145
|
+
route,
|
146
|
+
db,
|
147
|
+
view_params
|
148
|
+
)
|
141
149
|
|
142
150
|
if response_instance
|
143
151
|
return Rack::Response.new(
|
@@ -150,6 +158,30 @@ module Rack
|
|
150
158
|
[status, { 'Content-Type' => 'text/html' }, [erb]]
|
151
159
|
end
|
152
160
|
|
161
|
+
def layout(layout_path, file_path)
|
162
|
+
[
|
163
|
+
"layout/#{layout_path}/_header",
|
164
|
+
file_path,
|
165
|
+
"layout/#{layout_path}/_footer"
|
166
|
+
]
|
167
|
+
end
|
168
|
+
|
169
|
+
def assign(obj, hash)
|
170
|
+
hash.each do |k, v|
|
171
|
+
obj.define_singleton_method(k) { v }
|
172
|
+
end
|
173
|
+
|
174
|
+
obj
|
175
|
+
end
|
176
|
+
|
177
|
+
def html(content, status: 200)
|
178
|
+
[status, { 'Content-Type' => 'text/html' }, [content]]
|
179
|
+
end
|
180
|
+
|
181
|
+
def html_response(content, status: 200)
|
182
|
+
Rack::Response.new(content, status, { 'Content-Type' => 'text/html' })
|
183
|
+
end
|
184
|
+
|
153
185
|
def json(content = {}, status: 200)
|
154
186
|
[status, { 'Content-Type' => 'application/json' }, [Oj.dump(content, mode: :compat)]]
|
155
187
|
end
|
@@ -175,10 +207,10 @@ module Rack
|
|
175
207
|
end
|
176
208
|
|
177
209
|
# rubocop:disable Lint/UnusedMethodArgument
|
178
|
-
def erb(
|
210
|
+
def erb(content, config, route, db, view_params = {})
|
179
211
|
@view = OpenStruct.new(view_params)
|
180
212
|
|
181
|
-
eval(Erubi::Engine.new(
|
213
|
+
eval(Erubi::Engine.new(content).src)
|
182
214
|
end
|
183
215
|
# rubocop:enable Lint/UnusedMethodArgument
|
184
216
|
|
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.36
|
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-07-
|
11
|
+
date: 2023-07-30 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: []
|