Extracting logic from templates with Hanami Views
summary
Hanami extracts template logic into Ruby objects so form rendering stays declarative: the Hanami View gem (2.1) is framework‑agnostic and provides Parts (decorators) and Scopes that compute locals, format errors, pick icons, and build control CSS classes. The demo shows a registration form refactored into a RegistrationPart that returns scope instances which render one reusable partial per input; it reduces template branching, is fully optional, and the extracted pieces are easily unit tested and reusable.
AI-written summary · about
chapters (10)
- 0:00Introduction and motivation
- 2:14What is Hanami framework
- 4:26Ruby and Rails issues
- 8:42Hanami View introduction
- 9:48Logic in templates problem
- 13:02Form errors extraction
- 15:34Form input logic extraction
- 19:59Using Scopes for partials
- 22:12Decorating form inputs
- 25:08Conclusion and takeaways
related talks
36mReturn To Simplicity: Architect Hypermedia REST applications using Hanami + HTMX
25mHanami - New Ruby Web Framework
42mHanami - New Ruby Web Framework
23mMaintainable Templates
28mDo Your Views Know Too Much?
37mEncapsulating Views
42mRender It! A Deep Dive into ActionView and Template Engines
38mRethinking the View Layer with Components
