Rails Controller Integration
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
class SomeApp::SomeLayout < Matestack::Ui::Layout
2
3
def response
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
class SomeController < ApplicationController
2
3
include Matestack::Ui::Core::Helper
4
5
matestack_layout SomeApp::SomeLayout
6
7
def page_1
8
render SomeApp::Pages::Page1
9
end
10
11
def page_2
12
render SomeApp::Pages::Page2
13
end
14
15
def page_3
16
render SomeApp::Pages::Page3, matestack_layout: false # skip app layout on this page
17
end
18
19
end
Copied!
Last modified 3mo ago
Copy link
Edit on GitHub