From 961a218c05f458a7e6b1a99b4c5aba54f407747c Mon Sep 17 00:00:00 2001 From: Marvin Ahlgrimm Date: Wed, 20 Mar 2024 16:33:13 +0100 Subject: [PATCH] Update README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 406faf2..6d0fe9a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,26 @@ [![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) [![QA](https://github.com/treagod/marten-turbo/actions/workflows/qa.yml/badge.svg)](https://github.com/treagod/marten-turbo/actions/workflows/qa.yml) +## Installation + +Simply add the following entry to your project's `shard.yml`: + +```yaml +dependencies: + marten_turbo: + github: treagod/marten-turbo +``` + +And run `shards install` afterward. + +First, add the following requirement to your project's `src/project.cr` file: + +```crystal +require "marten_turbo" +``` + +Afterwards you can use the template helper `dom_id` and the turbo handlers. + ## Tags Marten Turbo introduces a new template tag `dom_id`, which supports the creation of turbo frame ids for Marten models @@ -30,6 +50,8 @@ Identifier will respect your namespace of the model. I.e. if you have an Article Marten Turbo provides an extension to the generic Marten handlers. For example to create a record the `MartenTurbo::Handlers::RecordCreate` is used: +__Record Creation__: To create a record, use + ```crystal class ArticleCreateHandler < MartenTurbo::Handlers::RecordCreate model Article @@ -43,3 +65,26 @@ end Notice how we use `MartenTurbo::Handlers::RecordCreate` instead of `Marten::Handlers::RecordCreate`. Also the `#turbo_stream_name` class method gives you the option to define a turbo stream template which is rendered instead of the normal template if a turbo request is made. + +__Record Update__: To update a record, use + +```crystal +class ArticleCreateHandler < MartenTurbo::Handlers::RecordUpdate + model Article + schema ArticleSchema + template_name "articles/update.html" + turbo_stream_name "articles/update.turbo_stream.html" + success_route_name "articles" +end +``` + +__Record Deletion__: To delete a record, use + +```crystal +class ArticleCreateHandler < MartenTurbo::Handlers::RecordUpdate + model Article + template_name "articles/delete.html" + turbo_stream_name "articles/delete.turbo_stream.html" + success_route_name "articles" +end +```