phlex-sinatra 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +0 -1
- data/README.md +21 -3
- data/lib/phlex/sinatra/version.rb +1 -1
- data/lib/phlex-sinatra.rb +20 -25
- metadata +20 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ade28895613c97c295fa86d342ca9d3257776c26c049c83b2cf07a2be820217
|
4
|
+
data.tar.gz: 01503db3aa7fb22ae8721abb252e37a13a487c39754dc5403165015e79cea470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24fa744893452533b2be29534daf8cea3d2a9c99f04eacef9779998ede4ea6c09cc1cad0ab88599cd1cff7e56e6562540a07ef4e77014b3f690403278102a6c
|
7
|
+
data.tar.gz: 38fb8b653b9585149ccdb659ee13a8990afea1991a480003890dde99ab317bbe8eba70e9ae2bfdc6f06f6e4f7b5b345958cfb5fb1a1d97b022485d67ffc03483
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## Version 0.5.0 - 2025-02-23
|
2
|
+
|
3
|
+
- Add support for Phlex 2, drop support for Phlex 1 - this also means the minimum required Ruby version is now 3.2.
|
4
|
+
- Reimplement this library to use the official Sinatra extension API. For a modular-style app the extension must now be explicitly registered:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
class MyApp < Sinatra::Base
|
8
|
+
helpers Phlex::Sinatra
|
9
|
+
end
|
10
|
+
```
|
11
|
+
|
1
12
|
## Version 0.4.0 - 2024-09-10
|
2
13
|
|
3
14
|
- Add support for wrapping a Phlex view in a layout. Pass `layout: true` to use Sinatra's default layout or specify the view by passing a symbol. Defaults to ERB and other Sinatra templating languages can be specified via the `layout_engine:` keyword.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
# phlex-sinatra
|
2
2
|
|
3
|
-
[Phlex](https://github.com/phlex-ruby/phlex) already works with Sinatra (and everything else) but its normal usage leaves you without access to Sinatra's standard helper methods. This
|
3
|
+
[Phlex](https://github.com/phlex-ruby/phlex) already works with Sinatra (and everything else) but its normal usage leaves you without access to Sinatra's standard helper methods. This extension lets you use Sinatra's `url()` helper method from within a Phlex view (along with the rest of the helper methods available in a Sinatra action).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add phlex-sinatra to your application's Gemfile and run `bundle install`.
|
7
|
+
Add phlex-sinatra to your application's `Gemfile` and run `bundle install`.
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
gem 'phlex-sinatra'
|
11
11
|
```
|
12
12
|
|
13
|
+
Then require it in your app:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'phlex-sinatra'
|
17
|
+
```
|
18
|
+
|
13
19
|
## Usage
|
14
20
|
|
15
|
-
|
21
|
+
Use the `phlex` helper method to render a Phlex view and pass an _instance_ of the Phlex view (instead of using `.call` to get its output). For a classic-style Sinatra app it'll Just Work™:
|
16
22
|
|
17
23
|
```ruby
|
18
24
|
get '/foo' do
|
@@ -20,6 +26,18 @@ get '/foo' do
|
|
20
26
|
end
|
21
27
|
```
|
22
28
|
|
29
|
+
For a modular app the extension must be explicitly registered:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class MyApp < Sinatra::Base
|
33
|
+
helpers Phlex::Sinatra
|
34
|
+
|
35
|
+
get '/foo' do
|
36
|
+
phlex MyView.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
23
41
|
You can now use Sinatra's `url()` helper method directly and its other methods (`params`, `request`, etc) via the `helpers` proxy:
|
24
42
|
|
25
43
|
```ruby
|
data/lib/phlex-sinatra.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'phlex'
|
4
|
+
require 'sinatra/base'
|
4
5
|
require_relative 'phlex/sinatra/version'
|
5
6
|
|
6
7
|
module Phlex
|
7
8
|
module Sinatra
|
8
9
|
Error = Class.new(StandardError)
|
9
|
-
|
10
|
+
ArgumentError = Class.new(Error)
|
10
11
|
|
11
12
|
class TypeError < Error
|
12
13
|
MAX_SIZE = 32
|
@@ -18,26 +19,16 @@ module Phlex
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
module
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
module SGMLOverrides
|
23
|
+
def helpers
|
24
|
+
context
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
27
|
+
def url(...)
|
28
|
+
context.url(...)
|
30
29
|
end
|
31
30
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class SGML
|
35
|
-
include Sinatra::SGML::Overrides
|
36
|
-
end
|
37
|
-
end
|
38
31
|
|
39
|
-
module Sinatra
|
40
|
-
module Templates
|
41
32
|
def phlex(
|
42
33
|
obj,
|
43
34
|
content_type: nil,
|
@@ -45,9 +36,13 @@ module Sinatra
|
|
45
36
|
layout_engine: :erb,
|
46
37
|
stream: false
|
47
38
|
)
|
48
|
-
raise
|
39
|
+
raise TypeError.new(obj) unless obj.is_a?(SGML)
|
40
|
+
|
41
|
+
if layout && stream
|
42
|
+
raise ArgumentError.new('streaming is not compatible with layout')
|
43
|
+
end
|
49
44
|
|
50
|
-
content_type ||= :svg if obj.is_a?(
|
45
|
+
content_type ||= :svg if obj.is_a?(SVG) && !layout
|
51
46
|
self.content_type(content_type) if content_type
|
52
47
|
|
53
48
|
# Copy Sinatra's behaviour and interpret layout=true as meaning "use the
|
@@ -55,15 +50,11 @@ module Sinatra
|
|
55
50
|
layout = @default_layout if layout == true
|
56
51
|
|
57
52
|
if stream
|
58
|
-
raise Phlex::Sinatra::IncompatibleOptionError.new(
|
59
|
-
'streaming is not compatible with layout'
|
60
|
-
) if layout
|
61
|
-
|
62
53
|
self.stream do |out|
|
63
|
-
obj.call(out,
|
54
|
+
obj.call(out, context: self)
|
64
55
|
end
|
65
56
|
else
|
66
|
-
output = obj.call(
|
57
|
+
output = obj.call(context: self)
|
67
58
|
|
68
59
|
if layout
|
69
60
|
render(layout_engine, layout, { layout: false }) { output }
|
@@ -73,4 +64,8 @@ module Sinatra
|
|
73
64
|
end
|
74
65
|
end
|
75
66
|
end
|
67
|
+
|
68
|
+
SGML.include Sinatra::SGMLOverrides
|
76
69
|
end
|
70
|
+
|
71
|
+
Sinatra.helpers Phlex::Sinatra
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Pickles
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-23 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: phlex
|
@@ -16,14 +15,28 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: '2'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: '2'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: sinatra
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
27
40
|
description: A Phlex adapter for Sinatra
|
28
41
|
email:
|
29
42
|
- spideryoung@gmail.com
|
@@ -49,7 +62,6 @@ metadata:
|
|
49
62
|
homepage_uri: https://github.com/benpickles/phlex-sinatra
|
50
63
|
rubygems_mfa_required: 'true'
|
51
64
|
source_code_uri: https://github.com/benpickles/phlex-sinatra
|
52
|
-
post_install_message:
|
53
65
|
rdoc_options: []
|
54
66
|
require_paths:
|
55
67
|
- lib
|
@@ -57,15 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
69
|
requirements:
|
58
70
|
- - ">="
|
59
71
|
- !ruby/object:Gem::Version
|
60
|
-
version: '2
|
72
|
+
version: '3.2'
|
61
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
74
|
requirements:
|
63
75
|
- - ">="
|
64
76
|
- !ruby/object:Gem::Version
|
65
77
|
version: '0'
|
66
78
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
79
|
+
rubygems_version: 3.6.2
|
69
80
|
specification_version: 4
|
70
81
|
summary: A Phlex adapter for Sinatra
|
71
82
|
test_files: []
|