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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a78afcc1302f4df83e718925f4dd189fd6270a83f6a0bd1a3fd14c480e15131e
4
- data.tar.gz: 3337dfdb6dc398e901222b50c1b51fb480070204298b406c486238b4c0c8a58c
3
+ metadata.gz: 4ade28895613c97c295fa86d342ca9d3257776c26c049c83b2cf07a2be820217
4
+ data.tar.gz: 01503db3aa7fb22ae8721abb252e37a13a487c39754dc5403165015e79cea470
5
5
  SHA512:
6
- metadata.gz: ddc9255d6c867f6bd67c349df61e05c0bc79af68a3ede5be8217bee8ae42b6b6f08c40064f43d956eec2ab82007742608d948b071c3efe448c3ca1196c1a626a
7
- data.tar.gz: 62e813a5c2523581b1eecc0fd3b02549d698454433f49618b5b3500684fc7fad8018b7a90d245b80711ce80bb98b4b8091cfdfe8ce8dc2c0fd26b7d2610fa6c6
6
+ metadata.gz: a24fa744893452533b2be29534daf8cea3d2a9c99f04eacef9779998ede4ea6c09cc1cad0ab88599cd1cff7e56e6562540a07ef4e77014b3f690403278102a6c
7
+ data.tar.gz: 38fb8b653b9585149ccdb659ee13a8990afea1991a480003890dde99ab317bbe8eba70e9ae2bfdc6f06f6e4f7b5b345958cfb5fb1a1d97b022485d67ffc03483
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
  SuggestExtensions: false
4
- TargetRubyVersion: 2.7
4
+ TargetRubyVersion: 3.2
5
5
 
6
6
  Layout:
7
7
  Enabled: false
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
@@ -12,4 +12,3 @@ gem 'rack-test'
12
12
  gem 'rake'
13
13
  gem 'rspec'
14
14
  gem 'rubocop'
15
- gem 'sinatra'
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 integration lets you use the `url()` helper method from within a Phlex view (along with the rest of the helper methods available in a Sinatra action).
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
- To enable the integration use the `phlex` method in your Sinatra action and pass an _instance_ of the Phlex view (instead of using `.call` to get its output):
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Sinatra
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
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
- IncompatibleOptionError = Class.new(Error)
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 SGML
22
- module Overrides
23
- def helpers
24
- @_view_context
25
- end
22
+ module SGMLOverrides
23
+ def helpers
24
+ context
25
+ end
26
26
 
27
- def url(...)
28
- helpers.url(...)
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 Phlex::Sinatra::TypeError.new(obj) unless obj.is_a?(Phlex::SGML)
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?(Phlex::SVG) && !layout
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, view_context: self)
54
+ obj.call(out, context: self)
64
55
  end
65
56
  else
66
- output = obj.call(view_context: self)
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.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: 2024-09-10 00:00:00.000000000 Z
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: 1.7.0
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: 1.7.0
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.7'
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.5.17
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: []