~hacktivista/leanweb-libreplanet-workshop-2023

f491d34df1622c0ccd07e3330ecd8971a4ae4b35 — Felix Freeman 1 year, 2 months ago c4a3115
Greet
3 files changed, 21 insertions(+), 1 deletions(-)

M routes.rb
M src/controllers/main_controller.rb
A src/views/hello.erb
M routes.rb => routes.rb +11 -1
@@ 2,5 2,15 @@

ROUTES = [
  { path: '/' },
  { path: '/leanweb/readme.html' }
  { path: '/leanweb/readme.html' },
  {
    path: %r{^/hello/(\w+)$},
    action: ->(who) { greet(who) },
    static: false
  },
  {
    path: %r{^/hello/(\w+).html$},
    action: { MainController: :hello_get },
    static: [ ['World'], ['LibrePlanet'] ]
  }
].freeze

M src/controllers/main_controller.rb => src/controllers/main_controller.rb +9 -0
@@ 7,4 7,13 @@ class MainController < LeanWeb::Controller
  def index_get
    render_response 'index.haml'
  end

  def greet(who)
    @response.write("Hello, #{who}!")
    @response.finish
  end

  def hello_get(who)
    render_response('hello.erb', { who: who }, 'text/html')
  end
end

A src/views/hello.erb => src/views/hello.erb +1 -0
@@ 0,0 1,1 @@
<h1>Hello, <%= who %></h1>