Skip to content

Commit 2a9992e

Browse files
author
Nils Henning
committed
[TASK] update rails integration guide
1 parent 88ba19f commit 2a9992e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/guides/300-rails_integration/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,24 @@ So with `rails_view` we can quickly integrate matestack with ease in an existing
282282

283283
## Custom haml components
284284

285-
![Coming Soon](../../images/coming_soon.png)
285+
Another way to reuse your existing views and partials are components with _*.haml_ templates. You can create a component and don't implement a `response` method. In this case matestack will look for a _*.haml_ file right next to it. In this _*.haml_ file you can access all variables, methods, helpers and so on which you could access in a component. Let's take a closer look by recreating our product teaser component with a _*.haml_ file. We create a file called `teaser_haml.rb` in `app/matestack/components/products/`.
286+
287+
```ruby
288+
class Components::Products::TeaserHaml < Matestack::Ui::Component
289+
290+
requires :product
291+
292+
end
293+
```
294+
295+
Next we create the corresponding _*.haml_ template. As said above, matestacks looks for this template next to the component file. So we will create it in `app/matestack/components/products/teaser_haml.haml`.
296+
297+
```
298+
= link_to product_path(product), class: 'product-teaser' do
299+
%div
300+
%h2= product.name
301+
%p= product.description
302+
%b= product.price
303+
```
304+
305+
After registering this component we can use it on our matestack pages or in our rails views with `matestack_render`. This gives you the opportunity to reuse your views, part of them or partials easily by creating a component and moving your view markup into a _*.haml_ file next to it. If you are not already using haml in your project checkout [html2haml](https://github.com/haml/html2haml) or many of the available online tools to convert your erb views effortless into _*.haml_ views.

0 commit comments

Comments
 (0)