rack-http_router 0.0.34 → 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 +59 -15
- 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,14 @@ 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
|
+
|
51
|
+
def assign(obj, hash)
|
52
|
+
Rack::HttpRouter::Action.assign(obj, hash)
|
53
|
+
end
|
54
|
+
|
47
55
|
def html(content, status: 200)
|
48
56
|
Rack::HttpRouter::Action.html(content, status: status)
|
49
57
|
end
|
@@ -85,14 +93,6 @@ module Rack
|
|
85
93
|
end
|
86
94
|
|
87
95
|
class << self
|
88
|
-
def html(content, status: 200)
|
89
|
-
[status, { 'Content-Type' => 'text/html' }, [content]]
|
90
|
-
end
|
91
|
-
|
92
|
-
def html_response(content, status: 200)
|
93
|
-
Rack::Response.new(content, status, { 'Content-Type' => 'text/html' })
|
94
|
-
end
|
95
|
-
|
96
96
|
def view_response(
|
97
97
|
paths,
|
98
98
|
view_params = {},
|
@@ -121,11 +121,31 @@ module Rack
|
|
121
121
|
db: nil,
|
122
122
|
response_instance: false
|
123
123
|
)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
+
)
|
129
149
|
|
130
150
|
if response_instance
|
131
151
|
return Rack::Response.new(
|
@@ -138,6 +158,30 @@ module Rack
|
|
138
158
|
[status, { 'Content-Type' => 'text/html' }, [erb]]
|
139
159
|
end
|
140
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
|
+
|
141
185
|
def json(content = {}, status: 200)
|
142
186
|
[status, { 'Content-Type' => 'application/json' }, [Oj.dump(content, mode: :compat)]]
|
143
187
|
end
|
@@ -163,10 +207,10 @@ module Rack
|
|
163
207
|
end
|
164
208
|
|
165
209
|
# rubocop:disable Lint/UnusedMethodArgument
|
166
|
-
def erb(
|
210
|
+
def erb(content, config, route, db, view_params = {})
|
167
211
|
@view = OpenStruct.new(view_params)
|
168
212
|
|
169
|
-
eval(Erubi::Engine.new(
|
213
|
+
eval(Erubi::Engine.new(content).src)
|
170
214
|
end
|
171
215
|
# rubocop:enable Lint/UnusedMethodArgument
|
172
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: []
|