web_pipe 0.9.0 → 0.10.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/CHANGELOG.md +5 -0
- data/README.md +37 -33
- data/docs/composing_applications.md +2 -2
- data/docs/connection_struct.md +1 -1
- data/docs/connection_struct/configuring_the_connection_struct.md +2 -2
- data/docs/extensions/dry_schema.md +1 -1
- data/docs/extensions/dry_view.md +1 -1
- data/docs/extensions/rails.md +115 -0
- data/docs/extensions/router_params.md +1 -1
- data/docs/introduction.md +5 -5
- data/docs/plugging_operations.md +1 -1
- data/docs/recipes/dry_rb_integration.md +2 -2
- data/docs/recipes/hanami_router_integration.md +1 -1
- data/docs/recipes/using_all_restful_methods.md +1 -1
- data/docs/using_rack_middlewares.md +1 -1
- data/lib/web_pipe.rb +4 -0
- data/lib/web_pipe/extensions/rails/rails.rb +152 -0
- data/lib/web_pipe/version.rb +1 -1
- metadata +4 -3
- data/docs/_config.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb774cbbdd90831e9ffcd5dba76265c37585b65f56618aff8cfa311b78d2bea8
|
4
|
+
data.tar.gz: c456b68f6995308a740dacf97bb7177f140c51757fa6f680ecc7e515036d37a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 118d6af2b98c082fa174b33e092744d82a5e2667e20bc717ef996fa9da1b934d44a618331527d2c328d02ce2ea0dc62b3649800f326cfc7516f9ba3ba23c8797
|
7
|
+
data.tar.gz: 32cb91bec0de9aaab6f48d48f4c68334a64fc3c5e944be4f6c20fccaacf1dab928b59809b0e50c129306d43951f0ef028812ab6196503cfff1d830cf8b5e658a
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
+
## [0.10.0] - 2019-11-15
|
8
|
+
### Added
|
9
|
+
- `:rails` extension integrating with Ruby On Rails.
|
10
|
+
[[#36]](https://github.com/waiting-for-dev/web_pipe/pull/36)
|
11
|
+
|
7
12
|
## [0.9.0] - 2019-08-31
|
8
13
|
### Added
|
9
14
|
- Comprehensive documentation.
|
data/README.md
CHANGED
@@ -10,40 +10,44 @@ In order to use in conjunction with [dry-rb](https://dry-rb.org/)
|
|
10
10
|
ecosystem, see also
|
11
11
|
[`dry-web-web_pipe`](https://github.com/waiting-for-dev/dry-web-web_pipe).
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
1. [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
1. [
|
21
|
-
1. [Injecting
|
22
|
-
1. [Composing
|
23
|
-
1. [
|
24
|
-
1. [
|
25
|
-
1. [
|
26
|
-
|
27
|
-
|
28
|
-
1. [
|
29
|
-
1. [
|
30
|
-
1. [
|
31
|
-
|
32
|
-
1. [
|
33
|
-
1. [
|
34
|
-
1. [
|
35
|
-
|
36
|
-
1. [
|
37
|
-
1. [
|
38
|
-
1. [
|
39
|
-
1. [
|
40
|
-
1. [
|
41
|
-
1. [
|
42
|
-
1. [
|
13
|
+
If you want to use it with a Rails project, don't miss docs for the [rails
|
14
|
+
extension](docs/extensions/rails.md).
|
15
|
+
|
16
|
+
1. [Introduction](docs/introduction.md)
|
17
|
+
1. [Design model](docs/design_model.md)
|
18
|
+
1. [Building a rack application](docs/building_a_rack_application.md)
|
19
|
+
1. [Plugging operations](docs/plugging_operations.md)
|
20
|
+
1. [Resolving operations](docs/plugging_operations/resolving_operations.md)
|
21
|
+
1. [Injecting operations](docs/plugging_operations/injecting_operations.md)
|
22
|
+
1. [Composing operations](docs/plugging_operations/composing_operations.md)
|
23
|
+
1. [Using rack middlewares](docs/using_rack_middlewares.md)
|
24
|
+
1. [Injecting middlewares](docs/using_rack_middlewares/injecting_middlewares.md)
|
25
|
+
1. [Composing middlewares](docs/using_rack_middlewares/composing_middlewares.md)
|
26
|
+
1. [Composing applications](docs/composing_applications.md)
|
27
|
+
1. [Connection struct](docs/connection_struct.md)
|
28
|
+
1. [Sharing data downstream](docs/connection_struct/sharing_data_downstream.md)
|
29
|
+
1. [Halting the pipe](docs/connection_struct/halting_the_pipe.md)
|
30
|
+
1. [Configuring the connection struct](docs/connection_struct/configuring_the_connection_struct.md)
|
31
|
+
1. [DSL free usage](docs/dsl_free_usage.md)
|
32
|
+
1. [Plugs](docs/plugs.md)
|
33
|
+
1. [Config](docs/plugs/config.md)
|
34
|
+
1. [ContentType](docs/plugs/content_type.md)
|
35
|
+
1. [Extensions](docs/extensions.md)
|
36
|
+
1. [Container](docs/extensions/container.md)
|
37
|
+
1. [Cookies](docs/extensions/cookies.md)
|
38
|
+
1. [Flash](docs/extensions/flash.md)
|
39
|
+
1. [Dry Schema](docs/extensions/dry_schema.md)
|
40
|
+
1. [Dry View](docs/extensions/dry_view.md)
|
41
|
+
1. [Params](docs/extensions/params.md)
|
42
|
+
1. [Rails](docs/extensions/rails.md)
|
43
|
+
1. [Redirect](docs/extensions/redirect.md)
|
44
|
+
1. [Router params](docs/extensions/router_params.md)
|
45
|
+
1. [Session](docs/extensions/session.md)
|
46
|
+
1. [URL](docs/extensions/url.md)
|
43
47
|
1. Recipes
|
44
|
-
1. [dry-rb integration](
|
45
|
-
1. [hanami-router integration](
|
46
|
-
1. [Using all RESTful methods](
|
48
|
+
1. [dry-rb integration](docs/recipes/dry_rb_integration.md)
|
49
|
+
1. [hanami-router integration](docs/recipes/hanami_router_integration.md)
|
50
|
+
1. [Using all RESTful methods](docs/recipes/using_all_restful_methods.md)
|
47
51
|
|
48
52
|
```ruby
|
49
53
|
# config.ru
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Composing applications
|
2
2
|
|
3
3
|
Previously, we have seen how to [compose plugged
|
4
|
-
operations](
|
5
|
-
rack middlewares](
|
4
|
+
operations](plugging_operations/composing_operations.md) and how to [compose
|
5
|
+
rack middlewares](using_rack_middlewares/composing_middlewares.md). The logical
|
6
6
|
next step is thinking about composing `web_pipe` applications, which is exactly
|
7
7
|
the same as composing both operations and middlewares at the same time.
|
8
8
|
|
data/docs/connection_struct.md
CHANGED
@@ -69,7 +69,7 @@ run DummyApp.new
|
|
69
69
|
|
70
70
|
As you can see, default available features are the very minimal to read from a
|
71
71
|
request and to write a response. However, you can pick from several
|
72
|
-
(extensions)[
|
72
|
+
(extensions)[extensions.md] which will make your life much easier.
|
73
73
|
|
74
74
|
Immutability is a core design principle in `web_pipe`. All methods in
|
75
75
|
`WebPipe::Conn` which are used to add data to it (both in core behaviour and
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configuring the connection struct
|
2
2
|
|
3
|
-
[Extensions](
|
3
|
+
[Extensions](../extensions.md) add extra behaviour to the connection struct.
|
4
4
|
Sometimes they need some user provided value to work properly or they may allow
|
5
5
|
some tweak depending on user needs.
|
6
6
|
|
@@ -10,7 +10,7 @@ what they need is `#config` attribute, which is very similar to `#bag` except
|
|
10
10
|
for its more private intention.
|
11
11
|
|
12
12
|
In order to interact with `#config`, you can use the method `#add_config(key,
|
13
|
-
value)` or [`Config` plug](
|
13
|
+
value)` or [`Config` plug](../plugs/config.md).
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
class MyApp
|
@@ -9,7 +9,7 @@ pipe of operations. It takes as arguments a `dry-schema` schema and a handler.
|
|
9
9
|
On success, it makes output available at `WebPipe::Conn#sanitized_params`. On
|
10
10
|
error, it calls given handler with the connection struct and validation result.
|
11
11
|
|
12
|
-
This extension automatically loads [`:params` extension](
|
12
|
+
This extension automatically loads [`:params` extension](params.md),
|
13
13
|
as it takes `WebPipe::Conn#params` as input for the validation schema.
|
14
14
|
|
15
15
|
Instead of providing an error handler as the second argument for the plug, you
|
data/docs/extensions/dry_view.md
CHANGED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Rails
|
2
|
+
|
3
|
+
The first two things to keep in mind in order to integrate with Rails is
|
4
|
+
that `WebPipe` instances are Rack applications and that rails router can
|
5
|
+
perfectly [dispatch to a rack application](https://guides.rubyonrails.org/routing.html#routing-to-rack-applications). For example:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# config/routes.rb
|
9
|
+
get '/my_route', to: MyRoute.new
|
10
|
+
|
11
|
+
# app/controllers/my_route.rb
|
12
|
+
class MyRoute
|
13
|
+
include WebPipe
|
14
|
+
|
15
|
+
plug :set_response_body
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_response_body(conn)
|
20
|
+
conn.set_response_body('Hello, World!')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
In order to do something like the previous example you don't need to enable
|
26
|
+
this extension. Notice that rails took care of dispatching the request to our
|
27
|
+
`WebPipe` rack application, which was then responsible for generating the
|
28
|
+
response. In this case, it used a simple call to `#set_response_body`.
|
29
|
+
|
30
|
+
It's quite possible that you don't need more than that in terms of rails
|
31
|
+
integration. Of course, surely you want something more elaborate to generate
|
32
|
+
responses. For that, you can use the view or template system you like. One
|
33
|
+
option that will play specially well here is
|
34
|
+
[`dry-view`](https://dry-rb.org/gems/dry-view/), which
|
35
|
+
[integrates](https://github.com/dry-rb/dry-view/tree/master/examples/rails)
|
36
|
+
itself easily with Rails. Furthermore, we have a tailored `dry_view`
|
37
|
+
[extension](https://waiting-for-dev.github.io/web_pipe/docs/extensions/dry_view.html).
|
38
|
+
|
39
|
+
You need to use this extension if:
|
40
|
+
|
41
|
+
- You want to use `action_view` as rendering system.
|
42
|
+
- You want to use rails url helpers from your `WebPipe` application.
|
43
|
+
- You want to use controller helpers from your `WebPipe` application.
|
44
|
+
|
45
|
+
Rails responsibilities for controlling the request/response cycle and the
|
46
|
+
rendering process are a little bit tangled. For this reason, even if you
|
47
|
+
want to use `WebPipe` applications instead of Rails controller actions you
|
48
|
+
still have to use the typical top `ApplicationController` in order to define
|
49
|
+
some behaviour for the view layer:
|
50
|
+
|
51
|
+
- Which layout is applied to the template.
|
52
|
+
- Which helpers will become available to the templates.
|
53
|
+
- Where within `app/views/` templates are looked up.
|
54
|
+
|
55
|
+
By default, the controller in use is `ActionController::Base`, which means that
|
56
|
+
no layout is applied and only built-in helpers (for example,
|
57
|
+
`number_as_currency`) are available. You can change it via the
|
58
|
+
`:rails_controller` configuration option.
|
59
|
+
|
60
|
+
The main method that this extension adds to `WebPipe::Conn` is `#render`,
|
61
|
+
which just delegates to the [Rails
|
62
|
+
implementation](https://api.rubyonrails.org/v6.0.1/classes/ActionController/Renderer.html)
|
63
|
+
as you'd do in a typical rails controller. Remember that you can provide
|
64
|
+
template instance variables through the keyword `:assigns`.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# config/routes.rb
|
68
|
+
get '/articles', to: ArticlesIndex.new
|
69
|
+
|
70
|
+
# app/controllers/application_controller.rb
|
71
|
+
class ApplicationController < ActionController::Base
|
72
|
+
# By default uses the layout in `layouts/application`
|
73
|
+
end
|
74
|
+
|
75
|
+
# app/controllers/articles_index.rb
|
76
|
+
require 'web_pipe/plugs/config'
|
77
|
+
|
78
|
+
WebPipe.load_extensions(:rails) # You can put it in an initializer
|
79
|
+
|
80
|
+
class ArticlesIndex
|
81
|
+
include WebPipe
|
82
|
+
|
83
|
+
plug :config, WebPipe::Plugs::Config.(
|
84
|
+
rails_controller: ApplicationController
|
85
|
+
)
|
86
|
+
|
87
|
+
def render(conn)
|
88
|
+
conn.render(
|
89
|
+
template: 'articles/index',
|
90
|
+
assigns: { articles: Article.all }
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
Notice that we used the keyword `template:` instead of taking advantage of
|
97
|
+
automatic template lookup. We did that way so that we don't have to create also
|
98
|
+
an `ArticlesController`, but it's up to you.
|
99
|
+
|
100
|
+
Besides, this extension provides with two other methods:
|
101
|
+
|
102
|
+
- `url_helpers` returns Rails router [url
|
103
|
+
helpers](https://api.rubyonrails.org/v6.0.1/classes/ActionView/Helpers/UrlHelper.html).
|
104
|
+
- `helpers` returns the associated [controller
|
105
|
+
helpers](https://api.rubyonrails.org/classes/ActionController/Helpers.html).
|
106
|
+
|
107
|
+
In all the examples we have supposed that we are putting `WebPipe` applications
|
108
|
+
within `app/controllers/` directory. However, remember you can put them
|
109
|
+
wherever you like as long as you respect rails [`autoload_paths`](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths).
|
110
|
+
|
111
|
+
Here you have a link to a very simple and contrived example of a rails
|
112
|
+
application integrating `web_pipe`:
|
113
|
+
|
114
|
+
https://github.com/waiting-for-dev/rails-web_pipe
|
115
|
+
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This extension can be used in order to merge placeholder parameters
|
4
4
|
that usually routers support (like `get /users/:id`) to the parameters hash
|
5
|
-
added through [`:params` extension](
|
5
|
+
added through [`:params` extension](params.md) (which is
|
6
6
|
automatically loaded).
|
7
7
|
|
8
8
|
What this extension does is adding a transformation function to the registry
|
data/docs/introduction.md
CHANGED
@@ -12,17 +12,17 @@ with [dry-rb](https://dry-rb.org/) ecosystem. If it helps, you can think of it
|
|
12
12
|
as a decoupled web controller (as the C in MVC).
|
13
13
|
|
14
14
|
`web_pipe` applications are built as a [pipe of
|
15
|
-
operations](
|
16
|
-
struct](
|
15
|
+
operations](design_model.md) on an [immutable
|
16
|
+
struct](connection_struct.md). The struct is automatically created
|
17
17
|
with data from an HTTP request, and it contains methods to
|
18
18
|
incrementally add data to generate an HTTP response. The pipe can
|
19
|
-
be [halted](
|
19
|
+
be [halted](connection_struct/halting_the_pipe.md) at any moment,
|
20
20
|
taking away from all operations downstream any chance to modify the
|
21
21
|
response.
|
22
22
|
|
23
23
|
`web_pipe` has a modular design, with only the minimal functionalities needed
|
24
24
|
to build a web application enabled by default. However, it ships with several
|
25
|
-
[extensions](
|
25
|
+
[extensions](extensions.md) to make your life easier.
|
26
26
|
|
27
27
|
Following there is a simple example. It is a web application that will check
|
28
28
|
the value of a `user` parameter. When it is `Alice` or `Joe`, it will kindly
|
@@ -70,4 +70,4 @@ class HelloApp
|
|
70
70
|
end
|
71
71
|
|
72
72
|
run HelloApp.new
|
73
|
-
|
73
|
+
```
|
data/docs/plugging_operations.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
You can plug operations to your application with the DSL method `plug`. The
|
4
4
|
first argument it always takes is a symbol with the name you want
|
5
5
|
to give to the operation (which is needed to allow
|
6
|
-
[injection](
|
6
|
+
[injection](plugging_operations/injecting_operations.md) on
|
7
7
|
initialization).
|
8
8
|
|
9
9
|
```ruby
|
@@ -4,8 +4,8 @@
|
|
4
4
|
[dry-rb](https://dry-rb.org/) ecosystem. It shares same design
|
5
5
|
principles and it ships with some extensions which even make this
|
6
6
|
integration tighter (like
|
7
|
-
[`:dry-view`](
|
8
|
-
[`:dry-schema`](
|
7
|
+
[`:dry-view`](../extensions/dry_view.md) or
|
8
|
+
[`:dry-schema`](../extensions/dry_schema.md) extensions).
|
9
9
|
|
10
10
|
If you want to use `web_pipe` with the rest of dry-rb libraries,
|
11
11
|
your best bet is to use
|
@@ -22,4 +22,4 @@ end
|
|
22
22
|
run router
|
23
23
|
```
|
24
24
|
|
25
|
-
In order to perform [string matching with variables](https://github.com/hanami/router#string-matching-with-variables) you just need to load [`:router_params` extension](
|
25
|
+
In order to perform [string matching with variables](https://github.com/hanami/router#string-matching-with-variables) you just need to load [`:router_params` extension](../extensions/router_params.md).
|
@@ -9,7 +9,7 @@ request method in rack's env if a magical `_method` parameter or
|
|
9
9
|
|
10
10
|
You have to be aware that if you use this middleware within a
|
11
11
|
`web_pipe` application (through [`use` DSL
|
12
|
-
method](
|
12
|
+
method](../using_rack_middlewares.md)) it will have no effect.
|
13
13
|
When your `web_pipe` application takes control of the request it
|
14
14
|
has already gone through the router, which is the one who should
|
15
15
|
read the request method set by rack.
|
@@ -9,7 +9,7 @@ encapsulate them in your application definition.
|
|
9
9
|
In order to add rack middlewares to the stack, you have to use the DSL method
|
10
10
|
`use`. The first argument it takes is a `Symbol` with the name you want to
|
11
11
|
assign to it (which is needed to allow
|
12
|
-
[injection](
|
12
|
+
[injection](using_rack_middlewares/injecting_middlewares.md) on
|
13
13
|
initialization). Then, it must follow the middleware class and any option it
|
14
14
|
may need:
|
15
15
|
|
data/lib/web_pipe.rb
CHANGED
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'web_pipe/conn'
|
4
|
+
|
5
|
+
module WebPipe
|
6
|
+
# Integrates with Rails framework.
|
7
|
+
#
|
8
|
+
# The first two things to keep in mind in order to integrate with Rails is
|
9
|
+
# that {WebPipe} instances are Rack applications and that rails router can
|
10
|
+
# perfectly dispatch to a rack application. For example:
|
11
|
+
#
|
12
|
+
# ```ruby
|
13
|
+
# # config/routes.rb
|
14
|
+
# get '/my_route', to: MyRoute.new
|
15
|
+
#
|
16
|
+
# # app/controllers/my_route.rb
|
17
|
+
# class MyRoute
|
18
|
+
# include WebPipe
|
19
|
+
#
|
20
|
+
# plug :set_response_body
|
21
|
+
#
|
22
|
+
# private
|
23
|
+
#
|
24
|
+
# def set_response_body(conn)
|
25
|
+
# conn.set_response_body('Hello, World!')
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
# In order to do something like the previous example you don't need to enable
|
31
|
+
# this extension. Notice that rails took care of dispatching the request to
|
32
|
+
# our {WebPipe} rack application, which was then responsible for generating the
|
33
|
+
# response. In this case, it used a simple call to
|
34
|
+
# {WebPipe::Conn#set_response_body}.
|
35
|
+
#
|
36
|
+
# It's quite possible that you don't need more than that in terms of rails
|
37
|
+
# integration. Of course, surely you want something more elaborate to generate
|
38
|
+
# responses. For that, you can use the view or template system you like. One
|
39
|
+
# option that will play specially well here is `dry-view`, which integrates
|
40
|
+
# itself easily with Rails. Furthermore, we have a tailored `dry_view`
|
41
|
+
# extension.
|
42
|
+
#
|
43
|
+
# You need to use this extension if:
|
44
|
+
#
|
45
|
+
# - You want to use `action_view` as rendering system.
|
46
|
+
# - You want to use rails url helpers from your {WebPipe} application.
|
47
|
+
# - You want to use controller helpers from your {WebPipe} application.
|
48
|
+
#
|
49
|
+
# Rails responsibilities for controlling the request/response cycle and the
|
50
|
+
# rendering process are a little bit tangled. For this reason, even if you
|
51
|
+
# want to use {WebPipe} applications instead of Rails controller actions you
|
52
|
+
# still have to use the typical top `ApplicationController` in order to define
|
53
|
+
# some behaviour for the view layer:
|
54
|
+
#
|
55
|
+
# - Which layout is applied to the template.
|
56
|
+
# - Which helpers will become available to the templates.
|
57
|
+
# - Where within `app/views/` templates are looked up.
|
58
|
+
#
|
59
|
+
# By default, the controller in use is `ActionController::Base`, which means
|
60
|
+
# that no layout is applied and only built-in helpers (for example,
|
61
|
+
# `number_as_currency`) are available. You can change it via the
|
62
|
+
# `:rails_controller` configuration option.
|
63
|
+
#
|
64
|
+
# The main method that this extension adds to {WebPipe::Conn} is `#render`,
|
65
|
+
# which just delegates to the Rails implementation as you'd do in a typical
|
66
|
+
# rails controller. Remember that you can provide template instance variables
|
67
|
+
# through the keyword `:assigns`.
|
68
|
+
#
|
69
|
+
# ```ruby
|
70
|
+
# # config/routes.rb
|
71
|
+
# get '/articles', to: ArticlesIndex.new
|
72
|
+
#
|
73
|
+
# # app/controllers/application_controller.rb
|
74
|
+
# class ApplicationController < ActionController::Base
|
75
|
+
# # By default uses the layout in `layouts/application`
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# # app/controllers/articles_index.rb
|
79
|
+
# require 'web_pipe/plugs/config'
|
80
|
+
#
|
81
|
+
#
|
82
|
+
# WebPipe.load_extensions(:rails) # You can put it in an initializer
|
83
|
+
#
|
84
|
+
# class ArticlesIndex
|
85
|
+
# include WebPipe
|
86
|
+
#
|
87
|
+
# plug :config, WebPipe::Plugs::Config.(
|
88
|
+
# rails_controller: ApplicationController
|
89
|
+
# )
|
90
|
+
#
|
91
|
+
# def render(conn)
|
92
|
+
# conn.render(
|
93
|
+
# template: 'articles/index',
|
94
|
+
# assigns: { articles: Article.all }
|
95
|
+
# )
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
# ```
|
99
|
+
#
|
100
|
+
# Notice that we used the keyword `template:` instead of taking advantage of
|
101
|
+
# automatic template lookup. We did that way so that we don't have to create
|
102
|
+
# also an `ArticlesController`, but it's up to you.
|
103
|
+
#
|
104
|
+
# Besides, this extension provides with two other methods:
|
105
|
+
#
|
106
|
+
# - `url_helpers` returns Rails router url helpers.
|
107
|
+
# - `helpers` returns the associated controller helpers.
|
108
|
+
#
|
109
|
+
# In all the examples we have supposed that we are putting {WebPipe}
|
110
|
+
# applications within `app/controllers/` directory. However, remember you can
|
111
|
+
# put them wherever you like as long as you respect rails `autoload_paths`.
|
112
|
+
#
|
113
|
+
# Here you have a link to a very simple and contrived example of a rails
|
114
|
+
# application integrating `web_pipe`:
|
115
|
+
#
|
116
|
+
# https://github.com/waiting-for-dev/rails-web_pipe
|
117
|
+
#
|
118
|
+
# @see https://guides.rubyonrails.org/routing.html#routing-to-rack-applications
|
119
|
+
# @see https://dry-rb.org/gems/dry-view/
|
120
|
+
# @see https://github.com/dry-rb/dry-view/tree/master/examples/rails
|
121
|
+
# @see https://waiting-for-dev.github.io/web_pipe/docs/extensions/dry_view.html
|
122
|
+
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionController/Renderer.html
|
123
|
+
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionController/Renderer.html
|
124
|
+
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionView/Helpers/UrlHelper.html
|
125
|
+
# @see https://api.rubyonrails.org/classes/ActionController/Helpers.html
|
126
|
+
# @see https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths
|
127
|
+
module Rails
|
128
|
+
def render(*args)
|
129
|
+
set_response_body(
|
130
|
+
rails_controller.renderer.render(*args)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
# @see https://devdocs.io/rails~6.0/actioncontroller/helpers
|
135
|
+
def helpers
|
136
|
+
rails_controller.helpers
|
137
|
+
end
|
138
|
+
|
139
|
+
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionView/Helpers/UrlHelper.html
|
140
|
+
def url_helpers
|
141
|
+
::Rails.application.routes.url_helpers
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def rails_controller
|
147
|
+
config.fetch(:rails_controller, ActionController::Base)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
Conn.include(Rails)
|
152
|
+
end
|
data/lib/web_pipe/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_pipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Busqué
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -244,7 +244,6 @@ files:
|
|
244
244
|
- _config.yml
|
245
245
|
- bin/console
|
246
246
|
- bin/setup
|
247
|
-
- docs/_config.yml
|
248
247
|
- docs/building_a_rack_application.md
|
249
248
|
- docs/composing_applications.md
|
250
249
|
- docs/connection_struct.md
|
@@ -260,6 +259,7 @@ files:
|
|
260
259
|
- docs/extensions/dry_view.md
|
261
260
|
- docs/extensions/flash.md
|
262
261
|
- docs/extensions/params.md
|
262
|
+
- docs/extensions/rails.md
|
263
263
|
- docs/extensions/redirect.md
|
264
264
|
- docs/extensions/router_params.md
|
265
265
|
- docs/extensions/session.md
|
@@ -298,6 +298,7 @@ files:
|
|
298
298
|
- lib/web_pipe/extensions/flash/flash.rb
|
299
299
|
- lib/web_pipe/extensions/params/params.rb
|
300
300
|
- lib/web_pipe/extensions/params/params/transf.rb
|
301
|
+
- lib/web_pipe/extensions/rails/rails.rb
|
301
302
|
- lib/web_pipe/extensions/redirect/redirect.rb
|
302
303
|
- lib/web_pipe/extensions/router_params/router_params.rb
|
303
304
|
- lib/web_pipe/extensions/session/session.rb
|
data/docs/_config.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
theme: jekyll-theme-slate
|