Jets Custom Upcase Renderer

Important: These docs are for the outdated Jets 5 versions and below. For the latest Jets docs: docs.rubyonjets.com

Here’s a cheatsheet for the simplest custom renderer ever that simply does an upcase.

Setup Template Handler

To add a custom render, you can register new template handlers. This is typcially done in the initializer.

config/initializers/renderers.rb

class UppercaseRenderer
  def self.call(template, source = nil)
    source ||= template.source
    source.upcase.inspect
  end
end

ActionView::Template.register_template_handler(:upcase, UppercaseRenderer)

Use in View

app/views/examples/index.html.upcase

This text will be rendered in upcase.

Controller

app/controllers/examples_controller.rb

class ExamplesController < ApplicationController
  def index
  end
end

Routes

config/routes.rb

Jets.application.routes.draw do
  get "/examples", to: "examples#index"
end