0.0
No commit activity in last 3 years
No release in over 3 years
Mote plugin for Cuba.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
 Project Readme

mote-render

Mote plugin for Cuba. This plugin was extracted from the cuba-contrib gem, made by cyx.

Usage

To use Mote in Cuba, you need to load the Mote::Render plugin as shown below:

require "mote"
require "mote/render"

Cuba.plugin(Mote::Render)

Mote::Render provides three helper methods for rendering templates: partial, view and render.

Cuba.define do
  on "about" do
    # `partial` renders a template without a layout.
    res.write partial("about")
  end

  on "home" do
    # `view` renders a template within a layout.
    res.write view("about")
  end

  on "contact" do
    # `render` is a shortcut to `res.write view(...)`
    render("contact")
  end
end

By default, Mote::Render assumes that all view templates are placed in a folder named views and that they use the .mote extension. Also for view and render methods, it assumes that the layout template is called layout.mote.

The defaults can be changed through the Cuba.settings method:

Cuba.settings[:mote][:views] = "./views/admin/"
Cuba.settings[:mote][:layout] = "admin"

Layouts

To render inner content into a layout, use the {{ content }} tag.

<html>
  <head>
    <title>Mote Layout</title>
  </head>
  <body>
    <h1>Hello, mote!</h1>
    {{ content }}
  </body>
</html>

Passing values

You can easily pass variables to your templates:

Cuba.define do
  on "home" do
    render("welcome", {username: "John Doe", day: "Monday"})
  end
end

And in the template file:

  <!-- welcome.mote -->
  <h1>Hello, {{username}}!</h1>
  <p>How are things going on this beautiful {{day}}?</p>

Helpers

You can use the app variable to access the application helpers.

Cuba.define do
  def h(unsafe)
    ...
  end
end
<h1>{{ app.h("unsafe") }}</h1>

{{ app.partial("list") }}

Installation

$ gem install mote-render