{"id":13482916,"url":"https://github.com/c910335/crinder","last_synced_at":"2025-03-27T13:33:05.448Z","repository":{"id":51201911,"uuid":"119375136","full_name":"c910335/crinder","owner":"c910335","description":"Class based json renderer in Crystal","archived":false,"fork":false,"pushed_at":"2021-05-20T08:30:31.000Z","size":72,"stargazers_count":28,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T16:41:25.130Z","etag":null,"topics":["crystal","json"],"latest_commit_sha":null,"homepage":"https://c910335.github.io/crinder/","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c910335.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-29T11:42:03.000Z","updated_at":"2022-04-30T13:11:58.000Z","dependencies_parsed_at":"2022-09-22T23:12:05.807Z","dependency_job_id":null,"html_url":"https://github.com/c910335/crinder","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c910335%2Fcrinder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c910335%2Fcrinder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c910335%2Fcrinder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c910335%2Fcrinder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c910335","download_url":"https://codeload.github.com/c910335/crinder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245854741,"owners_count":20683408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","json"],"created_at":"2024-07-31T17:01:06.691Z","updated_at":"2025-03-27T13:33:05.152Z","avatar_url":"https://github.com/c910335.png","language":"Crystal","readme":"# Crinder\n\n[![Crystal CI](https://github.com/c910335/crinder/actions/workflows/crystal.yml/badge.svg)](https://github.com/c910335/crinder/actions/workflows/crystal.yml)\n[![GitHub releases](https://img.shields.io/github/release/c910335/crinder.svg)](https://github.com/c910335/crinder/releases)\n[![GitHub license](https://img.shields.io/github/license/c910335/crinder.svg)](https://github.com/c910335/crinder/blob/master/LICENSE)\n\nClass based json renderer in Crystal\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  crinder:\n    github: c910335/crinder\n```\n\n## Usage\n\n### Basic\n\n```crystal\nrequire \"crinder\"\n\nrecord Todo, name : String, priority : Int32, expires_at : Time?, created_at : Time?, updated_at : Time?\n\nclass TodoRenderer \u003c Crinder::Base(Todo)\n  field name : String, as: title\n  field priority : Int, value: -\u003e{ priority * 10 }\n  field expires_at : String, as: deadline, unless: -\u003e{ priority \u003c 3 }\n  field created_at : String, if: -\u003e{ created_at? }\n  field updated : Bool, value: updated?\n\n  option created_at? : Bool = false\n\n  def self.updated?\n    !object.updated_at.nil?\n  end\nend\n\ntime = Time.utc(2018, 3, 14, 19, 55, 7)\ntodo = Todo.new(\"qaq\", 8, time + 20.hours, time, nil)\n\nTodoRenderer.render(todo, created_at?: true) # =\u003e \"{\\\"title\\\":\\\"qaq\\\",\\\"priority\\\":80,\\\"deadline\\\":\\\"2018-03-15 15:55:07 UTC\\\",\\\"created_at\\\":\\\"2018-03-14 19:55:07 UTC\\\",\\\"updated\\\":false}\"\n```\n\n### Inheritance\n\n```crystal\nclass AnotherTodoRenderer \u003c TodoRenderer\n  field expires_at : String, unless: -\u003e{ priority \u003c 1 }\n  field updated_at : String\n  remove updated\nend\n\ntodo = Todo.new(\"wow\", 6, time + 20.hours, time, time + 10.hours)\n\nAnotherTodoRenderer.render(todo) # =\u003e \"{\\\"title\\\":\\\"wow\\\",\\\"priority\\\":60,\\\"expires_at\\\":\\\"2018-03-15 15:55:07 UTC\\\",\\\"updated_at\\\":\\\"2018-03-15 05:55:07 UTC\\\"}\"\n```\n\n### Array\n\n```crystal\ntodos = [Todo.new(\"www\", 8, time + 20.hours, time, nil), Todo.new(\"api\", 10, time + 21.hours, time, nil)]\n\nTodoRenderer.render(todos) # =\u003e \"[{\\\"title\\\":\\\"www\\\",\\\"priority\\\":80,\\\"deadline\\\":\\\"2018-03-15 15:55:07 UTC\\\",\\\"updated\\\":false},{\\\"title\\\":\\\"api\\\",\\\"priority\\\":100,\\\"deadline\\\":\\\"2018-03-15 16:55:07 UTC\\\",\\\"updated\\\":false}]\"\n```\n\n### Nested\n\n```crystal\nclass TimeRenderer \u003c Crinder::Base(Time?)\n  field year : Int\n  field month : Int\n  field day : Int\n  field hour : Int\n  field minute : Int\n  field second : Int\nend\n\nclass NestedTodoRenderer \u003c TodoRenderer\n  remove expires_at\n  remove updated\n  field created_at, with: TimeRenderer\nend\n\ntodo = Todo.new(\"wtf\", 3, time + 20.hours, time, nil)\n\nNestedTodoRenderer.render(todo) # =\u003e \"{\\\"title\\\":\\\"wtf\\\",\\\"priority\\\":30,\\\"created_at\\\":{\\\"year\\\":2018,\\\"month\\\":3,\\\"day\\\":14,\\\"hour\\\":19,\\\"minute\\\":55,\\\"second\\\":7}}\"\n```\n\n### Nilable\n\n```crystal\nclass NilableTodoRenderer \u003c TodoRenderer\n  field expires_at : String?\n  field created_at : String?\n  field updated_at : String?\n  remove updated\nend\n\ntodo = Todo.new(\"IDK\", 10, nil, nil, nil)\n\nNilableTodoRenderer.render(todo) # =\u003e \"{\\\"title\\\":\\\"IDK\\\",\\\"priority\\\":100,\\\"expires_at\\\":null,\\\"created_at\\\":null,\\\"updated_at\\\":null}\"\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/c910335/crinder/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [c910335](https://github.com/c910335) Tatsiujin Chin - creator, maintainer\n","funding_links":[],"categories":["Data Formats"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc910335%2Fcrinder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc910335%2Fcrinder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc910335%2Fcrinder/lists"}