Reference · framework 0.7.3

Snippets: small, tested code to copy.

Recipes you would otherwise look up: a feed, slugs, Markdown, a pager, a theme button, backdated seeds, a public page by slug, a CRUD resource. Read one, copy it by hand, or let snippet add copy and wire it; snippet remove takes it back.

Listed from the framework's own .offrails/template/snippets/. Bigger pieces are parts; see also how snippets work.

  • atom-feed

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

    Needs
    nothing
    Adds
    5 files
    • src/controllers/feed.rs
    • src/routes/feed.rs
    • src/views/feed.rs
    • templates/feed/atom.xml
    • tests/app/feed_test.rs
    cargo offrails snippet show atom-feed
    cargo offrails snippet add atom-feed
    cargo offrails snippet remove atom-feed
  • markdown

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

    Needs
    crates pulldown-cmark and ammonia
    Adds
    1 file
    • src/views/markdown.rs
    cargo offrails snippet show markdown
    cargo offrails snippet add markdown
    cargo offrails snippet remove markdown
  • 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
    Adds
    7 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
    cargo offrails snippet show public-show-by-slug
    cargo offrails snippet add public-show-by-slug
    cargo offrails snippet remove public-show-by-slug
  • resource

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

    Needs
    nothing
    Adds
    22 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
    cargo offrails snippet show resource
    cargo offrails snippet add resource
    cargo offrails snippet remove resource
  • seed-backdated

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

    Needs
    nothing
    Adds
    2 files
    • src/tasks/seed_support.rs
    • tests/app/seed_backdated_test.rs
    cargo offrails snippet show seed-backdated
    cargo offrails snippet add seed-backdated
    cargo offrails snippet remove seed-backdated
  • slug

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

    Needs
    nothing
    Adds
    1 file
    • src/models/slug.rs
    cargo offrails snippet show slug
    cargo offrails snippet add slug
    cargo offrails snippet remove slug
  • 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
    Adds
    2 files
    • templates/shared/_theme_toggle.html
    • tests/app/theme_toggle_test.rs
    cargo offrails snippet show theme-toggle
    cargo offrails snippet add theme-toggle
    cargo offrails snippet remove theme-toggle

This page is also plain Markdown. Agents: the MCP server's list_snippets and read_snippet.