Skip to content
Secure Markup
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Cerubis Test Status

Cerubis is inspired by Liquid Markup and Mustache. I like how Mustache syntax looks, but it's logic-less. Liquid allows just enough logic, but I don't like the syntax. And so Cerubis was born.


A block is started with {{# ... }} and closed with {{/ ... }}. Output is defined as {{ ... }}.

  <h1>{{ page.title }}</h1>
  {{#unless navigation.empty?}}
    {{#loop nav in navigation}}
    <li>{{ link_to page }}</li>

Standard Blocks

  • if
  • unless
  • loop

Objects in Template Context

Rendering a Cerubis template with objects in the context is easy:

template_str = <<-STR
  {{#if items.empty?}}
    <p>There are no items!</p>

context = { items: [1,2,3] }

Cerubis.render(template_str, context)

You can create your own objects and add them to template context, but you need to make Cerubis aware of the methods it's allowed to call:

class Foo
  include Cerubis::Method
  cerubis_method :foo, :bar, :baz

  def foo; "Foo Method"; end
  def bar; "Bar Method"; end
  def baz; "Baz Method"; end

template_str = "<some-template-text>"
context      = { foo: }

Cerubis.render(template_str, context)

Shown above, object methods are made available to Cerubis templates by indicating them with cerubis_method. The cerubis_method can have many method names passed to it and cerubis_method can be called multiple times.

Template Helpers

Template helpers are meant to add convienence methods to your code. Below you see how simple it is to add a helper and to use it in your template:

# Adding a new helper
module FooHelper
  def foo_helper(name, value)
    "My name is #{name} and my value is #{value}"

Cerubis.register_helper :foo_helper, FooHelper

# Using the helper
content = <<-STR
  Hello {{ foo_helper 'John Doe', '12' }}

template = Cerubis.render(content)


You can run the tests in a few different ways. First, you've got your standard ruby way:

ruby -Ilib:test test/cerubis_test.rb
ruby -Ilib:test test/all.rb

Or you can run them all with Rake:

rake test

Code Coverage

The cover_me gem has been added to the project. If you'd like to see the current coverage just run thor test:coverage.

Something went wrong with that request. Please try again.