{"id":18006715,"url":"https://github.com/bryanx/cakecutter","last_synced_at":"2025-03-26T12:31:00.421Z","repository":{"id":57737980,"uuid":"249777901","full_name":"Bryanx/cakecutter","owner":"Bryanx","description":"🍰 A tiny android annotation library for injecting styled attributes into custom views.","archived":false,"fork":false,"pushed_at":"2020-07-06T12:27:52.000Z","size":121,"stargazers_count":45,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-07-05T15:44:03.086Z","etag":null,"topics":["android","android-annotation-library","android-annotation-processor","android-annotations","android-library","kotlin","kotlin-android","kotlin-library"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bryanx.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":"2020-03-24T17:47:59.000Z","updated_at":"2023-04-07T10:51:47.000Z","dependencies_parsed_at":"2022-08-24T14:42:27.629Z","dependency_job_id":null,"html_url":"https://github.com/Bryanx/cakecutter","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bryanx%2Fcakecutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bryanx%2Fcakecutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bryanx%2Fcakecutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bryanx%2Fcakecutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bryanx","download_url":"https://codeload.github.com/Bryanx/cakecutter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222144913,"owners_count":16938458,"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":["android","android-annotation-library","android-annotation-processor","android-annotations","android-library","kotlin","kotlin-android","kotlin-library"],"created_at":"2024-10-30T01:09:40.627Z","updated_at":"2024-10-30T01:09:41.268Z","avatar_url":"https://github.com/Bryanx.png","language":"Kotlin","readme":"# 🍰 CakeCutter\nA tiny annotation library for injecting styled attributes into custom views.\n\n## Example\nTraditional way of loading styled attributes:\n```kotlin\nclass CustomView(ctx: Context, attrs: AttributeSet) : FrameLayout(ctx, attrs) {\n    var customText: String = \"\"\n    var customNumber: Int = 0\n    var customSize: Float = 0F\n\n    init {\n        val styledAttrs = ctx.obtainStyledAttributes(attrs, R.styleable.CustomView)\n        try {\n            customText = styledAttrs.getString(R.styleable.CustomView_customText) ?: customText\n            customNumber = styledAttrs.getInt(R.styleable.CustomView_customNumber, customNumber)\n            customSize = styledAttrs.getDimension(R.styleable.CustomView_customSize, customSize)\n        } finally {\n            styledAttrs.recycle()\n        }\n    }\n}\n```\n\nWith cakecutter:\n```kotlin\nclass CustomView(ctx: Context, internal val attrs: AttributeSet) : FrameLayout(ctx, attrs) {\n    @Styleable var customText: String = \"\"\n    @Styleable var customNumber: Float = 0F\n    @Styleable var customSize: Int = 0\n\n    init {\n        CakeCutter.bind(this)\n    }\n}\n```\nThe styleables are bound by property name.\n\nSome advantages:\n* Default values are assigned once instead of twice.\n* Layout/programmatic setters are combined.\n* Less boilerplate.\n\nAlternative annotation:\n```kotlin\n@BindStyleable(\"customText\") var otherTextName: String = \"\"\n```\nWith this annotation the props can have different names than the styleables.\n\n\n## Generated code\nIt works similarly to [Dagger](https://github.com/google/dagger) and [ButterKnife](https://github.com/JakeWharton/butterknife), here is the generated code for above example:\n```kotlin\nfun bind(view: CustomView) {\n  view.context.obtainStyledAttributes(view.attrs, R.styleable.CustomView)\n    .apply {\n      try {\n        view.customText = getBoolean(6, view.customText)\n        view.customNumber = getString(R.styleable.CustomView_customNumber) ?: view.customNumber\n        view.customSize = getDimension(R.styleable.CustomView_customSize, view.customSize)\n      } finally {\n        recycle()\n      }\n  }\n}\n```\n## Install\nAdd these dependencies in your app's `build.gradle` file:\n```groovy\nimplementation 'nl.bryanderidder.cakecutter:annotations:0.2.1'\nkapt 'nl.bryanderidder.cakecutter:compiler:0.2.1'\n```\nUse `annotationProcessor` instead of `kapt` for Java projects. \\\nFor kotlin projects add this to the top of your `build.gradle` file if it's not added yet:\n```groov\napply plugin: \"kotlin-kapt\"\n```\nAfter adding the annotations you have to rebuild the project to load the generated code.\n\n## Note\nThis project is more of an expirement/study on annotation libraries and [ButterKnife](https://github.com/JakeWharton/butterknife).\n\nAt the moment this library does not support these custom attribute types:\n* Fraction types\n* Multi types\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\nThe cake is now ready to be served.\n\n🍰\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryanx%2Fcakecutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbryanx%2Fcakecutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryanx%2Fcakecutter/lists"}