class Crinder::Base(T)

Overview

Crinder::Base is the base renderer of type T.

To define your own renderer, you need to inherit Crinder::Base with specific type and declare the fields with Crinder::Field.field.

For example, this is a renderer of Time.

class TimeRenderer < Crinder::Base(Time)
  field year : Int
  field month : Int
  field day : Int
  field hour : Int
  field minute : Int
  field second : Int
end

Then .render will be auto generated.

time = Time.new(2018, 3, 15, 16, 21, 1)
TimeRenderer.render(time) # => "{\"year\":2018,\"month\":3,\"day\":15,\"hour\":16,\"minute\":21,\"second\":1}"

Included Modules

Defined in:

crinder.cr

Class Method Summary

Class Method Detail

def self.object #

the getter of the object to be rendered, which can be used in value, if or unless


[View source]