crumble-orma
crumble-orma
Small integration helpers between Crumble and Orma.
Installation
-
Add the dependency to your
shard.yml:dependencies: crumble-orma: github: sbsoftware/crumble-orma -
Run
shards install
Usage
require "crumble-orma"
Page model loading
class User < Orma::Record
column name : String
end
class UserPage < Crumble::Page
model user : User
view do
template do
p { user.name }
end
end
end
The model macro defines a user_id path param, loads the record before handling the request, exposes user in the page view, and returns 404 when the record is missing.
You can provide a redirect or a fallback view when the record is missing:
class UserPage < Crumble::Page
model user : User, fallback_redirect: "/"
view do
template do
p { user.name }
end
end
end
class MissingUserView
include Crumble::ContextView
template do
p { "User not found" }
end
end
class UserFallbackViewPage < Crumble::Page
model user : User, fallback_view: MissingUserView
view do
template do
p { user.name }
end
end
end
Orma attributes in HTML + CSS
class Model < Orma::Record
column active : Bool
end
class View
getter model : Model
def initialize(@model); end
ToHtml.instance_template do
div model.active do
model.active ? "Active" : "Inactive"
end
end
end
class Style < CSS::Stylesheet
rule Model.active(false) do
color "#8a8a8a"
end
end
Rendering adds a data-orma-... attribute to the element, and the attribute can be used in CSS selectors via Model.active(false).
Development
- Install dependencies:
shards install - Run tests:
crystal spec - Format code before PRs:
crystal tool format
Contributing
- Fork it (https://github.com/sbsoftware/crumble-orma/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Stefan Bilharz - creator and maintainer
Repository
crumble-orma
Owner
Statistic
- 1
- 0
- 0
- 1
- 3
- 5 days ago
- July 15, 2025
License
MIT License
Links
Synced at
Mon, 19 Jan 2026 04:25:16 GMT
Languages