Skip to content

Commit 7b74a8c

Browse files
author
Nils Henning
committed
add documentation and changelog
1 parent 22886a0 commit 7b74a8c

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,7 @@ And use it in your view as follows:
398398
### Rails Views in Matestack Pages/Components
399399

400400
To render existing rails views inside your components or pages use the new `rails_view` component. It replaces the old `html` component.
401-
You can render existing partials and views with this helper anywhere in your app.
402-
Views/Partials that are rendered with a `rails_view` component can access instance variables of the corresponding controller
403-
or you can pass data directly as a hash to it and access it in your view. See below for further details and examples.
404-
405-
Rails View in a component:
406-
```
407-
```
408-
401+
You can render existing partials and views with this helper anywhere in your app. For further information read the `rails_view` documentation.
409402

410403
### Removed Components
411404

docs/components/rails_view.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# matestack core component: rails_view
2+
3+
Show [specs](../../spec/usage/components/rails_view_spec.rb)
4+
5+
Use your rails views or partials with this component in your views, matestack pages, components or apps.
6+
7+
## Parameters
8+
9+
This component expects that either `view` or `partial` is given as parameter.
10+
11+
#### # view - optional
12+
Expects a string, specifying the path of the view that should be rendered by the component.
13+
The path resolution works like rails `render 'your_path'` path resolution.
14+
15+
#### # partial - optional
16+
Expects a string, specifying the partial that should be rendered by the component.
17+
The path resolution works like rails `render partial: 'your_path'` path resolution.
18+
19+
## Example 1 - Using Rails View and Partial on a page, component or app
20+
21+
```ruby
22+
class WelcomePage < Matestack::Ui::Page
23+
def response
24+
rails_view view: 'welcome/header'
25+
rails_view partial: 'welcome/hero'
26+
heading text: 'Welcome', size: 1
27+
end
28+
end
29+
```
30+
31+
The above page will first render your 'welcome/header' view.
32+
If for example you use erb templates, it will render your `app/views/welcome/header.html.erb` view.
33+
And secondly it will render your 'welcome/hero' partial.
34+
Again, if you use erb templates, it will render your `app/views/welcome/_hero.html.erb` partial.
35+
The usage of `rails_view` is the same on a page, component or app.
36+
37+
38+
## Example 2 - Using Rails View in a view
39+
40+
You can also use `rails_view` in another view
41+
42+
```html
43+
<%= matestack_component(:rails_view, view: 'welcome/header') %>
44+
<%= matestack_component(:rails_view, partial: 'welcome/hero') %>
45+
```
46+
47+
## Example 3 - Passing and accessing data
48+
49+
You can access all your instance variables from your controller action within a view or partial rendered by `rails_view`.
50+
You can also pass data explicitly. Just add them to the hash you pass to the `rails_view` call.
51+
You can access those like you would do if you pass `locals` to a rails view or partial.
52+
53+
Your `rails_view` call:
54+
```ruby
55+
rails_view view: 'welcome/header', headline: 'Great to see you!'
56+
```
57+
58+
and in your rails view you can access your data as follows:
59+
```
60+
<h1><%= headline %></h1>
61+
```

0 commit comments

Comments
 (0)