Skip to content

Add render with options#11

Merged
c910335 merged 2 commits intomasterfrom
add-render-with-options
Apr 20, 2020
Merged

Add render with options#11
c910335 merged 2 commits intomasterfrom
add-render-with-options

Conversation

@c910335
Copy link
Owner

@c910335 c910335 commented Apr 20, 2020

Example:

record Article, title : String, content : String, date : Time

class TimeRenderer < Crinder::Base(Time)
  field year : Int
  field month : Int
  field day : Int
  field hour : Int, unless: date_only?
  field minute : Int, unless: date_only?
  field second : Int, unless: date_only?

  option date_only? : Bool = false
end

class ArticleRenderer < Crinder::Base(Article)
  field title : String
  field content : String
  field date, with: TimeRenderer, options: {date_only?: true}
end

article = Article.new(title: "Add render with options", content: "You can pass options to the nested renderer.", date: Time.local(2020, 4, 20))
ArticleRenderer.render(article) # => "{\"title\":\"Add render with options\",\"content\":\"You can pass options to the nested renderer.\",\"date\":{\"year\":2020,\"month\":4,\"day\":20}}"

@c910335 c910335 added the enhancement New feature or request label Apr 20, 2020
@c910335 c910335 merged commit 0870b34 into master Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant