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.
app/matestack/some_app/some_layout.rb
1
classSomeApp::SomeLayout < Matestack::Ui::Layout
2
3
defresponse
4
h1 "Some App"
5
main do
6
yield
7
end
8
end
9
10
end
Copied!
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.
A Matestack layout itself will be yielded into the Rails layout, unless the Rails layout is disabled in the controller via:layout false
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:
1
app/matestack/
2
|
3
└───some_app/
4
│ │ some_layout.rb
5
│ └───pages/
6
│ │ │ page1.rb
7
│ │ │ page2.rb
8
│ │ │ page3.rb
Copied!
and then used in a controller like this:
app/controllers/some_controller.rb
1
classSomeController< ApplicationController
2
3
include Matestack::Ui::Core::Helper
4
5
matestack_layout SomeApp::SomeLayout
6
7
defpage_1
8
render SomeApp::Pages::Page1
9
end
10
11
defpage_2
12
render SomeApp::Pages::Page2
13
end
14
15
defpage_3
16
render SomeApp::Pages::Page3,matestack_layout:false# skip app layout on this page