Skip to content

Commit 98839cd

Browse files
author
Nils Henning
committed
[TASK][REFACTOR] finish reworking 01_setup guide, update heroku deployment guide
1 parent 1c4f9b5 commit 98839cd

File tree

2 files changed

+81
-74
lines changed

2 files changed

+81
-74
lines changed

docs/guides/essential/01_setup.md

Lines changed: 63 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -218,99 +218,104 @@ end
218218

219219
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".
220220

221+
**Create a second page**
221222

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.
224224

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.
230226

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+
```
231233

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.
236235

237236
```ruby
238-
class Demo::App < Matestack::Ui::App
237+
class Demo::Pages::SecondPage < Matestack::Ui::Page
239238

240239
def response
241-
header do
242-
heading size: 1, text: 'Demo App'
243-
transition path: :first_page_path, text: 'First page'
244-
br
245-
transition path: :second_page_path, text: 'Second page'
246-
end
247-
main do
248-
page_content
240+
div do
241+
heading size: 1, text: 'I am the second page!'
242+
paragraph text: "I'm a paragraph on the second page."
249243
end
250244
end
251245

252246
end
253247
```
254248

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`.
258250

259251
```ruby
260-
# in app/matestack/demo/pages/first_page.rb
261-
class Demo::Pages::FirstPage < Matestack::Ui::Page
252+
class DemoController < ApplicationController
253+
#...
262254

263-
def response
264-
5.times do
265-
paragraph text: 'Hello, first page!'
266-
end
255+
def second_page
256+
render Demo::Pages::SecondPage
267257
end
268258

269259
end
260+
```
270261

271-
# in app/matestack/demo/pages/second_page.rb
272-
class Demo::Pages::SecondPage < Matestack::Ui::Page
262+
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+
class Demo::App < Matestack::Ui::App
273270

274271
def response
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'
277284
end
278285
end
279286

280287
end
281288
```
282289

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.
284291

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.
286293

287294
```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:
297-
298-
```ruby
299-
class DemoAppController < ApplicationController
300-
matestack_app Demo::App
301-
302-
def first_page
303-
render Demo::Pages::FirstPage
304-
end
295+
class Demo::App < Matestack::Ui::App
305296

306-
def second_page
307-
render Demo::Pages::SecondPage
297+
def response
298+
nav do
299+
transition path: root_path, text: 'First Page'
300+
transition path: second_page_path, text: 'Second Page'
301+
header do
302+
heading size: 1, text: 'Demo App'
303+
end
304+
main do
305+
yield_page
306+
end
307+
footer do
308+
hr
309+
small text: 'These guides are provided by matestack'
310+
end
308311
end
309312

310313
end
311314
```
312315

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.
314319

315320
## Commiting the status quo
316321
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"
321326

322327
to do that.
323328

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-
342329
## 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.
344333

345334
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).

docs/guides/essential/11_heroku_deployment.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,22 @@ production:
4545
database: myapp_production
4646
username: myapp
4747
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
48+
```
49+
50+
## Deployment
51+
To set up a new project, run
52+
```sh
53+
heroku create
54+
```
55+
56+
followed by
57+
58+
```sh
59+
git push heroku master
60+
```
61+
62+
to trigger the first deployment! After the deployment has successfully finished, you can visit your running application by running
63+
64+
```sh
65+
heroku open
4866
```

0 commit comments

Comments
 (0)