CtrlK
BlogDocsLog inGet started
Tessl Logo

igmarin/hanakai-yaku

Curated library of atomic AI agent skills for Hanami, dry-rb, and ROM Ruby development. Covers actions, slices, repositories, relations, changesets, providers, DI, operations, TDD, CLI, views, routing, and validation. Shared Ruby process skills have moved to ruby-core-skills. Uses Markdown + Front-matter architecture.

92

1.33x
Quality

94%

Does it follow best practices?

Impact

92%

1.33x

Average score across 35 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

SKILL.mdskills/views/create-view/

name:
create-view
license:
MIT
description:
Use when creating Hanami 2.x view classes, exposing data to templates via the expose macro, configuring Tilt/ERB template rendering, setting up layouts, or working with the hanami-view gem and Hanami view layer. Covers view class structure, expose macro, context, rendering HTML templates, and integration with Actions and Parts.
metadata:
{"ecosystem_sources":["hanami/hanami-view"],"tags":["views","templates","rendering","tilt"],"version":"1.0.0"}

create-view

Use this skill when creating Hanami 2.x Views.

Core principle: Views are objects, not template files. They encapsulate presentation logic and expose data to templates.


Quick Reference

ScenarioApproach
Create a ViewClass inherits from Hanami::View in app/views/
Define exposuresUse expose :name to declare what the template receives
Expose with transformationexpose :user { |user| UserPresenter.new(user) }
Render a templateView automatically looks up templates/<path>.html.erb
Pass contextexpose :current_user, as: :current_user
Define a layoutlayout "application" in the View class
Set template formatformat :html (default) or format :json
Access exposures in template<%= user.name %> (locals passed to ERB)

Core Rules

  1. Create the View file in the app or slice:

    # app/views/users/show.rb
    # frozen_string_literal: true
    
    module MyApp
      module Views
        module Users
          class Show < MyApp::View
            expose :user
          end
        end
      end
    end
  2. Create the template alongside the View:

    <!-- app/templates/users/show.html.erb -->
    <h1><%= user.name %></h1>
    <p><%= user.email %></p>
  3. Expose data from the Action:

    def handle(request, response)
      user = user_repo.by_id(request.params[:id]).one
      response.render(view, user: user)
    end
  4. Transform exposures within the View:

    class Show < MyApp::View
      expose :user do |user|
        {
          name: "#{user.first_name} #{user.last_name}",
          email: user.email,
          member_since: user.created_at.strftime("%B %Y")
        }
      end
    end
  5. Use Parts for decorator-style logic (decorate-with-parts):

    class Show < MyApp::View
      expose :user, as: :user_part
    end
  6. Define a layout:

    class Show < MyApp::View
      layout "application"
    end
    <!-- app/templates/layouts/application.html.erb -->
    <!DOCTYPE html>
    <html>
      <head><title>MyApp</title></head>
      <body>
        <%= yield %>
      </body>
    </html>
  7. Keep Views focused on presentation. No database queries, no business logic. Views receive prepared data from Actions.

  8. Use explicit exposures. Do not pass raw params or unparsed data to Views.


Common Mistakes & Red Flags

Mistake / Red FlagReality
Database queries in View classes or templatesViews are for presentation only. All data fetching happens in Actions via Repositories.
@instance_variables in templatesTemplates receive locals from expose. No instance variables.
Skipping the View class and rendering templates directlyAlways define a View class. It encapsulates presentation logic and makes templates testable.
Template path mismatched from View namespaceTemplates follow the View namespace: app/views/users/show.rbapp/templates/users/show.html.erb.

Integration

Related SkillWhen to chain
create-actionActions render Views and pass exposures. Master Action structure first.
decorate-with-partsUse Parts for complex decorator-style logic in Views.
create-repositoryActions fetch data from Repositories before passing to Views.
write-request-spec (testing)Test the full stack: request → Action → View → template.

skills

views

create-view

README.md

tile.json