diff --git a/frameworks/Ruby/hanami/Gemfile b/frameworks/Ruby/hanami/Gemfile index ebc633433f4..83b7c0d287b 100644 --- a/frameworks/Ruby/hanami/Gemfile +++ b/frameworks/Ruby/hanami/Gemfile @@ -7,6 +7,7 @@ gem "hanami-router", "~> 2.2" gem "hanami-controller", "~> 2.2" gem "hanami-db", "~> 2.2" gem "hanami-validations", "~> 2.2" +gem "hanami-view", "~> 2.2" gem "dry-types", "~> 1.0", ">= 1.6.1" gem "puma" diff --git a/frameworks/Ruby/hanami/Gemfile.lock b/frameworks/Ruby/hanami/Gemfile.lock index 09111dda2dc..a1d3a8ff478 100644 --- a/frameworks/Ruby/hanami/Gemfile.lock +++ b/frameworks/Ruby/hanami/Gemfile.lock @@ -102,6 +102,13 @@ GEM dry-transformer (~> 1.0, < 2) hanami-validations (2.2.0) dry-validation (>= 1.10, < 2) + hanami-view (2.2.1) + dry-configurable (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0, < 2) + temple (~> 0.10.0, >= 0.10.2) + tilt (~> 2.3) + zeitwerk (~> 2.6) hansi (0.2.1) ice_nine (0.11.2) json (2.10.2) @@ -146,6 +153,8 @@ GEM ruby2_keywords (0.0.5) sequel (5.90.0) bigdecimal + temple (0.10.3) + tilt (2.6.0) transproc (1.1.1) zeitwerk (2.7.2) @@ -160,6 +169,7 @@ DEPENDENCIES hanami-db (~> 2.2) hanami-router (~> 2.2) hanami-validations (~> 2.2) + hanami-view (~> 2.2) pg puma rake diff --git a/frameworks/Ruby/hanami/app/actions/fortunes/index.rb b/frameworks/Ruby/hanami/app/actions/fortunes/index.rb new file mode 100644 index 00000000000..4d6bbbba502 --- /dev/null +++ b/frameworks/Ruby/hanami/app/actions/fortunes/index.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module HelloWorld + module Actions + module Fortunes + class Index < HelloWorld::Action + def handle(*, response) + end + end + end + end +end diff --git a/frameworks/Ruby/hanami/app/relations/fortunes.rb b/frameworks/Ruby/hanami/app/relations/fortunes.rb new file mode 100644 index 00000000000..d35a05575f1 --- /dev/null +++ b/frameworks/Ruby/hanami/app/relations/fortunes.rb @@ -0,0 +1,7 @@ +module HelloWorld + module Relations + class Fortunes < HelloWorld::DB::Relation + schema :Fortune, infer: true, as: :fortunes + end + end +end diff --git a/frameworks/Ruby/hanami/app/repos/fortune_repo.rb b/frameworks/Ruby/hanami/app/repos/fortune_repo.rb new file mode 100644 index 00000000000..c356c615e91 --- /dev/null +++ b/frameworks/Ruby/hanami/app/repos/fortune_repo.rb @@ -0,0 +1,11 @@ +module HelloWorld + module Repos + class FortuneRepo < HelloWorld::DB::Repo + def all + results = fortunes.to_a.map(&:to_h) + results << { id: 0, message: 'Additional fortune added at request time.' } + results.sort_by! { |fortune| fortune[:message] } + end + end + end +end diff --git a/frameworks/Ruby/hanami/app/templates/fortunes/index.html.erb b/frameworks/Ruby/hanami/app/templates/fortunes/index.html.erb new file mode 100644 index 00000000000..eacad31aca9 --- /dev/null +++ b/frameworks/Ruby/hanami/app/templates/fortunes/index.html.erb @@ -0,0 +1,12 @@ +
| id | +message | +
|---|---|
| <%= fortune[:id] %> | +<%= fortune[:message] %> | +