You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,43 @@
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
19
25
phlex MyView.new
20
26
end
21
27
```
22
28
29
+
For a modular app the extension must be explicitly registered:
30
+
31
+
```ruby
32
+
classMyApp < 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:
0 commit comments