{"id":15651572,"url":"https://github.com/boxed/elm-cog","last_synced_at":"2025-07-09T03:03:19.408Z","repository":{"id":56667905,"uuid":"97264643","full_name":"boxed/elm-cog","owner":"boxed","description":"Code generation for Elm, using Ned Batchelder's Cog","archived":false,"fork":false,"pushed_at":"2020-10-26T10:27:27.000Z","size":25,"stargazers_count":32,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T20:02:27.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/boxed.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":"2017-07-14T19:01:03.000Z","updated_at":"2024-02-08T19:55:27.000Z","dependencies_parsed_at":"2022-08-15T23:00:27.182Z","dependency_job_id":null,"html_url":"https://github.com/boxed/elm-cog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxed%2Felm-cog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxed%2Felm-cog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxed%2Felm-cog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxed%2Felm-cog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boxed","download_url":"https://codeload.github.com/boxed/elm-cog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251774894,"owners_count":21641731,"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":[],"created_at":"2024-10-03T12:39:08.979Z","updated_at":"2025-04-30T20:04:58.059Z","avatar_url":"https://github.com/boxed.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elm-cog\n\nCode generation for Elm, using Ned Batchelder's Cog. This is useful for two main scenarios:\n\n- keeping data from your python server side code in sync with the Elm side\n- enhancing Elm in certain areas where you might otherwise end up with error prone copy paste mess\n\nFeatures:\n\n- Lists\n  - Example: (`list_of('a, b, c')` or `list_of('a', 'b', 'c')`)\n- Union types\n  - Example: (`union('A, B, C')`)\n- Enums (A union type + a list that are always in sync)\n  - Example: (`enum('A, B, C')`)\n- Type alias\n  - Example: (`type_alias('FooBar', type_info=dict(a=int, b=float, c=str))`\n- Record\n  - Example: (`record('foo', dict(a=1, b=1.5, c=\"bar\"))`)\n- Enhanced enums: an enum with an associated Dict for extra data\n  - Example: (`enhanced_enum('FooBar', dict(A=dict(some_data1=1, some_data2=1.5, display_name=\"3\"), B=dict(some_data1=2, some_data2=2.5, display_name=\"4\"),)`)\n- Record alias with generated encoders and decoders (like `enhanced_enum` but you call `type_alias_with_json`)\n\n\n## Usage\n\n1. Install my fork of Cog:\n\n```shell\nhg clone https://bitbucket.org/boxed/cog\ncd cog\npython3 setup.py install\n```\n\n(I have sent a pull request for the feature I need, hopefully you can at some point use standard Cog)\n\n 2. From the elm-cog repo, copy https://raw.githubusercontent.com/boxed/elm-cog/master/elm.py and https://raw.githubusercontent.com/boxed/elm-cog/master/elm-cog to your source tree.  \n\n3. Run `elm-cog` to do the actual code generation.\n\nI know it's a bit clunky right now, but this tool is still in a prototype stage. Let me know if you find it useful!\n\n## Full example of code generation\n\nYou write this in your elm code:\n\n```elm\n-- [[[cog type_alias_with_json('Foobar2', type_info=dict(a=int, b=str, c='CustomType')) ]]]\n-- [[[end]]]\n```\n\nthen run `elm-cog` and it will update your file in place to replace the above with:\n\n```elm\n-- [[[cog type_alias_with_json('Foobar2', type_info=dict(a=int, b=str, c='CustomType')) ]]]\n\n\ntype alias Foobar2 =\n    { a : Int\n    , b : String\n    , c : CustomType\n    }\n\n\nfoobar2Decoder : Json.Decode.Decoder Foobar2\nfoobar2Decoder =\n    Json.Decode.Pipeline.decode Foobar2\n        |\u003e Json.Decode.Pipeline.required \"a\" Json.Decode.int\n        |\u003e Json.Decode.Pipeline.required \"b\" Json.Decode.string\n        |\u003e Json.Decode.Pipeline.required \"c\" customTypeDecoder\n\n\nfoobar2Encoder : Foobar2 -\u003e Json.Encode.Value\nfoobar2Encoder record =\n    Json.Encode.object\n        [ ( \"a\", Json.Encode.int record.a )\n        , ( \"b\", Json.Encode.string record.b )\n        , ( \"c\", customTypeEncoder record.c )\n        ]\n\n\n\n-- [[[end]]]\n\n```\n\nThe output will be formatted according to `elm-format` already, so no need to run it after.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxed%2Felm-cog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboxed%2Felm-cog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxed%2Felm-cog/lists"}