Do you wish you could write a modern user interface in Ruby?
Now you can. Presenters are a Ruby DSL for rendering user interfaces.
- Presenters are a power washer for building user interfaces
- Presenters are to HTML/User Interfaces what C is to assembly
- A presenter generates a Presenter Object Model (POM)
- A POM fully describes a user interface
- A POM client can fully render user interface from POM
The semantics are adopted from Material Design.
Building a user interface should like Ruby itself:
... a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
Instead building a user interface has turned into:
How many languages/technologies/frameworks do I need to learn to build a rich user interface/experience?"
A typical web client requires at a minimum the following: HTML, CSS, Javascript, in addition we need Ruby on the server, plus some SQL.
That is 5 technologies/languages.
Now lets talk about a new client like an iOS or Android client. If we go native, we can now add Java and Swift to that list. We are up to 7 technologies/languages!
We didn't even add any popular extras like coffeescript, haml, sass, and we left out frameworks.
What if you could write all your user interface in Ruby and have it rendered natively in ANY client? The COPRL enable that. It is a Ruby DSL that describes a user interface. It generates an intermediate Presenter Object Model (POM). The POM is a declarative user interface that can be rendered by a POM client. The presenters gem provides a web client as a fully functional implementation that both renders natively as a Rails templating engine and as a Rack app.
This concept was initially inspired by the Presenters concepts of Ivar Jacobson as presented by Robert Martin.
Or to run locally:
git clone git@github.com:rx/presenters.git
cd presenters/
bundle install
bundle exec rackup
open http://localhost:9292
Note: Demo defaults to Ruby version 2.7.3 in the .ruby-version file. If you want to run a different version -- set RBENV_VERSION to your desired version. For example:
RBENV_VERSION=2.5.5 bundle insatall RBENV_VERSION=2.5.5 bundle exec rackup```
To see the POM:
open http://localhost:9292/index.pom
Presenters are a view templating language in Rails. You can mix and match presenters with your existing views, use them as new views, or call them as partials in existing views.
gem 'coprl'
require 'coprl'
mount Coprl::Presenters::Rails::Engine => "/"
Coprl::Presenters.define(:hello_world) do
heading 'hello world'
end
Navigate to locahost:3000/hello_world
Use the Demo to get example code to drop into your presenters.
If you name a presenter :index and want the root of the app to serve up that presenter add the following to your config/initializers/routes.rb
root 'coprl#show'
You can render a presenter as a partial from other templating laguages (erb, haml):
<%= render 'show', presenter: 'hello_world' %>
You need to add the following to your layout to use presenters as a partial alongside other erb's, haml or any other rails templating language.
<title><%= @pom.page.title if @pom.page %></title>
<%= coprl_headers %>
<%= with_presenters_wrapper do %>
<%= yield %>
<%= end %>
gem 'coprl'
Coprl::Presenters.define(:hello_world) do
heading 'hello world'
end
Presenters are rack based. If your framework uses a rack config file add the following:
use Coprl::Presenters::WebClient::App
# the api is optional
# use Coprl::Presenters::Api::App
Start your app and goto /hello_world
Use the Demo to get example code to drop into your presenters.
This project is in a released status.
Bug reports and pull requests are welcome on GitHub at https://github.com/rx/presenters.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the COPRL project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.