Skip to content

Add render with options #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2020
Merged

Add render with options #11

merged 2 commits into from
Apr 20, 2020

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