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: docs/README.md
+3-348Lines changed: 3 additions & 348 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ Start right away and install `matestack-ui-core` on top of your Rails app, or re
48
48
49
49
## Feature walk-through
50
50
51
-
####1. Create UI components in pure Ruby
51
+
### 1. Create UI components in pure Ruby
52
52
53
53
Craft your UI based on your components written in pure Ruby. Utilizing Ruby's amazing language features, you're able to create a cleaner and more maintainable UI implementation.
54
54
@@ -308,7 +308,7 @@ class Components::CardBody < Matestack::Ui::Component
308
308
end
309
309
```
310
310
311
-
####2. Substitute Rails Views with Matestack Pages
311
+
### 2. Substitute Rails Views with Matestack Pages
312
312
313
313
Until here we used Matestack components on Rails views. If desired you can go one step further and use Matestack components on something called a Matestack Page:
314
314
@@ -349,352 +349,7 @@ end
349
349
350
350
The page response - in this case - will be yielded into the Rails layout if not specified differently.
351
351
352
-
#### 3. Wrap Matestack Pages in Matestack Layouts
353
-
354
-
Just like a Rails layout would yield a Rails view, a Matestack layout yields a Matestack page. The layout uses Matestack's HTML rendering mechanism in a `response` method and may additionally call other components in order to define a specific UI.
In this basic example the layout is using the methods `h1` and `main` in order to create the markup as well as a `yield` in order to yield a page on a specific position.
372
-
373
-
{% hint style="info" %}
374
-
A Matestack layout itself will be yielded into the Rails layout, unless the Rails layout is disabled in the controller via:`layout false`
375
-
{% endhint %}
376
-
377
-
Usually a layout implies a specific context of your application. Multiple pages are then scoped within that context, which could lead to a file structure like:
378
-
379
-
```bash
380
-
app/matestack/
381
-
|
382
-
└───some_app/
383
-
│ │ some_layout.rb
384
-
│ └───pages/
385
-
│ │ │ page1.rb
386
-
│ │ │ page2.rb
387
-
│ │ │ page3.rb
388
-
```
389
-
390
-
and then used in a controller like this:
391
-
392
-
393
-
394
-
### Feature walk-through
395
-
396
-
#### 1. Create UI components in pure Ruby
397
-
398
-
Craft your UI based on your components written in pure Ruby. Utilizing Ruby's amazing language features, you're able to create a cleaner and more maintainable UI implementation.
399
-
400
-
**Implement UI components in pure Ruby**
401
-
402
-
Create Ruby classes within your Rails project and call Matestack's core components through a Ruby DSL in order to craft your UIs. The Ruby method "div" for example calls one of the static core components, responsible for rendering HTML tags. A component can take Strings, Integers Symbols, Arrays or Hashes (...) as optional properties (e.g. "title") or require them (e.g. "body").
**Use your Ruby UI components on your existing Rails views**
427
-
428
-
Components can be then called on Rails views (not only! see below), enabling you to create a reusable card components, abstracting UI complexity in your own components.
Split your UI implementation into multiple small chunks helping others (and yourself) to better understand your implementation. Using this approach helps you to create a clean, readable and maintainable codebase.
Because it's just a Ruby class, you can use class inheritance in order to further improve the quality of your UI implementation. Class inheritance can be used to easily create variants of UI components but still reuse parts of the implementation.
487
-
488
-
`app/matestack/components/blue_card.rb`
489
-
490
-
```ruby
491
-
classComponents::BlueCard < Components::Card
492
-
493
-
defresponse
494
-
div class: "card shadow-sm border-0 bg-primary text-white"do
Just like you used matestack's core components on your own UI component, you can use your own UI components within other custom UI components. You decide when using a Ruby method partial should be replaced by another self contained UI component!
# Just an example. Would make more sense, if this component had
546
-
# a more complex structure
547
-
div class: "card-body"do
548
-
h5 context.title if context.title.present?
549
-
paragraph context.body, class: "card-body"
550
-
end
551
-
end
552
-
553
-
end
554
-
```
555
-
556
-
**Yield components into components**
557
-
558
-
Sometimes it's not enough to just pass simple data into a component. No worries! You can just yield a block into your components! Using this approach gives you more flexibility when using your UI components. Ofcourse yielding can be used alongside passing in simple params.
# Just an example. Would make more sense, if this component had
590
-
# a more complex structure
591
-
div class: "card-body"do
592
-
yieldifblock_given?
593
-
end
594
-
end
595
-
596
-
end
597
-
```
598
-
599
-
**Use named slots for advanced content injection**
600
-
601
-
If you need to inject multiple blocks into your UI component, you can use "slots"! Slots help you to build complex UI components with multiple named content placeholders for highest implementation flexibility!
# Just an example. Would make more sense, if this component had
642
-
# a more complex structure
643
-
div class: "card-body"do
644
-
div class: "heading-section"do
645
-
slot :heading
646
-
end
647
-
div class: "body-section"do
648
-
slot :body
649
-
end
650
-
end
651
-
end
652
-
653
-
end
654
-
```
655
-
656
-
#### 2. Substitute Rails Views with Matestack Pages
657
-
658
-
Until here we used Matestack components on Rails views. If desired you can go one step further and use Matestack components on something called a Matestack Page:
659
-
660
-
A Matestack page can be compared to a Rails view and might be yielded within a layout provided by an associated Matestack layout class (see below). The page itself uses Matestack's HTML rendering mechanism in a `response` method and may additionally call other components in order to define a specific UI.
The page response - in this case - will be yielded into the Rails layout if not specified differently.
696
-
697
-
#### 3. Wrap Matestack Pages in Matestack Layouts
352
+
### 3. Wrap Matestack Pages in Matestack Layouts
698
353
699
354
Just like a Rails layout would yield a Rails view, a Matestack layout yields a Matestack page. The layout uses Matestack's HTML rendering mechanism in a `response` method and may additionally call other components in order to define a specific UI.
0 commit comments