Hello World
Make sure you know how to use matestack-ui-core
before learning matestack-ui-vuejs
1. Use reactive UI components in pure Ruby
Matestack's generic, reactive components can be placed on your UI with a simple Ruby DSL. While putting these generic components in your UI code, you inject some configuration in order to adjust the behaviour to your needs. This enables you to create reactive UIs without touching JavaScript!
Behind the scenes: When calling a reactive component with the Ruby DSL, Matestack will render a special component tag with a bunch of attributes to the resulting, server-side rendered HTML. Within the browser, Vue.js will pick up these component tags and mount the JavaScript driven components on it.
Toggle parts of the UI based on events
matestack-ui-vuejs
offers an event hub. Reactive components can emit and receive events through this event hub. "onclick" and "toggle" calling two of these reactive core components. "onclick" emits an event which causes the body of the "toggle" component to be visible for 5 seconds in this example.
app/matestack/components/some_component.rb
Learn more:
Call controller actions without JavaScript
Core components offer basic dynamic behaviour and let you easily call controller actions and react to server responses on the client side without full page reload. The "action" component is configured to emit an event after successfully performed an HTTP request against a Rails controller action, which is received by the "toggle" component, displaying the success message.
app/matestack/components/some_component.rb
Learn more:
Dynamically handle form input without JavaScript
Create dynamic forms for ActiveRecord Models (or plain objects) and display server side responses, like validation errors or success messages, without relying on a full page reload. Events emitted by the "form" component can be used to toggle parts of the UI.
app/matestack/components/some_component.rb
Learn more:
Implement asynchronous, event-based UI rerendering in pure Ruby
Using Matestack's built-in event system, you can rerender parts of the UI on client side events, such as form or action submissions. Even server side events pushed via ActionCable may be received! The "async" component requests a new version of its body at the server via an HTTP GET request after receiving the configured event. After successful server response, the DOM of the "async" component gets updated. Everything else stays untouched.
app/matestack/components/some_component.rb
Learn more:
Manipulate parts of the UI via ActionCable
"async" rerenders its whole body - but what about just appending the element to the list after successful form submission? The "cable" component can be configured to receive events and data pushed via ActionCable from the server side and just append/prepend new chunks of HTML (ideally rendered through a component) to the current "cable" component body. Updating and deleting is also supported!
app/matestack/components/some_component.rb
app/controllers/some_controller.rb
Learn more:
Easily extend with Vue.js
Matestack's dynamic parts are built on Vue.js. If you want to implement custom dynamic behaviour, you can simply create your own Vue components and use them along Matestack's components. It's even possible to interact with Matestack's components using the built-in event bus.
app/matestack/components/some_component.rb
app/matestack/components/my_vue_js_component.rb
app/matestack/components/my_vue_js_component.js
Learn more:
2. Create whole SPA-like apps in pure Ruby
The last step in order to leverage the full Matestack power: Create a Matestack layout (~Rails layout) and Matestack page (Rails ~view) classes (as seen on matestack-ui-core
) and implement dynamic page transitions with components coming from matestack-ui-vuejs
without any custom JavaScript implementation required.
Create your layouts and views in pure Ruby
The layout class is used to define a layout, usually containing some kind of header, footer and navigation. The page class is used to define a view. Following the same principles as seen on components, you can use components (core or your own) in order to create the UI. The matestack_vue_js_app
page_switch
and transition
components enable dynamic page transition, replacing the yielded content with new serverside rendered content rendered by the requested page.
app/matestack/some_app/some_layout.rb
app/matestack/some_app/pages/page1.rb
app/matestack/some_app/pages/page2.rb
Layouts and pages are referenced in your Rails controllers and actions
Instead of referencing Rails layouts and views on your controllers, you just use apps and pages as substitutes. Work with controllers, actions and routing as you're used to! Controller hooks (e.g. devise's authenticate_user) would still work!
app/controllers/some_controller.rb
app/config/routes.rb
Learn more:
Use CSS animations for fancy page transition animations
Use Matestack's css classes applied to the wrapping DOM structure of a page in order to add CSS animiations, whenever a page transition is performed. You can even inject a loading state element, enriching your page transition effect.
app/matestack/some_app/some_layout.rb
app/assets/stylesheets/application.scss
Last updated