{"id":15713505,"url":"https://github.com/treagod/marten-turbo","last_synced_at":"2025-05-07T08:42:43.288Z","repository":{"id":228809799,"uuid":"770721962","full_name":"treagod/marten-turbo","owner":"treagod","description":"Enhance your Marten app with dynamic updates using Turbo Frames!","archived":false,"fork":false,"pushed_at":"2025-04-13T03:51:49.000Z","size":751,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T04:33:31.804Z","etag":null,"topics":["crystal","frontend","hotwire-turbo","marten","web"],"latest_commit_sha":null,"homepage":"https://treagod.github.io/marten-turbo/","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/treagod.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-12T03:22:29.000Z","updated_at":"2025-04-13T03:51:52.000Z","dependencies_parsed_at":"2024-03-25T12:58:53.739Z","dependency_job_id":"c4a5bd70-a5e2-4786-b492-cf628e9f74f6","html_url":"https://github.com/treagod/marten-turbo","commit_stats":null,"previous_names":["treagod/marten-turbo"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treagod%2Fmarten-turbo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treagod%2Fmarten-turbo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treagod%2Fmarten-turbo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treagod%2Fmarten-turbo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treagod","download_url":"https://codeload.github.com/treagod/marten-turbo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252845591,"owners_count":21813279,"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","frontend","hotwire-turbo","marten","web"],"created_at":"2024-10-03T21:31:50.548Z","updated_at":"2025-05-07T08:42:43.268Z","avatar_url":"https://github.com/treagod.png","language":"Crystal","funding_links":[],"categories":["Marten shards"],"sub_categories":["Front-end Integration"],"readme":"\u003ch1\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/treagod/marten-turbo/e317fa4c759ebb61a335d22872a39caf39cfe5cc/docs/_media/logo.svg\" height=\"32\" width=\"32\" alt=\"Marten Turbo Logo\"\u003e\n  \u003cspan\u003eMarten Turbo\u003c/span\u003e\n\u003c/h1\u003e\n\n[![GitHub Release](https://img.shields.io/github/v/release/treagod/marten-turbo?style=flat)](https://github.com/treagod/marten-turbo/releases)\n[![Marten Turbo Specs](https://github.com/treagod/marten-turbo/actions/workflows/specs.yml/badge.svg)](https://github.com/treagod/marten-turbo/actions/workflows/specs.yml)\n[![QA](https://github.com/treagod/marten-turbo/actions/workflows/qa.yml/badge.svg)](https://github.com/treagod/marten-turbo/actions/workflows/qa.yml)\n\nMarten Turbo provides helpers to interact with Turbo applications using the \u003ca href=\"https://martenframework.com/\"\u003eMarten Framework\u003c/a\u003e.\n\n## Installation\n\nSimply add the following entry to your project's `shard.yml`:\n\n```yaml\ndependencies:\n  marten_turbo:\n    github: treagod/marten-turbo\n```\n\nAnd run `shards install` afterward.\n\nFirst, add the following requirement to your project's `src/project.cr` file:\n\n```crystal\nrequire \"marten_turbo\"\n```\n\nAfterwards you can use the template helper `dom_id` and the turbo handlers.\n\n## Tags\n\nMarten Turbo introduces a new template tag `dom_id`, which supports the creation of turbo frame ids for Marten models\n\n```html\n{% for article in articles %}\n  \u003cdiv id=\"{% dom_id article %}\"\u003e \u003c!-- Generates id artcle_1, artcle_2, etc. --\u003e\n    \u003c!-- some content--\u003e\n  \u003c/div\u003e\n{% endfor %}\n\n\u003cform id=\"{% dom_id article %}\" method=\"POST\" action=\"/articles\"\u003e\n  \u003c!-- Assuming the article instance is new an id of new_article is generated --\u003e\n  \u003c!-- Otherwise the id will be for example article_1 --\u003e\n\u003c/form\u003e\n```\n\nIdentifier will respect your namespace of the model. I.e. if you have an Article model in the app blogging the generated id will be `blogging_article_1`.\n\nMarten Turbo also provides a turbo stream tag helper\n\n```html\n{% turbo_stream 'append' \"articles\" do %}\n  \u003cdiv class=\"{% dom_id article %}\"\u003e\n    {{ article.name }}\n  \u003c/div\u003e\n{% end_turbo_stream %}\n\n\u003c!--\n  \u003cturbo-stream action=\"append\" target=\"articles\"\u003e\n    \u003ctemplate\u003e\n      \u003cdiv class=\"article_1\"\u003e\n        My First Article\n      \u003c/div\u003e\n    \u003c/template\u003e\n  \u003c/turbo-stream\u003e\n--\u003e\n\n\u003c!-- or in one line --\u003e\n{% turbo_stream 'append' \"articles\" template: \"articles/article.html\" %}\n\u003c!--\n  \u003cturbo-stream action=\"append\" target=\"articles\"\u003e\n    \u003ctemplate\u003e\n      content of \"articles/article.html\"\n    \u003c/template\u003e\n  \u003c/turbo-stream\u003e\n--\u003e\n\n\u003c!-- dom_id is automatically applied if targeting a record --\u003e\n{% turbo_stream 'remove' article %}\n\u003c!--\n  \u003cturbo-stream action=\"remove\" target=\"article_1\"\u003e\n  \u003c/turbo-stream\u003e\n--\u003e\n```\n\n\n## Handlers\n\nMarten Turbo provides an extension to the generic Marten handlers:\n\n__Record Creation__: To create a record, use\n\n```crystal\nclass ArticleCreateHandler \u003c MartenTurbo::Handlers::RecordCreate\n  model Article\n  schema ArticleSchema\n  template_name \"articles/create.html\"\n  turbo_stream_name \"articles/create.turbo_stream.html\"\n  success_route_name \"articles\"\nend\n```\n\nNotice how we use `MartenTurbo::Handlers::RecordCreate` instead of `Marten::Handlers::RecordCreate`.\nAlso the `#turbo_stream_name` class method gives you the option to define a turbo stream template which is\nrendered instead of the normal template if a turbo request is made.\n\n__Record Update__: To update a record, use\n\n```crystal\nclass ArticleUpdateHandler \u003c MartenTurbo::Handlers::RecordUpdate\n  model Article\n  schema ArticleSchema\n  template_name \"articles/update.html\"\n  turbo_stream_name \"articles/update.turbo_stream.html\"\n  success_route_name \"articles\"\nend\n```\n\n__Record Deletion__: It's also possible to define a `turbo_stream` method\n\n```crystal\nclass ArticleDeleteHandler \u003c MartenTurbo::Handlers::RecordDelete\n  model Article\n  template_name \"articles/delete.html\"\n  success_route_name \"articles\"\n\n  def turbo_stream\n    MartenTurbo::TurboStream.remove(record)\n  end\nend\n```\n\n## Turbo Native\n\nMarten Turbo lets you check if a request is from a Turbo Native Application. To check, just check the `request.turbo_native_app?` variable.\n\nA context producer also adds the `turbo_native?` variable to your templates to adjust your HTML. For the context producer you have to insert `MartenTurbo::Template::ContextProducer::TurboNative` \u003ca href=\"https://martenframework.com/docs/templates/introduction#using-context-producers\" target=\"_blank\" rel=\"noopener noreferrer\"\u003einto your context producer array\u003c/a\u003e.\n\nYou could add a custom class to your body if a turbo native app hits your application:\n\n```html\n\u003cbody {% if turbo_native? %}class=\"turbo-native\"{% endif %}\u003e\n  …\n\u003c/body\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreagod%2Fmarten-turbo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreagod%2Fmarten-turbo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreagod%2Fmarten-turbo/lists"}