From 309c9c8a51ffb1eb2c28f29989740dae5ccbccac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 16 Feb 2021 12:29:41 +0100 Subject: [PATCH] Update to Elixir v1.11 and remove unused files (#32) --- config/config.exs | 7 +++-- config/dev.exs | 10 +++---- config/prod.exs | 2 +- config/prod.secret.exs | 29 ------------------- config/runtime.exs | 29 +++++++++++++++++++ config/test.exs | 2 +- lib/live_book.ex | 6 +--- lib/live_book/notebook.ex | 20 ++++++------- lib/live_book/notebook/cell.ex | 12 ++++---- lib/live_book/notebook/section.ex | 10 +++---- lib/live_book_web.ex | 26 +---------------- lib/live_book_web/controllers/.gitkeep | 0 lib/live_book_web/router.ex | 5 ---- lib/live_book_web/views/error_helpers.ex | 30 -------------------- lib/live_book_web/views/error_view.ex | 16 ----------- mix.exs | 2 +- test/live_book_web/views/error_view_test.exs | 14 --------- test/support/conn_case.ex | 16 ----------- 18 files changed, 64 insertions(+), 172 deletions(-) delete mode 100644 config/prod.secret.exs create mode 100644 config/runtime.exs delete mode 100644 lib/live_book_web/controllers/.gitkeep delete mode 100644 lib/live_book_web/views/error_helpers.ex delete mode 100644 lib/live_book_web/views/error_view.ex delete mode 100644 test/live_book_web/views/error_view_test.exs diff --git a/config/config.exs b/config/config.exs index 881133ad7..22615dc57 100644 --- a/config/config.exs +++ b/config/config.exs @@ -5,15 +5,16 @@ # is restricted to this project. # General application configuration -use Mix.Config +import Config # Configures the endpoint config :live_book, LiveBookWeb.Endpoint, url: [host: "localhost"], secret_key_base: "9hHHeOiAA8wrivUfuS//jQMurHxoMYUtF788BQMx2KO7mYUE8rVrGGG09djBNQq7", - render_errors: [view: LiveBookWeb.ErrorView, accepts: ~w(html json), layout: false], pubsub_server: LiveBook.PubSub, - live_view: [signing_salt: "mAPgPEM4"] + live_view: [signing_salt: "mAPgPEM4"], + # We are always in debug mode since we are executing code anyway + debug_errors: true # Configures Elixir's Logger config :logger, :console, diff --git a/config/dev.exs b/config/dev.exs index 749e404b7..8ee76f0a8 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,14 +1,14 @@ -use Mix.Config +import Config -# For development, we disable any cache and enable -# debugging and code reloading. +# For development, we disable any cache and enable code reloading. # # The watchers configuration can be used to run external # watchers to your application. For example, we use it # with webpack to recompile .js and .css sources. config :live_book, LiveBookWeb.Endpoint, - http: [port: 4000], - debug_errors: true, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {127, 0, 0, 1}, port: 4000], code_reloader: true, check_origin: false, watchers: [ diff --git a/config/prod.exs b/config/prod.exs index 1bd61366a..04c9bc611 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config # For production, don't forget to configure the url host # to something meaningful, Phoenix uses this information diff --git a/config/prod.secret.exs b/config/prod.secret.exs deleted file mode 100644 index c5e88e8e6..000000000 --- a/config/prod.secret.exs +++ /dev/null @@ -1,29 +0,0 @@ -# In this file, we load production configuration and secrets -# from environment variables. You can also hardcode secrets, -# although such is generally not recommended and you have to -# remember to add this file to your .gitignore. -use Mix.Config - -secret_key_base = - System.get_env("SECRET_KEY_BASE") || - raise """ - environment variable SECRET_KEY_BASE is missing. - You can generate one by calling: mix phx.gen.secret - """ - -config :live_book, LiveBookWeb.Endpoint, - http: [ - port: String.to_integer(System.get_env("PORT") || "4000"), - transport_options: [socket_opts: [:inet6]] - ], - secret_key_base: secret_key_base - -# ## Using releases (Elixir v1.9+) -# -# If you are doing OTP releases, you need to instruct Phoenix -# to start each relevant endpoint: -# -# config :live_book, LiveBookWeb.Endpoint, server: true -# -# Then you can assemble a release by calling `mix release`. -# See `mix help release` for more information. diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 000000000..f48122068 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,29 @@ +import Config + +if config_env() == :prod do + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ + + config :live_book, LiveBookWeb.Endpoint, + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: String.to_integer(System.get_env("PORT") || "4000") + ], + secret_key_base: secret_key_base + + # ## Using releases (Elixir v1.9+) + # + # If you are doing OTP releases, you need to instruct Phoenix + # to start each relevant endpoint: + # + # config :live_book, LiveBookWeb.Endpoint, server: true + # + # Then you can assemble a release by calling `mix release`. + # See `mix help release` for more information. +end diff --git a/config/test.exs b/config/test.exs index 1a1481759..ab0d260a4 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config # We don't run a server during test. If one is required, # you can enable the server option below. diff --git a/lib/live_book.ex b/lib/live_book.ex index 2c0cf6d9c..341f27bdf 100644 --- a/lib/live_book.ex +++ b/lib/live_book.ex @@ -1,9 +1,5 @@ defmodule LiveBook do @moduledoc """ - LiveBook keeps the contexts that define your domain - and business logic. - - Contexts are also responsible for managing your data, regardless - if it comes from the database, an external API or others. + LiveBook. """ end diff --git a/lib/live_book/notebook.ex b/lib/live_book/notebook.ex index 4655f1907..ef95f9ef2 100644 --- a/lib/live_book/notebook.ex +++ b/lib/live_book/notebook.ex @@ -1,15 +1,15 @@ defmodule LiveBook.Notebook do - @moduledoc """ - Data structure representing a notebook. + @moduledoc false - A notebook is just the representation and roughly - maps to a file that the user can edit. - A notebook *session* is a living process that holds a specific - notebook instance and allows users to collaboratively apply - changes to this notebook. - - A notebook is divided into a set of isolated *sections*. - """ + # Data structure representing a notebook. + # + # A notebook is just the representation and roughly + # maps to a file that the user can edit. + # A notebook *session* is a living process that holds a specific + # notebook instance and allows users to collaboratively apply + # changes to this notebook. + # + # A notebook is divided into a set of isolated *sections*. defstruct [:name, :version, :sections, :metadata] diff --git a/lib/live_book/notebook/cell.ex b/lib/live_book/notebook/cell.ex index 98944d522..bc540333c 100644 --- a/lib/live_book/notebook/cell.ex +++ b/lib/live_book/notebook/cell.ex @@ -1,11 +1,11 @@ defmodule LiveBook.Notebook.Cell do - @moduledoc """ - Data structure representing a single cell in a notebook. + @moduledoc false - A cell is the smallest unit of work in a notebook. - It primarly consists of text content that the user can edit - and may potentially produce some output (e.g. during code evaluation). - """ + # Data structure representing a single cell in a notebook. + # + # A cell is the smallest unit of work in a notebook. + # It primarly consists of text content that the user can edit + # and may potentially produce some output (e.g. during code evaluation). defstruct [:id, :type, :source, :outputs, :metadata] diff --git a/lib/live_book/notebook/section.ex b/lib/live_book/notebook/section.ex index ae7bf0b2e..f80b59d73 100644 --- a/lib/live_book/notebook/section.ex +++ b/lib/live_book/notebook/section.ex @@ -1,10 +1,10 @@ defmodule LiveBook.Notebook.Section do - @moduledoc """ - Data structure representing a single section in a notebook. + @moduledoc false - Each section contains a number of cells and is isolated - in the sense that cells don't interfere with cells in other sections. - """ + # Data structure representing a single section in a notebook. + # + # Each section contains a number of cells and is isolated + # in the sense that cells don't interfere with cells in other sections. defstruct [:id, :name, :cells, :metadata] diff --git a/lib/live_book_web.ex b/lib/live_book_web.ex index 122e6c96e..bbb7f988b 100644 --- a/lib/live_book_web.ex +++ b/lib/live_book_web.ex @@ -1,21 +1,5 @@ defmodule LiveBookWeb do - @moduledoc """ - The entrypoint for defining your web interface, such - as controllers, views, channels and so on. - - This can be used in your application as: - - use LiveBookWeb, :controller - use LiveBookWeb, :view - - The definitions below will be executed for every view, - controller, etc, so keep them short and clean, focused - on imports, uses and aliases. - - Do NOT define functions inside the quoted expressions - below. Instead, define any helper function in modules - and import those modules here. - """ + @moduledoc false def controller do quote do @@ -68,12 +52,6 @@ defmodule LiveBookWeb do end end - def channel do - quote do - use Phoenix.Channel - end - end - defp view_helpers do quote do # Use all HTML functionality (forms, tags, etc) @@ -84,8 +62,6 @@ defmodule LiveBookWeb do # Import basic rendering functionality (render, render_layout, etc) import Phoenix.View - - import LiveBookWeb.ErrorHelpers alias LiveBookWeb.Router.Helpers, as: Routes # Custom helpers diff --git a/lib/live_book_web/controllers/.gitkeep b/lib/live_book_web/controllers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/live_book_web/router.ex b/lib/live_book_web/router.ex index ee5989881..6e1571ff4 100644 --- a/lib/live_book_web/router.ex +++ b/lib/live_book_web/router.ex @@ -22,9 +22,4 @@ defmodule LiveBookWeb.Router do live "/sessions/:id", SessionLive, :page live "/sessions/:id/runtime", SessionLive, :runtime end - - # Other scopes may use custom stacks. - # scope "/api", LiveBookWeb do - # pipe_through :api - # end end diff --git a/lib/live_book_web/views/error_helpers.ex b/lib/live_book_web/views/error_helpers.ex deleted file mode 100644 index 272bd1b63..000000000 --- a/lib/live_book_web/views/error_helpers.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule LiveBookWeb.ErrorHelpers do - @moduledoc """ - Conveniences for translating and building error messages. - """ - - use Phoenix.HTML - - @doc """ - Generates tag for inlined form input errors. - """ - def error_tag(form, field) do - Enum.map(Keyword.get_values(form.errors, field), fn error -> - content_tag(:span, translate_error(error), - class: "invalid-feedback", - phx_feedback_for: input_id(form, field) - ) - end) - end - - @doc """ - Translates an error message. - """ - def translate_error({msg, opts}) do - # Because the error messages we show in our forms and APIs - # are defined inside Ecto, we need to translate them dynamically. - Enum.reduce(opts, msg, fn {key, value}, acc -> - String.replace(acc, "%{#{key}}", to_string(value)) - end) - end -end diff --git a/lib/live_book_web/views/error_view.ex b/lib/live_book_web/views/error_view.ex deleted file mode 100644 index ef6287457..000000000 --- a/lib/live_book_web/views/error_view.ex +++ /dev/null @@ -1,16 +0,0 @@ -defmodule LiveBookWeb.ErrorView do - use LiveBookWeb, :view - - # If you want to customize a particular status code - # for a certain format, you may uncomment below. - # def render("500.html", _assigns) do - # "Internal Server Error" - # end - - # By default, Phoenix returns the status message from - # the template name. For example, "404.html" becomes - # "Not Found". - def template_not_found(template, _assigns) do - Phoenix.Controller.status_message_from_template(template) - end -end diff --git a/mix.exs b/mix.exs index e407de340..8e5ebab20 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule LiveBook.MixProject do [ app: :live_book, version: "0.1.0", - elixir: "~> 1.7", + elixir: "~> 1.11", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix] ++ Mix.compilers(), start_permanent: Mix.env() == :prod, diff --git a/test/live_book_web/views/error_view_test.exs b/test/live_book_web/views/error_view_test.exs deleted file mode 100644 index c9be08b83..000000000 --- a/test/live_book_web/views/error_view_test.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule LiveBookWeb.ErrorViewTest do - use LiveBookWeb.ConnCase, async: true - - # Bring render/3 and render_to_string/3 for testing custom views - import Phoenix.View - - test "renders 404.html" do - assert render_to_string(LiveBookWeb.ErrorView, "404.html", []) == "Not Found" - end - - test "renders 500.html" do - assert render_to_string(LiveBookWeb.ErrorView, "500.html", []) == "Internal Server Error" - end -end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 1bd14d30b..b37a4f985 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,20 +1,4 @@ defmodule LiveBookWeb.ConnCase do - @moduledoc """ - This module defines the test case to be used by - tests that require setting up a connection. - - Such tests rely on `Phoenix.ConnTest` and also - import other functionality to make it easier - to build common data structures and query the data layer. - - Finally, if the test case interacts with the database, - we enable the SQL sandbox, so changes done to the database - are reverted at the end of every test. If you are using - PostgreSQL, you can even run database tests asynchronously - by setting `use LiveBookWeb.ConnCase, async: true`, although - this option is not recommended for other databases. - """ - use ExUnit.CaseTemplate using do