Project

render_kit

0.0
The project is in a healthy, maintained state
A small library to allow claases to be rendered oike partials in Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

RenderKit

RenderKit is a small library to that extends rails renderable classes functionality by:

  • Allowing renderables to be called by a string identifier, i.e. `render "my_renderable"
  • Allowing renderables to be used in place of views with matching controller actions

This project is best used alongside a component library like ViewComponent or Phlex

Installation

Add this line to your application's Gemfile:

gem 'render_kit'

And then execute:

$ bundle install

Usage

Rendering like partials

Defining a renderable

To begin you first need a (Rails renderable class)[rails/rails#36388]

class MyRenderable
  def render_in(_)
    "Hello World"
  end
end

Registering a renderable

You can register a renderable by calling ActionView::Base.register_renderable with a string identifier and the renderable class

class MyRenderable
  ActionView::Base.register_renderable("my_renderable", self)

  def render_in(_)
    "Hello World"
  end
end
<%= render "my_renderable" %> # => "Hello World"

Using renderables in place of views

Defining a controller action

class MyController < ApplicationController
  def index
    render MyRenderable.new
  end
end

Defining a renderable

class MyRenderable
  ActionView::Base.register_renderable("my_controller_index", self)

  def render_in(_)
    "Hello World"
  end
end

This will render the renderable in place of the view for the index action in MyController

Development

After checking out the repo, run bin/setup to install dependencies.The tests use Appraisal to run multiple rails versions(7.0, 7.1, 7.2), i.e for rails 7.2 run bundle exec appraisal rails-7.1 rake test

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Code of Conduct

Everyone interacting in the RenderKit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct to ensure fait treatment of everyone, remember MINASWAN.