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/guides/essential/01_setup.md
+63-74Lines changed: 63 additions & 74 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -218,99 +218,104 @@ end
218
218
219
219
If we visit [localhost:3000](http://localhost:3000/) now, we can see that our app is rendered around our first page and the "Hello world!" is shown below the heading "Demo App".
220
220
221
+
**Create a second page**
221
222
222
-
----
223
-
Refactor the below part and remove doubled stuff!
223
+
In order to better unterstand which advantages and features apps provide, let's create a second page.
224
224
225
-
Next steps:
226
-
- add a second page
227
-
- introduce a navigation with transition
228
-
- describe the benefits of transitions inside an app ;)
229
-
----
225
+
First we add a route to our `routes.rb` file.
230
226
227
+
```ruby
228
+
Rails.application.routes.draw do
229
+
root to:'demo#first_page'
230
+
get '/second_page'to:'demo#second_page'
231
+
end
232
+
```
231
233
232
-
233
-
Within your `app` directory, create a directory called `matestack` - this is where `matestack`**apps**, **pages** and, later on, **components**, will live.
234
-
235
-
Now, create a file called `app.rb` in `app/matestack/demo/`, and add the following content:
234
+
Afterwards we create the second page under `app/matestack/demo/pages` as `second_page.rb` and add some page content.
paragraph text:"I'm a paragraph on the second page."
249
243
end
250
244
end
251
245
252
246
end
253
247
```
254
248
255
-
This file provides us with a basic app layout that will stay the same throughout the pages within this app - the header (and other content you may add in the above file) will stay the same, and switching between pages will only replace the `page_content` within the `main`-tag.
256
-
257
-
Moving on, create two files called `first_page.rb` and `second_page.rb` within `app/matestack/demo/pages/`, and add the following content to them:
249
+
To view our second page we need to add the corresponding controller action `second_page`.
Visit [localhost:3000/second_page](http://localhost:3000/second_page) to view our second page.
263
+
264
+
### Understanding matestack apps
265
+
266
+
Now we have two pages which we can only visit via typing in the url. Let's add a navigation above our header to our app in order to navigate between these two pages. We do this like we would normally do it, by adding two links into a _nav_ html tag using matestacks `link` helper. In this step we also add a footer for better understanding of whats happening later.
267
+
268
+
```ruby
269
+
classDemo::App < Matestack::Ui::App
273
270
274
271
defresponse
275
-
5.times do
276
-
paragraph text:'Hello, second page!'
272
+
nav do
273
+
link path: root_path, text:'First Page'
274
+
link path: second_page_path, text:'Second Page'
275
+
header do
276
+
heading size:1, text:'Demo App'
277
+
end
278
+
main do
279
+
yield_page
280
+
end
281
+
footer do
282
+
hr
283
+
small text:'These guides are provided by matestack'
277
284
end
278
285
end
279
286
280
287
end
281
288
```
282
289
283
-
Now, you have two simple matestack pages within your first matestack app, but we're still missing routes and controller actions, so let's quickly add them!
290
+
As you might guess right now, all the method calls like `nav, footer, hr, small` are calls of matestack helpers representing the equivalent html tags.
284
291
285
-
Change your `config/routes.rb` to
292
+
If we visit [localhost:3000](http://localhost:3000/) now, we see our page with the 'Hello World!' content wrapped by our navigation, header and footer. Clicking the link to the second page, the whole browser page is rerendered and we see our second page. Nothing special here, but matestack provides us with a `transition` helper. Let's take a look at what it does by changing our links to transitions.
286
293
287
294
```ruby
288
-
Rails.application.routes.draw do
289
-
root to:'demo_app#first_page'
290
-
291
-
get '/first_page', to:'demo_app#first_page'
292
-
get '/second_page', to:'demo_app#second_page'
293
-
end
294
-
```
295
-
296
-
and create a new controller called `demo_app_controller.rb` within `app/controllers/`, using the following content:
small text:'These guides are provided by matestack'
310
+
end
308
311
end
309
312
310
313
end
311
314
```
312
315
313
-
Great! Now, you should be able to run `rails s` once more and, when visiting [localhost:3000](http://localhost:3000/), be greeted with the contents of your first matestack page!
316
+
Again visit [localhost:3000](http://localhost:3000/). Okay now pay close attention to the navigation, header and footer from our app. When you click one of the links generated by the `transition` helper, you should notice that only the page content, in this case the 'Hello World!' gets replaced by the contents of our second page.
317
+
318
+
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.
314
319
315
320
## Commiting the status quo
316
321
Let's save the progress so far using Git. In the repo root, run
@@ -321,25 +326,9 @@ git add . && git commit -m "Save basic Rails app with PG and matestack set up"
321
326
322
327
to do that.
323
328
324
-
## Deployment
325
-
To set up a new project, run
326
-
```sh
327
-
heroku create
328
-
```
329
-
330
-
followed by
331
-
332
-
```sh
333
-
git push heroku master
334
-
```
335
-
336
-
to trigger the first deployment! After the deployment has successfully finished, you can visit your running application by running
337
-
338
-
```sh
339
-
heroku open
340
-
```
341
-
342
329
## Recap & outlook
343
-
You now have a working Rails app using `matestack` not only up and running, but even successfully deployed in the public web - awesome!
330
+
We now have a working Rails app using `matestack`.
331
+
332
+
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.
344
333
345
334
After taking a well deserved rest, make sure to continue exploring the features `matestack` offers you by checking out the [next part of the series](/guides/essential/02_active_record.md).
0 commit comments