These notes cover an upgrade from 2.0.0 to 2.1.0.
Update the app
-
Edit
Gemfileand update the versions of the Hanami gems to"~> 2.1". -
Add the following gems to
Gemfile:
group :development do
end
group :test do
end
- Add the following lines to
.gitignore:
public/
node_modules/
spec/examples.txt
- Update
Guardfileto match the following:
group :server do
guard "puma", port: ENV.fetch("HANAMI_PORT", 2300) do
# Edit the following regular expression for your needs.
# See: https://guides.hanamirb.org/app/code-reloading/
watch(%r{^(app|config|lib|slices)([\/][^\/]+)*.(rb|erb|haml|slim)$}i)
end
end
- Create
Procfile.devand add the following:
web: bundle exec hanami server
assets: bundle exec hanami assets watch
- Create
bin/dev, mark it as executable, (chmod a+x) and add the following:
#!/usr/bin/env sh
if ! ; then
fi
- If you are using the default
config/puma.rb, update it to match the following (note the addition and use of thepuma_concurrencyandpuma_cluster_modevariables):
# frozen_string_literal: true
#
# Environment and port
#
port ENV.fetch("HANAMI_PORT", 2300)
environment ENV.fetch("HANAMI_ENV", "development")
#
# Threads within each Puma/Ruby process (aka worker)
#
# Configure the minimum and maximum number of threads to use to answer requests.
max_threads_count = ENV.fetch("HANAMI_MAX_THREADS", 5)
min_threads_count = ENV.fetch("HANAMI_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
#
# Workers (aka Puma/Ruby processes)
#
puma_concurrency = Integer(ENV.fetch("HANAMI_WEB_CONCURRENCY", 0))
puma_cluster_mode = puma_concurrency > 1
# How many worker (Puma/Ruby) processes to run.
# Typically this is set to the number of available cores.
workers puma_concurrency
#
# Cluster mode (aka multiple workers)
#
if puma_cluster_mode
# Preload the application before starting the workers. Only in cluster mode.
preload_app!
# Code to run immediately before main process forks workers (once on boot).
#
# These hooks can block if necessary to wait for background operations unknown
# to puma to finish before the process terminates. This can be used to close
# any connections to remote servers (database, redis, …) that were opened when
# preloading the code.
before_fork do
Hanami.shutdown
end
end
- Add the following line to
spec/spec_helper.rb, underneath therequire_relative "support/rspec":
- Create
spec/support/features.rb:
# frozen_string_literal: true
Capybara.app = Hanami.app
- If you wish, update
spec/support/rspec.rbto include the following configs:
config.example_status_persistence_file_path = "spec/examples.txt"
# Uncomment this to enable warnings. This is recommended, but in some cases
# may be too noisy due to issues in dependencies.
# config.warnings = true
Add views
The steps below apply to each of your app and slices. The code examples use Bookshelf as the enclosing Ruby module; replace this with the relevant module for your app or slice.
- Add a
view.rb(toapp/or your slice):
# auto_register: false
# frozen_string_literal: true
end
end
- Add a
views/helpers.rb(toapp/or your slice):
# auto_register: false
# frozen_string_literal: true
# Add your view helpers here
end
end
end
- Add a
templates/layout/app.html.erb(toapp/or your slice):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookshelf</title>
<%= favicon_tag %>
<%= stylesheet_tag "app" %>
</head>
<body>
<%= yield %>
<%= javascript_tag "app" %>
</body>
</html>
- Create
public/404.htmlwith the following:
The page you were looking for doesn’t exist (404)
<!-- This file lives in public/404.html -->
404
The page you were looking for doesn’t exist.
- Create
public/500.htmlwith the following:
We’re sorry, but something went wrong (500)
<!-- This file lives in public/500.html -->
500
We’re sorry, but something went wrong.
Add assets
- Create
package.jsonwith the following:
-
Run
npm install -
Append the following to
Procfile.dev:
assets: bundle exec hanami assets watch
- Create
config/assets.jswith the following:
;
await assets.;
// To provide additional esbuild (https://esbuild.github.io) options, use the following:
//
// Read more at: https://guides.hanamirb.org/assets/overview/
//
// await assets.run({
// esbuildOptionsFn: (args, esbuildOptions) => {
// // Add to esbuildOptions here. Use `args.watch` as a condition for different options for
// // compile vs watch.
//
// return esbuildOptions;
// }
// });
- Create
app/assets/css/app.css(orassets/css/app.cssin your slice) with the following:
}
- Create
app/assets/js/app.js(orassets/js/app.jsin your slice) with the following:
;
- Create
app/assets/images/favicon.ico(orassets/images/favicon.icoin your slice) with the contents of this file.