# Snippets

> Small, tested code to copy, for Rust off Rails 0.7.3: read one with `cargo offrails snippet show <name>`, copy and wire it with `snippet add`, take it back with `snippet remove`.

## atom-feed

GET /feed.xml: an Atom feed (escaped, RFC 3339 dates, newest 20), linked from every page

- Needs: nothing
- Files: `src/controllers/feed.rs`, `src/routes/feed.rs`, `src/views/feed.rs`, `templates/feed/atom.xml`, `tests/app/feed_test.rs`
- Commands: `cargo offrails snippet show atom-feed`, `cargo offrails snippet add atom-feed`, `cargo offrails snippet remove atom-feed`
- README: https://rustoffrails.org/snippets/atom-feed.md

## markdown

markdown::to_html: CommonMark (tables, strikethrough) rendered by pulldown-cmark, sanitized by ammonia

- Needs: crates pulldown-cmark and ammonia
- Files: `src/views/markdown.rs`
- Commands: `cargo offrails snippet show markdown`, `cargo offrails snippet add markdown`, `cargo offrails snippet remove markdown`
- README: https://rustoffrails.org/snippets/markdown.md

## pagination

PageLinks::new(base, page, more) and shared/_pager.html: the kit's pagination, per kept, ?page clamped

- Needs: nothing
- Files: `src/views/pager.rs`, `templates/shared/_pager.html`
- Commands: `cargo offrails snippet show pagination`, `cargo offrails snippet add pagination`, `cargo offrails snippet remove pagination`
- README: https://rustoffrails.org/snippets/pagination.md

## public-show-by-slug

GET /read/notes/{slug}: a public page per record, by slug (a path param), slugs unique and stable

- Needs: the resource and slug snippets
- Files: `migration/src/m20261018_000200_add_slug_to_notes.rs`, `src/controllers/note_pages.rs`, `src/models/note_slugs.rs`, `src/routes/note_pages.rs`, `src/views/note_pages.rs`, `templates/note_pages/show.html`, `tests/app/note_pages_test.rs`
- Commands: `cargo offrails snippet show public-show-by-slug`, `cargo offrails snippet add public-show-by-slug`, `cargo offrails snippet remove public-show-by-slug`
- README: https://rustoffrails.org/snippets/public-show-by-slug.md

## resource

htmx CRUD for one model (notes: title, body): the files `g resource` writes, split per action, public

- Needs: nothing
- Files: `migration/src/m20261018_000100_create_notes.rs`, `src/controllers/notes/destroy.rs`, `src/controllers/notes/edit.rs`, `src/controllers/notes/index.rs`, `src/controllers/notes/mod.rs`, `src/controllers/notes/new.rs`, `src/controllers/notes/show.rs`, `src/models/note/mod.rs`, `src/models/note/params.rs`, `src/models/note/queries.rs`, `src/routes/notes.rs`, `src/views/notes.rs`, `templates/notes/_form.html`, `templates/notes/edit.html`, `templates/notes/index.html`, `templates/notes/new.html`, `templates/notes/show.html`, `tests/app/factories/note.rs`, `tests/app/notes/mod.rs`, `tests/app/notes/model_test.rs`, `tests/app/notes/read_test.rs`, `tests/app/notes/write_test.rs`
- Commands: `cargo offrails snippet show resource`, `cargo offrails snippet add resource`, `cargo offrails snippet remove resource`
- README: https://rustoffrails.org/snippets/resource.md

## seed-backdated

Seeds with history: create through the model, then backdate::<E>(db, id, days_ago(30)) moves the timestamps

- Needs: nothing
- Files: `src/tasks/seed_support.rs`, `tests/app/seed_backdated_test.rs`
- Commands: `cargo offrails snippet show seed-backdated`, `cargo offrails snippet add seed-backdated`, `cargo offrails snippet remove seed-backdated`
- README: https://rustoffrails.org/snippets/seed-backdated.md

## slug

slugify(title) (accents folded, 80 chars) and unique(base, query): -2, -3… unique per owner or global

- Needs: nothing
- Files: `src/models/slug.rs`
- Commands: `cargo offrails snippet show slug`, `cargo offrails snippet add slug`, `cargo offrails snippet remove slug`
- README: https://rustoffrails.org/snippets/slug.md

## theme-toggle

A System/Light/Dark button in the nav: shared/_theme_toggle.html, a delegated handler in app.js, no-JS POST

- Needs: nothing
- Files: `templates/shared/_theme_toggle.html`, `tests/app/theme_toggle_test.rs`
- Commands: `cargo offrails snippet show theme-toggle`, `cargo offrails snippet add theme-toggle`, `cargo offrails snippet remove theme-toggle`
- README: https://rustoffrails.org/snippets/theme-toggle.md

