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 @@ + + + + + + <% fortunes.each do |fortune| %> + + + + + <% end %> +
idmessage
<%= fortune[:id] %><%= fortune[:message] %>
diff --git a/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb b/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb index ab87e9112bd..2c125c136fd 100644 --- a/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb +++ b/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb @@ -1,9 +1,7 @@ - + - - - Bookshelf + Fortunes <%= yield %> diff --git a/frameworks/Ruby/hanami/app/views/fortunes/index.rb b/frameworks/Ruby/hanami/app/views/fortunes/index.rb new file mode 100644 index 00000000000..5eb7d500305 --- /dev/null +++ b/frameworks/Ruby/hanami/app/views/fortunes/index.rb @@ -0,0 +1,14 @@ +module HelloWorld + module Views + module Fortunes + class Index < HelloWorld::View + + include Deps["repos.fortune_repo"] + + expose :fortunes do + fortune_repo.all + end + end + end + end +end diff --git a/frameworks/Ruby/hanami/benchmark_config.json b/frameworks/Ruby/hanami/benchmark_config.json index d384577682c..1a081210b16 100644 --- a/frameworks/Ruby/hanami/benchmark_config.json +++ b/frameworks/Ruby/hanami/benchmark_config.json @@ -5,6 +5,7 @@ "json_url": "/json", "db_url": "/db", "query_url": "/queries?queries=", + "fortune_url": "/fortunes", "update_url": "/updates?queries=", "plaintext_url": "/plaintext", "port": 8080, diff --git a/frameworks/Ruby/hanami/config/routes.rb b/frameworks/Ruby/hanami/config/routes.rb index d568af27c70..55f2f414845 100644 --- a/frameworks/Ruby/hanami/config/routes.rb +++ b/frameworks/Ruby/hanami/config/routes.rb @@ -2,10 +2,11 @@ module HelloWorld class Routes < Hanami::Routes - get "/db", to: "db.index" get "/json", to: "json.index" + get "/db", to: "db.index" + get "/queries", to: "queries.index" + get "/fortunes", to: "fortunes.index" get "/updates", to: "updates.index" get "/plaintext", to: "plaintext.index" - get "/queries", to: "queries.index" end end