Resources
+-
+
- + Guides & Docs + +
- + Source + +
- + v1.4 Changelog + +
From 1566a2fcba0676cf54dde2b04702a320d9f1edcd Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Tue, 4 Feb 2020 13:49:53 +0100 Subject: Initial commit --- lib/waev_web/channels/user_socket.ex | 33 ++++++++++++++++++++ lib/waev_web/controllers/page_controller.ex | 7 +++++ lib/waev_web/endpoint.ex | 47 +++++++++++++++++++++++++++++ lib/waev_web/gettext.ex | 24 +++++++++++++++ lib/waev_web/router.ex | 26 ++++++++++++++++ lib/waev_web/templates/layout/app.html.eex | 31 +++++++++++++++++++ lib/waev_web/templates/page/index.html.eex | 35 +++++++++++++++++++++ lib/waev_web/views/error_helpers.ex | 44 +++++++++++++++++++++++++++ lib/waev_web/views/error_view.ex | 16 ++++++++++ lib/waev_web/views/layout_view.ex | 3 ++ lib/waev_web/views/page_view.ex | 3 ++ 11 files changed, 269 insertions(+) create mode 100644 lib/waev_web/channels/user_socket.ex create mode 100644 lib/waev_web/controllers/page_controller.ex create mode 100644 lib/waev_web/endpoint.ex create mode 100644 lib/waev_web/gettext.ex create mode 100644 lib/waev_web/router.ex create mode 100644 lib/waev_web/templates/layout/app.html.eex create mode 100644 lib/waev_web/templates/page/index.html.eex create mode 100644 lib/waev_web/views/error_helpers.ex create mode 100644 lib/waev_web/views/error_view.ex create mode 100644 lib/waev_web/views/layout_view.ex create mode 100644 lib/waev_web/views/page_view.ex (limited to 'lib/waev_web') diff --git a/lib/waev_web/channels/user_socket.ex b/lib/waev_web/channels/user_socket.ex new file mode 100644 index 0000000..b4a6ff6 --- /dev/null +++ b/lib/waev_web/channels/user_socket.ex @@ -0,0 +1,33 @@ +defmodule WaevWeb.UserSocket do + use Phoenix.Socket + + ## Channels + # channel "room:*", WaevWeb.RoomChannel + + # Socket params are passed from the client and can + # be used to verify and authenticate a user. After + # verification, you can put default assigns into + # the socket that will be set for all channels, ie + # + # {:ok, assign(socket, :user_id, verified_user_id)} + # + # To deny connection, return `:error`. + # + # See `Phoenix.Token` documentation for examples in + # performing token verification on connect. + def connect(_params, socket, _connect_info) do + {:ok, socket} + end + + # Socket id's are topics that allow you to identify all sockets for a given user: + # + # def id(socket), do: "user_socket:#{socket.assigns.user_id}" + # + # Would allow you to broadcast a "disconnect" event and terminate + # all active sockets and channels for a given user: + # + # WaevWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{}) + # + # Returning `nil` makes this socket anonymous. + def id(_socket), do: nil +end diff --git a/lib/waev_web/controllers/page_controller.ex b/lib/waev_web/controllers/page_controller.ex new file mode 100644 index 0000000..3bb2336 --- /dev/null +++ b/lib/waev_web/controllers/page_controller.ex @@ -0,0 +1,7 @@ +defmodule WaevWeb.PageController do + use WaevWeb, :controller + + def index(conn, _params) do + render(conn, "index.html") + end +end diff --git a/lib/waev_web/endpoint.ex b/lib/waev_web/endpoint.ex new file mode 100644 index 0000000..ad20615 --- /dev/null +++ b/lib/waev_web/endpoint.ex @@ -0,0 +1,47 @@ +defmodule WaevWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :waev + + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_waev_key", + signing_salt: "oHHex3Ho" + ] + + socket "/socket", WaevWeb.UserSocket, + websocket: true, + longpoll: false + + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :waev, + gzip: false, + only: ~w(css fonts images js favicon.ico robots.txt) + + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + end + + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug WaevWeb.Router +end diff --git a/lib/waev_web/gettext.ex b/lib/waev_web/gettext.ex new file mode 100644 index 0000000..8893769 --- /dev/null +++ b/lib/waev_web/gettext.ex @@ -0,0 +1,24 @@ +defmodule WaevWeb.Gettext do + @moduledoc """ + A module providing Internationalization with a gettext-based API. + + By using [Gettext](https://hexdocs.pm/gettext), + your module gains a set of macros for translations, for example: + + import WaevWeb.Gettext + + # Simple translation + gettext("Here is the string to translate") + + # Plural translation + ngettext("Here is the string to translate", + "Here are the strings to translate", + 3) + + # Domain-based translation + dgettext("errors", "Here is the error message to translate") + + See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. + """ + use Gettext, otp_app: :waev +end diff --git a/lib/waev_web/router.ex b/lib/waev_web/router.ex new file mode 100644 index 0000000..e98f87a --- /dev/null +++ b/lib/waev_web/router.ex @@ -0,0 +1,26 @@ +defmodule WaevWeb.Router do + use WaevWeb, :router + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_flash + plug :protect_from_forgery + plug :put_secure_browser_headers + end + + pipeline :api do + plug :accepts, ["json"] + end + + scope "/", WaevWeb do + pipe_through :browser + + get "/", PageController, :index + end + + # Other scopes may use custom stacks. + # scope "/api", WaevWeb do + # pipe_through :api + # end +end diff --git a/lib/waev_web/templates/layout/app.html.eex b/lib/waev_web/templates/layout/app.html.eex new file mode 100644 index 0000000..3eb7e3a --- /dev/null +++ b/lib/waev_web/templates/layout/app.html.eex @@ -0,0 +1,31 @@ + + +
+ + + +<%= get_flash(@conn, :info) %>
+<%= get_flash(@conn, :error) %>
+ <%= render @view_module, @view_template, assigns %> +A productive web framework that
does not compromise speed or maintainability.