Matestack Ui Core
AboutMatestack Ui CoreMatestack Ui VueJsMatestack Ui Bootstrap
1.5
1.5
  • Welcome
  • Getting started
    • Installation & Update
    • Concepts & Rails Integration
    • Quick Start
    • Support & Feedback [WIP]
    • Common Issues [WIP]
  • UI Components
    • Component Overview
    • Rails Integration
    • Component Registry
    • General Component API
    • Haml Components
    • Reusing Views or Partials
    • Testing [WIP]
  • Reactivity
    • Reactivity Overview
    • Rails Integration
    • Actions
    • Forms
    • Async
    • Cable
    • Isolated
    • Collection
    • Custom Vue.js Components
    • Vue.js Event Hub
    • Vuex [WIP]
  • SPA-like Apps
    • SPA Overview
    • Rails Integration
    • App API
    • Page API
    • Transitions
    • Authorization
    • Tutorial
      • Creating a SPA-like App with Matestack
      • Essential Guide 1: Setup
      • Essential Guide 2: ActiveRecord & Database
      • Essential Guide 3: Person Index, Show, Transition
      • Essential Guide 4: Forms & Actions (Create, Update, Delete)
      • Essential Guide 5: Toggle Component
      • Essential Guide 6: Async Component
      • Essential Guide 7: Partials and custom components
      • Essential Guide 8: Collection and async component
      • Essential Guide 9: Custom Vue.js components
      • Essential Guide 10: Styling and Notifications
      • Essential Guide 11: Authentication
      • Essential Guide 12: Heroku Deployment with Postgres
      • Essential Guide 13: Wrap Up & Outlook
  • Components API
    • Core Components
      • Abbr
      • Address
      • Area
      • Article
      • Aside
      • B
      • Bdi
      • Bdo
      • Blockquote
      • Button
      • Br
      • Caption
      • Cite
      • Code
      • Data
      • Datalist
      • Dd
      • Del
      • Details
      • Dfn
      • Dialog
      • Div
      • Dl
      • Dt
      • Em
      • Fieldset
      • Figure
      • Footer
      • Hr
      • Icon
      • Iframe
      • Img
      • Ins
      • Input
      • Header
      • Heading
      • Kbd
      • Label
      • Legend
      • Link
      • Lists
      • Main
      • Mark
      • Map
      • Meter
      • Nav
      • Noscript
      • Object
      • Option
      • Optgroup
      • Output
      • Paragraph
      • Param
      • Picture
      • Pg
      • Plain
      • Pre
      • Progress
      • S
      • Samp
      • Section
      • Select
      • Small
      • Span
      • Sup
      • Sub
      • Strong
      • Table
      • Template
      • Textarea
      • U
      • Unescaped
      • Q
      • Rails View
      • Rp
      • Rt
      • Ruby
      • Var
      • Video
      • Wbr
      • Youtube
    • Reactive Core Components
      • Action
      • Async
      • Cable
      • Collection
      • Form
      • Form Input
      • Form Checkbox
      • Form Radio
      • Form Select
      • Form Submit
      • Form Textarea
      • Onclick
      • Transition
      • Toggle
  • Integrations
    • Action Cable
    • Devise
    • CSS Frameworks [WIP]
    • Third Party JavaScript [WIP]
    • Third Party Ruby Gems [WIP]
  • Matestack Addons
    • Create your own Addon [WIP]
  • Community
    • Discord
    • Contribute
  • About
    • Core Team [WIP]
    • Sponsoring [WIP]
    • Legal Details [WIP]
Powered by GitBook
On this page
  • Use core components
  • Use registered custom components
  • Access request params
  • Prepare method
  • Use pure Ruby on pages
  • Use instance methods
  • Use local partials
  • Use partials from included modules

Was this helpful?

Edit on GitHub
  1. SPA-like Apps

Page API

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

class ExampleApp::Pages < Matestack::Ui::Page

  def response
    div do
      plain "Hello World from Example Page!"
    end
  end

end

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

class ExampleApp::Pages < Matestack::Ui::Page

  def response
    div do
      # calling your registered card component without using matestack_component helper!
      card title: "hello"
    end
  end

end

Access request params

visit "/my_action_path/?foo=bar"

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  def response
    div do
      plain params[:foo] #--> bar
    end
  end

end

Prepare method

The prepare method is called before rendering.

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  def prepare
    @some_data = "data!"
  end

  def response
    div do
      plain @some_data #--> "data!"
    end
  end

end

Use pure Ruby on pages

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  def prepare
    @some_data = [1,2,3,4,5]
  end

  def response
    div do
      unless @some_data.empty?
        @some_data.each do |data|
          plain data
        end
      else
        plain "no data given"
      end
    end
  end

end

Use instance methods

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  def prepare
    @some_data = [1,2,3,4,5]
  end

  def response
    div do
      unless @some_data.empty?
        @some_data.each do |data|
          plain calculated_value(data)
        end
      else
        plain "no data given"
      end
    end
  end

  def calculated_value data
    return data*2
  end

end

Use local partials

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  def response
    div do
      my_simple_partial
      br
      my_partial_with_param "foo"
      br
      my_partial_with_partial
    end
  end

  def my_simple_partial
    span id: "my_simple_partial" do
      plain "some content"
    end
  end

  def my_partial_with_param some_param
    span id: "my_partial_with_param" do
      plain "content with param: #{some_param}"
    end
  end

  def my_partial_with_partial
    span id: "my_partial_with_partial" do
      my_simple_partial
    end
  end

end

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

module Pages::MySharedPartials

  def my_partial_with_param some_param
    span id: "my_partial_with_param" do
      plain "content with param: #{some_param}"
    end
  end

end

app/matestack/example_app/pages/example_page.rb

class ExampleApp::Pages < Matestack::Ui::Page

  include Pages::MySharedPartials

  def response
    div do
      my_simple_partial
      br
      my_partial_with_param "foo"
      br
      my_partial_with_partial
    end
  end

  def my_simple_partial
    span id: "my_simple_partial" do
      plain "some content"
    end
  end

  def my_partial_with_partial
    span id: "my_partial_with_partial" do
      my_simple_partial
    end
  end

end

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>
PreviousApp APINextTransitions

Last updated 3 years ago

Was this helpful?