lively 0.19.0 → 0.21.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
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +8 -18
- data/lib/lively/application.rb +38 -14
- data/lib/lively/page.rb +10 -2
- data/lib/lively/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8430df315a92af764a65128e479adf71cd0971e27edfc259ba9ec5c7bbc21cbc
|
|
4
|
+
data.tar.gz: c48c124558fd175a016cd60a38e5f9773821d0c9fe260ed5a60218ee21e4f08d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 529d3090d929d951da18f7f58df1cb6df958f1489b54bdcbf370003b24a103dcee9ec72071be2b50c0ca327c66486cb44ed3954064cd38180774166c50e319b8
|
|
7
|
+
data.tar.gz: 23a4576c7fd367afbe32c761f6e039c74b5bef211d35f1be48690a30c68c2546d4c2530101fbe7798a526b497b864ec98e52d6b6cea29bb30fa3c6bcbb433b43
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/context/getting-started.md
CHANGED
|
@@ -117,33 +117,23 @@ class Application < Lively::Application
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def configure_routes(router)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
router.get("/") do
|
|
123
|
-
render(DisplayView.new(**state))
|
|
120
|
+
router.get("/") do |request|
|
|
121
|
+
render_view(request, DisplayView)
|
|
124
122
|
end
|
|
125
123
|
|
|
126
|
-
router.get("/control") do |
|
|
127
|
-
|
|
124
|
+
router.get("/control") do |request, parameters|
|
|
125
|
+
render_view(request, ControlView, mode: parameters["mode"])
|
|
128
126
|
end
|
|
129
127
|
end
|
|
130
|
-
|
|
131
|
-
# Unmatched routes are passed here:
|
|
132
|
-
def handle(request)
|
|
133
|
-
delegate.call(request)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
private
|
|
137
|
-
|
|
138
|
-
def render(body)
|
|
139
|
-
page = Lively::Pages::Index.new(title: "My App", body: body)
|
|
140
|
-
Protocol::HTTP::Response[200, [], [page.call]]
|
|
141
|
-
end
|
|
142
128
|
end
|
|
143
129
|
```
|
|
144
130
|
|
|
131
|
+
`allowed_views` defines the view classes the live resolver may construct. Routes select which view to display at each path, including `/`. `make_view` constructs a view with shared state, `make_page` wraps it in the default page, and `render_view` composes both operations. A custom route can construct any {ruby Lively::Page} around `make_view` and call it with the request. Lively installs its `/live` WebSocket route independently, so overriding `configure_routes` does not remove it.
|
|
132
|
+
|
|
145
133
|
Routes match exact paths and may accept one or more HTTP methods. Query parameters are decoded using `protocol-url` and passed to the handler as its second argument. Routes without an explicit method accept every method.
|
|
146
134
|
|
|
135
|
+
Requests which do not match a route are passed to the application's delegate. An application using client-side history routing can instead override `#handle` to render an application page for unmatched paths.
|
|
136
|
+
|
|
147
137
|
## Live Reloading
|
|
148
138
|
|
|
149
139
|
To enable live reloading, add the `io-watch` gem to your `gems.rb` file:
|
data/lib/lively/application.rb
CHANGED
|
@@ -31,7 +31,7 @@ module Lively
|
|
|
31
31
|
# Create a new application class configured for a specific Live view tag,
|
|
32
32
|
# optionally with shared state that is passed to all views.
|
|
33
33
|
#
|
|
34
|
-
# @parameter tag [Class] The Live view class to
|
|
34
|
+
# @parameter tag [Class] The Live view class to render at the root route.
|
|
35
35
|
# @parameter state [Hash] Shared state to pass to all views as keyword arguments.
|
|
36
36
|
# @returns [Class] A new application class configured for the specified tag.
|
|
37
37
|
def self.[](*tags, **state)
|
|
@@ -87,31 +87,44 @@ module Lively
|
|
|
87
87
|
self.class.name
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
#
|
|
90
|
+
# Construct a view with shared application state.
|
|
91
|
+
# @parameter view_class [Class] The view class to construct.
|
|
92
|
+
# @parameter arguments [Hash] Additional keyword arguments for the view.
|
|
91
93
|
# @returns [Live::View] A new view instance.
|
|
92
|
-
def
|
|
93
|
-
|
|
94
|
+
def make_view(view_class, **arguments)
|
|
95
|
+
view_class.new(**self.state, **arguments)
|
|
94
96
|
end
|
|
95
97
|
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
# Construct the default page for a view.
|
|
99
|
+
# Override this to customize the document surrounding live views.
|
|
100
|
+
# @parameter view [Live::View] The root view for the page.
|
|
101
|
+
# @returns [Page] A new page instance.
|
|
102
|
+
def make_page(view)
|
|
103
|
+
Pages::Index.new(title: self.title, body: view)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Construct a view and its default page, then render an HTTP response.
|
|
107
|
+
# @parameter request [Protocol::HTTP::Request] The incoming request.
|
|
108
|
+
# @parameter view_class [Class] The view class to render.
|
|
109
|
+
# @parameter arguments [Hash] Additional keyword arguments for the view.
|
|
110
|
+
# @returns [Protocol::HTTP::Response] A successful HTML response.
|
|
111
|
+
def render_view(request, view_class, **arguments)
|
|
112
|
+
make_page(make_view(view_class, **arguments)).call(request)
|
|
100
113
|
end
|
|
101
114
|
|
|
102
115
|
# Handle a standard HTTP request which did not match a configured route.
|
|
103
116
|
# @parameter request [Protocol::HTTP::Request] The incoming HTTP request.
|
|
104
|
-
# @returns [Protocol::HTTP::Response] The
|
|
117
|
+
# @returns [Protocol::HTTP::Response] The delegate response.
|
|
105
118
|
def handle(request)
|
|
106
|
-
return
|
|
119
|
+
return delegate.call(request)
|
|
107
120
|
end
|
|
108
121
|
|
|
109
|
-
# Add
|
|
110
|
-
# Override this method
|
|
122
|
+
# Add application routes to the given router.
|
|
123
|
+
# Override this method to map paths to views or other handlers.
|
|
111
124
|
# @parameter router [Router] The router to configure.
|
|
112
125
|
def configure_routes(router)
|
|
113
|
-
router.
|
|
114
|
-
|
|
126
|
+
router.get("/") do |request|
|
|
127
|
+
self.render_view(request, self.allowed_views.first)
|
|
115
128
|
end
|
|
116
129
|
end
|
|
117
130
|
|
|
@@ -120,6 +133,7 @@ module Lively
|
|
|
120
133
|
# @returns [Router] The configured router.
|
|
121
134
|
def router
|
|
122
135
|
@router ||= Router.new.tap do |router|
|
|
136
|
+
configure_system_routes(router)
|
|
123
137
|
configure_routes(router)
|
|
124
138
|
end
|
|
125
139
|
end
|
|
@@ -130,5 +144,15 @@ module Lively
|
|
|
130
144
|
def call(request)
|
|
131
145
|
return router.call(request) || handle(request)
|
|
132
146
|
end
|
|
147
|
+
|
|
148
|
+
private
|
|
149
|
+
|
|
150
|
+
# Add framework-owned routes to the given router.
|
|
151
|
+
# @parameter router [Router] The router to configure.
|
|
152
|
+
def configure_system_routes(router)
|
|
153
|
+
router.route("/live") do |request|
|
|
154
|
+
Async::WebSocket::Adapters::HTTP.open(request, &self.method(:live)) || Protocol::HTTP::Response[400]
|
|
155
|
+
end
|
|
156
|
+
end
|
|
133
157
|
end
|
|
134
158
|
end
|
data/lib/lively/page.rb
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# Copyright, 2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require "json"
|
|
7
|
+
require "protocol/http/response"
|
|
7
8
|
require "xrb/markup"
|
|
8
9
|
require "xrb/tag"
|
|
9
10
|
require "xrb/template"
|
|
@@ -94,10 +95,17 @@ module Lively
|
|
|
94
95
|
XRB::MarkupString.raw(json)
|
|
95
96
|
end
|
|
96
97
|
|
|
97
|
-
# Render this page to
|
|
98
|
+
# Render this page to an HTML string.
|
|
98
99
|
# @returns [String]
|
|
99
|
-
def
|
|
100
|
+
def to_html
|
|
100
101
|
@template.to_string(self)
|
|
101
102
|
end
|
|
103
|
+
|
|
104
|
+
# Render this page as an HTTP response.
|
|
105
|
+
# @parameter request [Protocol::HTTP::Request] The incoming request.
|
|
106
|
+
# @returns [Protocol::HTTP::Response] A successful HTML response.
|
|
107
|
+
def call(request)
|
|
108
|
+
Protocol::HTTP::Response[200, {"content-type" => "text/html; charset=utf-8"}, [to_html]]
|
|
109
|
+
end
|
|
102
110
|
end
|
|
103
111
|
end
|
data/lib/lively/version.rb
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|