Skip to content

Commit b202084

Browse files
author
Nils Henning
committed
[WIP][TASK][REFACTOR] rework guides, rename and add new ones
1 parent f68ff97 commit b202084

13 files changed

+291
-45
lines changed

docs/guides/essential/01_setup.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Essential Guide 1: Setup
2-
Welcome to the first part of the 10-step-guide of setting up a working Rails CRUD app with `matestack-ui-core`!
2+
3+
Welcome to the first part of our essential guide about building a web application with matestack.
34

45
## Introduction
6+
57
In this guide, we will
68
- create a new Rails application
79
- install `matestack-ui-core`
810
- create and render our first 'Hello world' page
911
- add a simple matestack app, wrap our page and add another one
1012

1113
## Prerequisites
14+
1215
To follow along, make sure you have successfully installed
1316
- Ruby (Version > 2.6, [view installation details](https://www.ruby-lang.org))
1417
- RubyOnRails (Version >6.0, [view installation details](https://rubyonrails.org/))
@@ -19,6 +22,7 @@ To follow along, make sure you have successfully installed
1922
The contents of this article are heavily inspired by [Getting Started on Heroku with Rails 6.x](https://devcenter.heroku.com/articles/getting-started-with-rails6), but goes beyond it by introducing the `matestack-ui-core` gem and setting it up with some example content. Both beginners and experienced Ruby/Rails developers should be able to follow along.
2023

2124
## Getting started
25+
2226
In the terminal, create a new Rails app by running
2327

2428
```sh
@@ -108,6 +112,7 @@ Before creating our page we add a root route which calls the `first_page` action
108112
```ruby
109113
Rails.application.routes.draw do
110114
root to: 'demo#first_page'
115+
get '/first_page', to: 'demo#first_page'
111116
end
112117
```
113118

@@ -130,7 +135,7 @@ class FirstPage < Matestack::Ui::Page
130135

131136
def response
132137
div do
133-
plain 'Hello World!'
138+
heading text: 'Hello World!', size: 1
134139
end
135140
end
136141

@@ -139,11 +144,11 @@ end
139144

140145
A page needs to inherit from `Matestack::Ui::Page`. Each page must have a `response` method. The response method should contain your html (written in ruby) which will be displayed when this page gets rendered.
141146

142-
In our `FirstPage` we define the response method and inside call `div` with a block and `plain` with text inside this block. `div` and `plain` are two of many `Matestack::Ui::Components` which you can use to create UI's in Ruby. As you might can imagine the `div` call will render a `<div></div>` and the given block will be rendered inside this div. `plain` renders the given argument plainly. So this response message would look like this in HTML:
147+
In our `FirstPage` we define the response method and inside call `div` with a block and `heading` with text and size inside this block. `div` and `heading` are two of many `Matestack::Ui::Components` which you can use to create UI's in Ruby. As you might can imagine the `div` call will render a `<div></div>` and the given block will be rendered inside this div. `heading` renders a html headline tag with the given size, in this case a _h1_ tag. So this response message would look like this in HTML:
143148

144149
```html
145150
<div>
146-
Hello World!
151+
<h1>Hello World!</h1>
147152
</div>
148153
```
149154

@@ -319,6 +324,7 @@ Again visit [localhost:3000](http://localhost:3000/). Okay now pay close attenti
319324
matestack `transitions` asynchronously fetch the requested page without the app layout and only replaces the page. Providing a more app like or SPA like behavior. And all you needed to do was creating an app for your pages.
320325

321326
## Commiting the status quo
327+
322328
Let's save the progress so far using Git. In the repo root, run
323329

324330
```sh
@@ -328,6 +334,7 @@ git add . && git commit -m "Save basic Rails app with PG and matestack set up"
328334
to do that.
329335

330336
## Recap & outlook
337+
331338
We now have a working Rails app using `matestack`.
332339

333340
In this guide we learned how matestack pages work, how we can use matestacks components to create html and how we can use an app as a layout for pages and what benefits we get through using an app.

docs/guides/essential/02_active_record.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Essential Guide 2: ActiveRecord & Database
2-
Welcome to the second part of the 10-step-guide of setting up a working Rails CRUD app with `matestack-ui-core`!
2+
3+
Welcome to the second part of our essential guide about building a web application with matestack.
34

45
## Introduction
6+
57
In the [previous guide](guides/essential/01_setup.md), we created a new project, installed the necessary libraries, added a demo `matestack` app featuring two `matestack` pages, and deployed it using Heroku.
68

79
In this guide, we will
@@ -10,9 +12,11 @@ In this guide, we will
1012
- deploy the changes to the publicly running Heroku application
1113

1214
## Prerequisites
15+
1316
We expect you to have successfully finished the [previous guide](guides/essential/01_setup.md).
1417

1518
## Adding the ActiveRecord model
19+
1620
First, we need to create an ActiveRecord model and add the corresponding table to the database. This is quickly achieved by running
1721

1822
```sh
@@ -28,6 +32,7 @@ rails db:migrate
2832
which should update the database schema in `db/schema.rb`.
2933

3034
## Updating the model, adding seeds and displaying an index page
35+
3136
The `role` database field should represent different roles which we define as an enum in our person model. Update `app/models/person.rb` to look like this:
3237

3338
```ruby
@@ -120,13 +125,15 @@ Run `rails s` and head over to [localhost:3000/persons/index](http://localhost:3
120125
Of course, this is a very basic approach that we will iterate and improve in the following parts of this guide series!
121126

122127
## Saving the status quo
128+
123129
As usual, we want to commit the progress to Git. In the repo root, run
124130

125131
```sh
126132
git add . && git commit -m "Introduce person model including seeds, add it to matestack/demo/app.rb"
127133
```
128134

129135
## Recap & outlook
136+
130137
We have updated the app to use a working database model, added some records and displayed them on an index page.
131138

132139
Let's continue and build even cooler stuff by heading directly to the [next part of the series](/guides/essential/03_index_show.md).

docs/guides/essential/03_index_show_transition.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Essential Guide 3: Person Index, Show, Transition
2-
Welcome to the third part of the 10-step-guide of setting up a working Rails CRUD app with `matestack-ui-core`!
2+
3+
Welcome to the third part of our essential guide about building a web application with matestack.
34

45
## Introduction
6+
57
In the [previous guide](guides/essential/02_active_record.md), we added an ActiveRecord model to our project, added some fake persons to our database and displayed them on an index page.
68

79
In this guide, we will
810
- a detail page for every person
911
- dive more into the concept of page transitions
1012

1113
## Prerequisites
14+
1215
We expect you to have successfully finished the [previous guide](guides/essential/02_active_record.md).
1316

1417
## Update person controller and routes
@@ -43,6 +46,7 @@ end
4346
```
4447

4548
## Page transitions
49+
4650
In `app/matestack/demo/app.rb`, replace the contents with the code snippet below in order to add a navigation transition to the root path in our app layout.
4751

4852
```ruby

docs/guides/essential/04_forms_edit_new_create_update_delete.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Essential Guide 4: Forms & Actions (Create, Update, Delete)
22

3-
Welcome to the forth part of the 10-step-guide of setting up a working Rails CRUD app with `matestack-ui-core`!
3+
Welcome to the fourth part of our essential guide about building a web application with matestack.
44

55
## Introduction
66

@@ -13,8 +13,6 @@ In this guide, we will
1313
- introduce the concept of matestack forms
1414
- introduce the concept of matestack actions
1515

16-
action with a delete button to the "show" page and corresponding controller action to remove an existing person from the database
17-
1816
## Prerequisites
1917
We expect you to have successfully finished the [previous guide](guides/essential/03_index_show_transition.md).
2018

@@ -124,7 +122,7 @@ Create a new page in `app/matestack/demo/pages/persons/new.rb` and add the follo
124122
class Demo::Pages::Persons::New < Matestack::Ui::Page
125123

126124
def response
127-
transition path: :persons_path, text: 'All persons'
125+
transition path: persons_path, text: 'All persons'
128126
heading size: 2, text: 'Create a new person'
129127
form new_person_form_config, :include do
130128
label text: 'First name'
@@ -254,7 +252,7 @@ Update your show page in `app/matestack/demo/pages/persons/show.rb` to look like
254252
class Demo::Pages::Persons::Show < Matestack::Ui::Page
255253

256254
def response
257-
transition path: :persons_path, text: 'Back to index'
255+
transition path: persons_path, text: 'All persons'
258256
heading size: 2, text: "Name: #{@person.first_name} #{@person.last_name}"
259257
paragraph text: "Role: #{@person.role}"
260258
transition path: :edit_person_path, params: { id: @person.id }, text: 'Edit'
@@ -314,4 +312,4 @@ We got a brief introduction of the `form` and `action` components and know how t
314312

315313
But there's still more guides coming - so what's left? In the upcoming chapters, we will dive deeper into some `matestack` concepts to further enhance both user experience and developer happiness!
316314

317-
Take a well deserved rest and make sure to come back to the next part of this series, introducing the powerful [`async` and `collection` components](/guides/essential/04_form_create_update_delete.md).
315+
Take a well deserved rest and make sure to come back to the next part of this series, introducing the powerful [`toggle component`](/guides/essential/05_toggle_component.md).
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Essential Guide 5: Toggle Component
2+
3+
Welcome to the fifth part of our essential guide about building a web application with matestack.
4+
5+
## Introduction
6+
7+
In this guide, we will introduce matestacks `toggle` and `onclick` components. For this we will
8+
- add a show more button to the person show page
9+
- add more content to the show page
10+
11+
## Prerequisites
12+
13+
We expect you to have successfully finished the [previous guide](guides/essential/04_forms_edit_new_create_update_delete.md).
14+
15+
## Adding a show more button with onclick
16+
17+
Let's add a show more button to the person show page. When clicked more information about the user should be shown. In our case when it was created and when it was last updated. To do this we will use matestacks `onclick` component and later the `toggle` component.
18+
19+
Edit the show page in `app/matestack/demo/pages/persons/show.rb`
20+
21+
```ruby
22+
class Demo::Pages::Persons::Show < Matestack::Ui::Page
23+
24+
def response
25+
transition path: persons_path, text: 'All Persons'
26+
heading size: 2, text: "Name: #{@person.first_name} #{@person.last_name}"
27+
paragraph text: "Role: #{@person.role}"
28+
29+
onclick emit: 'show_more' do
30+
button text: 'Show more'
31+
end
32+
33+
transition path: :edit_person_path, params: { id: @person.id }, text: 'Edit'
34+
action delete_person_config do
35+
button text: 'Delete person'
36+
end
37+
end
38+
39+
#...
40+
41+
end
42+
```
43+
44+
So what does the `onclick` component do? Onclick takes one argument called `emit`. The `onclick` component renders the given block and if its clicked emits an event with the specified name. In this case it emits an event with the name `show_more` when the button is clicked. In the next section you will find out, why this is useful.
45+
46+
## Show more content with toggle
47+
48+
When the show more button is clicked, we want to show more content. Above we added a button which emits a `show_more` event when clicked. So we need a component which will show its content when this event is emitted. For this we use matestacks `toggle` component. It allows us to show or hide content depending on emitted events. Let's add more content inside a `toggle` component to the show page.
49+
50+
```ruby
51+
class Demo::Pages::Persons::Show < Matestack::Ui::Page
52+
53+
def response
54+
transition path: persons_path, text: 'All Persons'
55+
heading size: 2, text: "Name: #{@person.first_name} #{@person.last_name}"
56+
paragraph text: "Role: #{@person.role}"
57+
58+
onclick emit: 'show_more' do
59+
button text: 'Show more'
60+
end
61+
62+
toggle show_on: 'show_more' do
63+
paragraph text: "Created at: #{I18n.l(@person.created_at)}"
64+
paragraph text: "Created at: #{I18n.l(@person.updated_at)}"
65+
end
66+
67+
transition path: :edit_person_path, params: { id: @person.id }, text: 'Edit'
68+
action delete_person_config do
69+
button text: 'Delete person'
70+
end
71+
end
72+
73+
#...
74+
75+
end
76+
```
77+
78+
The `toggle` component will be hidden on page loads. When we click our 'Show more' button, the content of our `toggle` component gets visible and you can see the localized time of the person created and updated timestamp.
79+
80+
Run `rails s` and head over to [localhost:3000](http://localhost:3000/) and open the details of one person to test it out.
81+
82+
To learn more, check out the [complete API documentation](/docs/api/components/toggle.md) for the `toggle` component.
83+
84+
## Saving the status quo
85+
86+
As usual, we want to commit the progress to Git. In the repo root, run
87+
88+
```sh
89+
git add . && git commit -m "add show more toggle to person show page"
90+
```
91+
92+
## Recap & outlook
93+
94+
We added a show more button to our persons show page and learned how to use the `onclick` and `toggle` components and what they can be used for.
95+
96+
Take a well deserved rest and make sure to come back to the next part of this series, introducing the powerful [`async` component](/guides/essential/06_async_component.md).

0 commit comments

Comments
 (0)