Update to Elixir v1.11 and remove unused files (#32)

This commit is contained in:
José Valim 2021-02-16 12:29:41 +01:00 committed by GitHub
parent 85806f5e03
commit 309c9c8a51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 64 additions and 172 deletions

View file

@ -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,

View file

@ -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: [

View file

@ -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

View file

@ -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.

29
config/runtime.exs Normal file
View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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