Class: Himg::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/himg/railtie.rb,
lib/himg/railtie/template_handler.rb,
lib/himg/railtie/controller_config.rb

Overview

Himg::Railtie

Allows you to render Png images directly from rails using HTML based templates.

View templates can be registered with .himg and will be converted from HTML to an image, or with .himg.erb to insert dynamic content. A renderer also allows direct rendering of HTML without going through a template.

Example usage:

  • show.himg.erb renders an image based on controller data.
  • render himg: '<div>My Data</div>' generates an image from HTML.

This works by registering a template handler, which will be called by Rails' default_render method when a view template exists matching the current action in a request where the format extension is .himg or a png is requested.

The direct render works similarly, but instead of checking the request format it looks for the :himg key passed into a Rails render function.

Defined Under Namespace

Modules: ControllerConfig Classes: ErbTemplateHandler, TemplateHandler