lownode 0.5.16 → 0.5.17
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/lownode.rb +5 -0
- data/lib/templates/renderer.rb +12 -4
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ebedc5ce0d14fe37bf8da82b53667396090f5420f3c67fea6c97f1dd4b81574
|
|
4
|
+
data.tar.gz: a293bc4836581a5aa4804a0fa409e02ba20243ab880aeccc076923ef24e056ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be5574331e3c4225179bc6712651dbbc9b5f6386eff4daa1b67c7d394419715f98b5cf41d4109ae72e2653b67859caadaeb4ecb20934527f25adb806fd27ae34
|
|
7
|
+
data.tar.gz: 21f955a2a0bb6f91c02cf82e9cb0fc96c9d728bc7aca7f1d133bb2e36b8bbbca62640a018ae9775fcbe7aaa50de9b342029dab91458110371ff57a429dfd7d66
|
data/lib/lownode.rb
CHANGED
|
@@ -27,6 +27,11 @@ class LowNode
|
|
|
27
27
|
@response_headers ||= Protocol::HTTP::Headers.new
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# The headers the node added, or nil when it added none, so a response without any doesn't make them.
|
|
31
|
+
def added_headers
|
|
32
|
+
@response_headers
|
|
33
|
+
end
|
|
34
|
+
|
|
30
35
|
# Adds a header to this node's response, like add_header('cache-control', 'public, max-age=3600'), for an action that
|
|
31
36
|
# returns its body, like a string, a hash or an array.
|
|
32
37
|
def add_header(name, value)
|
data/lib/templates/renderer.rb
CHANGED
|
@@ -25,9 +25,9 @@ module Low
|
|
|
25
25
|
mod.module_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
26
26
|
def #{action}(**kwargs)
|
|
27
27
|
node, body = action_body(:#{action}, kwargs)
|
|
28
|
-
return if body.nil? || body
|
|
28
|
+
return if body.nil? || (body.is_a?(String) && body.empty?)
|
|
29
29
|
|
|
30
|
-
response_event(body:, event: kwargs[:event], headers: node&.
|
|
30
|
+
response_event(body:, event: kwargs[:event], headers: node&.added_headers)
|
|
31
31
|
end
|
|
32
32
|
RUBY
|
|
33
33
|
end
|
|
@@ -113,9 +113,12 @@ module Low
|
|
|
113
113
|
# The keywords the method takes, like Antlers::Keywords.accepted, but with its params read once for each method,
|
|
114
114
|
# as reading them makes new objects every time. A method that's defined again, like when a file reloads, is a
|
|
115
115
|
# different method, so its params are read again.
|
|
116
|
+
# When the method takes every keyword given, like a node's initialize(event:), they're passed as they are.
|
|
116
117
|
def accepted_keywords(method, kwargs)
|
|
117
118
|
names = Renderer.keyword_names[method] ||= keyword_names(method.parameters)
|
|
118
|
-
names == :all
|
|
119
|
+
return kwargs if names == :all || kwargs.all? { |key, _| names.include?(key) }
|
|
120
|
+
|
|
121
|
+
kwargs.slice(*names)
|
|
119
122
|
end
|
|
120
123
|
|
|
121
124
|
def keyword_names(parameters)
|
|
@@ -138,13 +141,18 @@ module Low
|
|
|
138
141
|
|
|
139
142
|
# What a template or action rendered, as HTML unless the node added its own content type, like text/plain.
|
|
140
143
|
def html_response_event(html:, event:, headers:)
|
|
141
|
-
headers.add('content-type', 'text/html') unless
|
|
144
|
+
headers.add('content-type', 'text/html') unless content_type?(headers)
|
|
142
145
|
# A rendered page is a new string, so strip it in place rather than copying it. A frozen string is copied.
|
|
143
146
|
html = html.frozen? ? html.strip : html.tap(&:strip!)
|
|
144
147
|
response = Protocol::HTTP::Response.new('HTTP/1.1', response_status(event), headers, Protocol::HTTP::Body::Buffered.wrap(html))
|
|
145
148
|
Low::Events::ResponseEvent.new(response:).tap(&:branch)
|
|
146
149
|
end
|
|
147
150
|
|
|
151
|
+
# Whether the node set a content type. Its headers are looked through as a list, as include? indexes them all.
|
|
152
|
+
def content_type?(headers)
|
|
153
|
+
headers.fields.any? { |name, _| (name = name.to_s).length == 12 && name.casecmp('content-type') == 0 } # rubocop:disable Style/NumericPredicate
|
|
154
|
+
end
|
|
155
|
+
|
|
148
156
|
# A response an action made itself, with the headers the node set, like its cookies, added to its own.
|
|
149
157
|
def protocol_response_event(response:, headers:)
|
|
150
158
|
headers.each { |name, value| response.headers.add(name, value) }
|
data/lib/version.rb
CHANGED