A page orchestrates components within its response method. A Rails controller action references a page (and its corresponding app) in its render call. Thus a matestack page substitutes a typical Rails view.
Use core components
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefresponse div do plain "Hello World from Example Page!"endendend
Use registered custom components
Imagine having created and registered a custom component card. Go ahead and use it on your page:
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefresponse div do# calling your registered card component without using matestack_component helper! card title: "hello"endendend
Access request params
visit "/my_action_path/?foo=bar"
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefresponse div do plain params[:foo] #--> barendendend
Prepare method
The prepare method is called before rendering.
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefprepare @some_data ="data!"enddefresponse div do plain @some_data #--> "data!"endendend
Use pure Ruby on pages
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefprepare @some_data = [1,2,3,4,5]enddefresponse div dounless @some_data.empty? @some_data.each do|data| plain dataendelse plain "no data given"endendendend
Use instance methods
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefprepare @some_data = [1,2,3,4,5]enddefresponse div dounless @some_data.empty? @some_data.each do|data| plain calculated_value(data)endelse plain "no data given"endendenddefcalculated_valuedatareturn data*2endend
Use local partials
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::Pagedefresponse div do my_simple_partial br my_partial_with_param "foo" br my_partial_with_partialendenddefmy_simple_partial span id: "my_simple_partial"do plain "some content"endenddefmy_partial_with_paramsome_param span id: "my_partial_with_param"do plain "content with param: #{some_param}"endenddefmy_partial_with_partial span id: "my_partial_with_partial"do my_simple_partialendendend
renders to:
<div>
<span id="my_simple_partial">
some content
</span>
<br/>
<span id="my_partial_with_param">
content with param: foo
</span>
<br/>
<span id="my_partial_with_partial">
<span id="my_simple_partial">
some content
</span>
</span>
</div>
Use partials from included modules
app/matestack/pages/my_shared_partials.rb
modulePages::MySharedPartialsdefmy_partial_with_paramsome_param span id: "my_partial_with_param"do plain "content with param: #{some_param}"endendend
app/matestack/example_app/pages/example_page.rb
classExampleApp::Pages<Matestack::Ui::PageincludePages::MySharedPartialsdefresponse div do my_simple_partial br my_partial_with_param "foo" br my_partial_with_partialendenddefmy_simple_partial span id: "my_simple_partial"do plain "some content"endenddefmy_partial_with_partial span id: "my_partial_with_partial"do my_simple_partialendendend
renders to:
<div>
<span id="my_simple_partial">
some content
</span>
<br/>
<span id="my_partial_with_param">
content with param: foo
</span>
<br/>
<span id="my_partial_with_partial">
<span id="my_simple_partial">
some content
</span>
</span>
</div>