roda-phlex 0.1.0 → 0.2.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
- data/.markdownlint.yml +10 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +58 -1
- data/README.md +25 -17
- data/lib/roda/phlex.rb +1 -1
- data/lib/roda/plugins/phlex.rb +33 -17
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4325bf47a07f07abf3c30722c16bcd2422559e3ae8ef3af32803efe081d640c
|
|
4
|
+
data.tar.gz: fe31c12b510c61204b61996b6f22a696a8e82ba1f6a491ffe399c71e30bae365
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3174f3c8d94c44d3876a51fe5f5d531f3feee7e5143d0b98a43e6978537f1b4e070c260f73421fb5bd04e9d8619e83067ab34eef073c7f91836d3c9a2e94df32
|
|
7
|
+
data.tar.gz: c6eb86db087726ee22f7cf2d0df7c140c34433606279675bd56c26158b361c9b0b34f8369eb9a390c04193b5b5c8e17e6591bb599553a1ffef06499be901baf3
|
data/.markdownlint.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
6
|
+
|
|
1
7
|
## [Unreleased]
|
|
2
8
|
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
### Deprecated
|
|
14
|
+
|
|
15
|
+
### Removed
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
### Security
|
|
20
|
+
|
|
21
|
+
## [0.2.0] - 2024-12-13
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- Allow `phlex_layout(false)` to be used to reset disable layout.
|
|
26
|
+
- Allow `phlex_layout_handler(:default)` to be used to reset to the default layout handler.
|
|
27
|
+
|
|
28
|
+
### Removed
|
|
29
|
+
|
|
30
|
+
- Don't delete layout options when deleting layout (eg via `phlex_layout(false)`)
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- `phlex_layout` should accept a `Phlex::SGML` class, not instance.
|
|
35
|
+
- `phlex_layout_handler` called with `nil` resets it to the default handler.
|
|
36
|
+
|
|
3
37
|
## [0.1.0] - 2024-08-28
|
|
4
38
|
|
|
5
|
-
- Initial release based on <https://github.com/benpickles/phlex-sinatra/commit/2e3c9a612cbf6f4b4bf5db880f164b66f008baf8>
|
|
39
|
+
- Initial release based on <https://github.com/benpickles/phlex-sinatra/commit/2e3c9a612cbf6f4b4bf5db880f164b66f008baf8>
|
|
40
|
+
and <https://gist.github.com/RomanTurner/0ce0b8792e4149d152d2af2224cb6407>
|
|
41
|
+
|
|
42
|
+
________________________________________________________________________________
|
|
43
|
+
|
|
44
|
+
[Unreleased]: https://github.com/fnordfish/roda-phlex/compare/v0.2.0...main
|
|
45
|
+
[0.2.0]: https://github.com/fnordfish/roda-phlex/releases/tag/v0.2.0
|
|
46
|
+
[0.1.0]: https://github.com/fnordfish/roda-phlex/releases/tag/v0.1.0
|
|
47
|
+
|
|
48
|
+
<!-- template for new release:
|
|
49
|
+
### Added
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
### Deprecated
|
|
54
|
+
|
|
55
|
+
### Removed
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
### Security
|
|
60
|
+
|
|
61
|
+
## [X.Y.Z] - YYYY-MM-DD
|
|
62
|
+
-->
|
data/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# roda-phlex
|
|
2
2
|
|
|
3
|
-
A [Roda](https://github.com/jeremyevans/roda) plugin that adds some convenience rendering
|
|
3
|
+
A [Roda](https://github.com/jeremyevans/roda) plugin that adds some convenience rendering
|
|
4
|
+
[Phlex](https://github.com/phlex-ruby/phlex) views.
|
|
4
5
|
Especially accessing application methods from the view.
|
|
5
6
|
|
|
7
|
+
* API documentation is available at [https://www.rubydoc.info/gems/roda-phlex](https://www.rubydoc.info/gems/roda-phlex/Roda/RodaPlugins/Phlex/InstanceMethods)
|
|
8
|
+
|
|
6
9
|
## Installation
|
|
7
10
|
|
|
8
11
|
Install the gem and add to the application's Gemfile by executing:
|
|
@@ -21,23 +24,23 @@ gem install roda-phlex
|
|
|
21
24
|
|
|
22
25
|
`plugin :phlex` takes the following options:
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
* `:layout` (`Phlex::SGML`): Specifies the layout class to be used for rendering
|
|
25
28
|
views. This class should be a Phlex layout class that defines how the
|
|
26
29
|
views are structured and rendered.
|
|
27
|
-
|
|
30
|
+
* `:layout_opts` (`Object`): Options that are passed to the layout
|
|
28
31
|
class when it is instantiated. These options can be used to customize
|
|
29
32
|
the behavior of the layout. Usually, this is a `Hash`.
|
|
30
|
-
|
|
33
|
+
* `:layout_handler` (`#call`): A custom handler for creating layout
|
|
31
34
|
instances. This proc receives three arguments: the layout class, the
|
|
32
|
-
layout options, and the object to be rendered. By default, it
|
|
35
|
+
layout options, and the object to be rendered. By default, it runs
|
|
33
36
|
`layout.new(obj, **layout_opts)`, which instantiates the layout class with the
|
|
34
37
|
provided view object and options as keyword arguments.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* `:delegate`: Define if or which methods should be delegated to the Roda app:
|
|
39
|
+
+ `true` (default): Create a single `app` method that delegates to the Roda app.
|
|
40
|
+
+ `false`: Do not create any delegate methods.
|
|
41
|
+
+ `:all`: Delegate all methods the Roda app responds to, to it. Be careful with this option.
|
|
42
|
+
It can lead to unexpected behavior if the Roda app has methods that conflict with Phlex methods.
|
|
43
|
+
+ `Symbol`, `String`, `Array<Symbol,String>`: Delegate only the specified methods to the Roda app.
|
|
41
44
|
|
|
42
45
|
## Usage
|
|
43
46
|
|
|
@@ -86,7 +89,8 @@ end
|
|
|
86
89
|
|
|
87
90
|
## Streaming
|
|
88
91
|
|
|
89
|
-
Streaming a Phlex view can be enabled by passing `stream: true` which will cause Phlex to automatically write
|
|
92
|
+
Streaming a Phlex view can be enabled by passing `stream: true` which will cause Phlex to automatically write
|
|
93
|
+
to the response after the closing `</head>` and buffer the remaining content.
|
|
90
94
|
The Roda `:stream` plugin must be enabled for this to work.
|
|
91
95
|
|
|
92
96
|
```ruby
|
|
@@ -101,7 +105,7 @@ You can also manually flush the contents of the buffer at any point using Phlex'
|
|
|
101
105
|
|
|
102
106
|
```ruby
|
|
103
107
|
class Layout < Phlex::HTML
|
|
104
|
-
def
|
|
108
|
+
def view_template(&block)
|
|
105
109
|
doctype
|
|
106
110
|
html {
|
|
107
111
|
head {
|
|
@@ -120,7 +124,7 @@ class Layout < Phlex::HTML
|
|
|
120
124
|
end
|
|
121
125
|
|
|
122
126
|
class MyView < Phlex::HTML
|
|
123
|
-
def
|
|
127
|
+
def view_template
|
|
124
128
|
render Layout.new {
|
|
125
129
|
# Knowing that this page can take a while to generate we can choose to
|
|
126
130
|
# flush here so the browser can render the site header while downloading
|
|
@@ -156,7 +160,9 @@ end
|
|
|
156
160
|
|
|
157
161
|
## Contributing
|
|
158
162
|
|
|
159
|
-
Bug reports and pull requests are welcome on GitHub at <https://github.com/fnordfish/roda-phlex>.
|
|
163
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/fnordfish/roda-phlex>.
|
|
164
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected
|
|
165
|
+
to adhere to the [code of conduct](https://github.com/fnordfish/roda-phlex/blob/main/CODE_OF_CONDUCT.md).
|
|
160
166
|
|
|
161
167
|
## License
|
|
162
168
|
|
|
@@ -164,8 +170,10 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
164
170
|
|
|
165
171
|
## Code of Conduct
|
|
166
172
|
|
|
167
|
-
Everyone interacting in the Roda::Phlex project's codebases, issue trackers, chat rooms and mailing lists is expected
|
|
173
|
+
Everyone interacting in the Roda::Phlex project's codebases, issue trackers, chat rooms and mailing lists is expected
|
|
174
|
+
to follow the [code of conduct](https://github.com/fnordfish/roda-phlex/blob/main/CODE_OF_CONDUCT.md).
|
|
168
175
|
|
|
169
176
|
## Acknowledgements
|
|
170
177
|
|
|
171
|
-
This gem is based on [phlex-sinatra](https://github.com/benpickles/phlex-sinatra), and extended by the layout handling
|
|
178
|
+
This gem is based on [phlex-sinatra](https://github.com/benpickles/phlex-sinatra), and extended by the layout handling
|
|
179
|
+
features in [RomanTurner's gist](https://gist.github.com/RomanTurner/0ce0b8792e4149d152d2af2224cb6407)
|
data/lib/roda/phlex.rb
CHANGED
data/lib/roda/plugins/phlex.rb
CHANGED
|
@@ -18,11 +18,11 @@ class Roda
|
|
|
18
18
|
# `DEFAULT_LAYOUT_HANDLER`, which instantiates the layout class with the
|
|
19
19
|
# provided object and options as keyword arguments.
|
|
20
20
|
# - `:delegate`: Define if or which methods should be delegated to the Roda app:
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
21
|
+
# + `true` (default): Create a single `app` method that delegates to the Roda app.
|
|
22
|
+
# + `false`: Do not create any delegate methods.
|
|
23
|
+
# + `:all`: Delegate all methods the Roda app responds to, to it. Be careful with this option.
|
|
24
|
+
# It can lead to unexpected behavior if the Roda app has methods that conflict with Phlex methods.
|
|
25
|
+
# + `Symbol`, `String`, `Array<Symbol,String>`: Delegate only the named methods to the Roda app.
|
|
26
26
|
module Phlex
|
|
27
27
|
Undefined = Object.new
|
|
28
28
|
private_constant :Undefined
|
|
@@ -44,6 +44,11 @@ class Roda
|
|
|
44
44
|
|
|
45
45
|
# The default layout handler for creating layout instances.
|
|
46
46
|
# Expects layout options to be a +Hash+ when provided.
|
|
47
|
+
# Layout options are passed as keyword arguments to the layout class.
|
|
48
|
+
#
|
|
49
|
+
# @param layout [Class] The layout class to be instantiated.
|
|
50
|
+
# @param layout_opts [Hash, nil] The layout options to be passed to the layout class.
|
|
51
|
+
# @param obj [Phlex::SGML] The object to be rendered.
|
|
47
52
|
DEFAULT_LAYOUT_HANDLER = proc do |layout, layout_opts, obj|
|
|
48
53
|
layout_opts ? layout.new(obj, **layout_opts) : layout.new(obj)
|
|
49
54
|
end
|
|
@@ -93,24 +98,32 @@ class Roda
|
|
|
93
98
|
|
|
94
99
|
module InstanceMethods
|
|
95
100
|
# Retrieves or sets the layout.
|
|
96
|
-
#
|
|
97
|
-
#
|
|
101
|
+
# When no argument is provided, it returns the current layout.
|
|
102
|
+
# Use +nil+ or +false+ to disable layout.
|
|
103
|
+
#
|
|
104
|
+
# @param layout [Class, nil, false] The layout (a +Phlex::SGML+ class) to be set.
|
|
105
|
+
# @return [Class, nil] The current layout (a +Phlex::SGML+ class) or nil if not set.
|
|
98
106
|
def phlex_layout(layout = Undefined)
|
|
99
107
|
case layout
|
|
100
108
|
when Undefined
|
|
101
109
|
opts.dig(:phlex, :layout)
|
|
102
|
-
when nil
|
|
110
|
+
when nil, false
|
|
103
111
|
opts[:phlex].delete(:layout)
|
|
104
|
-
opts[:phlex].delete(:layout_opts)
|
|
105
|
-
when ::Phlex::SGML
|
|
106
|
-
opts[:phlex][:layout] = layout
|
|
107
112
|
else
|
|
108
|
-
|
|
113
|
+
if layout <= ::Phlex::SGML
|
|
114
|
+
opts[:phlex][:layout] = layout
|
|
115
|
+
else
|
|
116
|
+
raise TypeError.new(layout)
|
|
117
|
+
end
|
|
109
118
|
end
|
|
110
119
|
end
|
|
111
120
|
|
|
112
121
|
# Retrieves or sets the layout options.
|
|
113
|
-
#
|
|
122
|
+
# When no argument is provided, it returns the current layout options.
|
|
123
|
+
# Use +nil+ to delete layout options.
|
|
124
|
+
#
|
|
125
|
+
# @note The {DEFAULT_LAYOUT_HANDLER} expects +layout_opts+ to be a +Hash+.
|
|
126
|
+
# @param layout_opts [Object, nil] The layout options to be set, usually a +Hash+.
|
|
114
127
|
# @return [Object, nil] The current layout options or nil if not set.
|
|
115
128
|
def phlex_layout_opts(layout_opts = Undefined)
|
|
116
129
|
case layout_opts
|
|
@@ -124,14 +137,17 @@ class Roda
|
|
|
124
137
|
end
|
|
125
138
|
|
|
126
139
|
# Retrieves or sets the layout handler.
|
|
127
|
-
#
|
|
128
|
-
#
|
|
140
|
+
# When no argument is provided, it returns the current layout handler.
|
|
141
|
+
# Use +nil+ or +:default: to reset the layout handler to the {DEFAULT_LAYOUT_HANDLER}.
|
|
142
|
+
#
|
|
143
|
+
# @param handler [#call, nil, :default] The layout handler to be set.
|
|
144
|
+
# @return [#call] The current layout handler.
|
|
129
145
|
def phlex_layout_handler(handler = Undefined)
|
|
130
146
|
case handler
|
|
131
147
|
when Undefined
|
|
132
148
|
opts.dig(:phlex, :layout_handler)
|
|
133
|
-
when nil
|
|
134
|
-
opts[:phlex]
|
|
149
|
+
when nil, :default
|
|
150
|
+
opts[:phlex][:layout_handler] = DEFAULT_LAYOUT_HANDLER
|
|
135
151
|
else
|
|
136
152
|
opts[:phlex][:layout_handler] = handler
|
|
137
153
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roda-phlex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Schulze
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: phlex
|
|
@@ -47,8 +47,10 @@ extra_rdoc_files: []
|
|
|
47
47
|
files:
|
|
48
48
|
- ".devcontainer/Gemfile"
|
|
49
49
|
- ".devcontainer/devcontainer.json"
|
|
50
|
+
- ".markdownlint.yml"
|
|
50
51
|
- ".rspec"
|
|
51
52
|
- ".standard.yml"
|
|
53
|
+
- ".yardopts"
|
|
52
54
|
- CHANGELOG.md
|
|
53
55
|
- CODE_OF_CONDUCT.md
|
|
54
56
|
- LICENSE.txt
|
|
@@ -78,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
78
80
|
- !ruby/object:Gem::Version
|
|
79
81
|
version: '0'
|
|
80
82
|
requirements: []
|
|
81
|
-
rubygems_version: 3.5.
|
|
83
|
+
rubygems_version: 3.5.23
|
|
82
84
|
signing_key:
|
|
83
85
|
specification_version: 4
|
|
84
86
|
summary: A Phlex adapter for Roda
|