matestack-ui-vuejs

Boost your productivity & easily create reactive web UIs in pure Ruby.

matestack-ui-vuejs ships all you need to build reactive UIs in pure Ruby orchestrating prebuilt Vue.js components with a simple Ruby DSL.

The prebuilt reactive components built on top of Vue.js are covering typical features of a reactive web UI, such as async form submission, dynamic page transitions or async partial UI updates. No Opal involved

If required, it can be easily extended with pure JavaScript.

Compatibility

matestack-ui-vuejs requires matestack-ui-core

matestack-ui-vuejs is tested against:

  • Rails 7.0.1 + Ruby 3.0.0 + Vue.js 3.2.26

  • Rails 6.1.1 + Ruby 3.0.0 + Vue.js 3.2.26

  • Rails 6.1.1 + Ruby 2.7.2 + Vue.js 3.2.26

  • Rails 6.0.3.4 + Ruby 2.6.6 + Vue.js 3.2.26

  • Rails 5.2.4.4 + Ruby 2.6.6 + Vue.js 3.2.26

Rails versions below 5.2 are not supported.

Vue.js 2.x is supported when using the Compat build of Vue.js

Documentation/Installation

Detailed documentation can be found here

Feature walk-through

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

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

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

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

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

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

3. 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

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