Skip to content

Commit 64ba88d

Browse files
author
Nils Henning
committed
[REFACTOR] update guides
1 parent ec28942 commit 64ba88d

File tree

4 files changed

+399
-240
lines changed

4 files changed

+399
-240
lines changed

docs/guides/essential/07_partials_and_custom_components.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -223,38 +223,6 @@ Using ur custom component is as easy as calling the name we defined in our regis
223223

224224
When you start your application locally now, the missing list bullet points should be the only visible change. We will take care of styling soon - but first, let's reuse our newly introduced component!
225225

226-
----
227-
# Refactor from here
228-
----
229-
230-
## Reusing the custom component
231-
How about displaying three random persons from the database on the person show page, each within a card? It's as simple as below:
232-
233-
```ruby
234-
class Demo::Pages::Persons::Show < Matestack::Ui::Page
235-
236-
def prepare
237-
@other_persons = Person.where.not(id: @person.id).order("RANDOM()").limit(3)
238-
end
239-
240-
def response
241-
# ...
242-
other_persons
243-
end
244-
245-
def other_persons
246-
heading size: 3, text: 'Three other persons:'
247-
@other_persons.each do |person|
248-
person_teaser person: person
249-
end
250-
end
251-
252-
# ...
253-
end
254-
```
255-
256-
We query the database for three random records in the `prepare` method, add a partial for better composability and then loop through the records, handing each record as input to our custom card component!
257-
258226
## Using HAML in custom components
259227

260228
If you need more fine-grained control of your view layer or want to reuse some old HAML files, you can also create custom components like this:

docs/guides/essential/09_custom_vue_js_components.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Okay, let's create our custom vue.js component. First we create a component in `
2323

2424
```ruby
2525
class Components::Persons::Activity < Matestack::Ui::VueJsComponent
26+
vue_js_component_name 'person-activity'
2627

2728
def response
2829
div do
@@ -44,10 +45,12 @@ end
4445

4546
Our vue.js component renders a div containing a paragraph and a list. The paragraph contains some text and a button. We set a `v-on:click` event handler like you would normally do in vue.js with its shorter version `@click`. This means the button will call the `addActivity` method from its corresponding vue.js component. In the list below we assume that our javascript vue.js component has an `activities` array. We loop over it, again using vue.js directives and display each activity with a button labelled 'Remove' which calls `deleteActivity(index)` if clicked.
4647

47-
Like stated above, a `Matestack::Ui::VueJsComponent` requires a javascript counterpart. Let's create it aside our ruby component in `app/matestack/components/persons/activity.js`
48+
Like stated above, a `Matestack::Ui::VueJsComponent` requires a javascript counterpart.
49+
Inside we define a vue.js component and give it a name. The name needs to equal the name we defined in our ruby component at the top with `vue_js_component_name`. This settings is necessary in order to connect the javascript component with our ruby component.
50+
Let's create it aside our ruby component in `app/matestack/components/persons/activity.js`
4851

4952
```javascript
50-
MatestackUiCore.Vue.component('custom-person-activity', {
53+
MatestackUiCore.Vue.component('person-activity', {
5154
mixins: [MatestackUiCore.componentMixin],
5255
data() {
5356
return {
@@ -82,7 +85,7 @@ After creating the new component, we still need to register it, both in the `/ap
8285
module Components::Registry
8386

8487
Matestack::Ui::Core::Component::Registry.register_components(
85-
person_card: Components::Persons::Teaser,
88+
person_teaser: Components::Persons::Teaser,
8689
person_disclaimer: Components::Persons::Disclaimer,
8790
person_activity: Components::Persons::Activity
8891
)

0 commit comments

Comments
 (0)