Module: Roy::Render

Defined in:
lib/roy/render.rb

Overview

A simple template rendering mechanism based on Tilt.

Configuration:

roy.conf.render

A hash of options to pass to Tilt.

roy.conf.views

The directory where views are kept. Defaults to views/

Examples:

Using roy.render


class ErbApp
  include Roy

  roy use: [:render]

  def get(path)
    case path
    when /\/hello/
      roy.render :erb, "Hello, <%= roy.params[:p] || \"world\" %>!\n"
    else
      roy.render :erb, :index
    end
  end
end

Test


$ cat views/index.erb
Let me <a href="/hello">greet</a> you.
$ curl -i localhost:9292
Let me <a href="/hello">greet</a> you.
$ curl -i localhost:9292/hello?p=blah
Hello, blah!

Haml renderer with partials support


module HamlRenderWithPartial
  def self.setup(roy)
    roy.send(:extend, InstanceMethods)
  end

  module InstanceMethods
    def render(tpl_or_string, params={})
      case layout = params.delete(:layout)
      when false
        super(:haml, tpl_or_string, params)
      else
        super(:haml, :layout, params do
          super(:haml, tpl_or_string, params)
        end
      end
    end
  end
end

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.setup(roy) ⇒ Object



60
61
62
# File 'lib/roy/render.rb', line 60

def self.setup(roy)
  roy.send(:extend, InstanceMethods)
end