├── assets
├── .babelrc
├── static
│ ├── favicon.ico
│ ├── images
│ │ ├── phoenix.png
│ │ ├── phoenix_uploads.png
│ │ └── generic_thumbnail.jpg
│ └── robots.txt
├── css
│ ├── app.css
│ ├── upload.css
│ └── phoenix.css
├── js
│ ├── app.js
│ ├── upload.js
│ └── socket.js
├── package.json
└── webpack.config.js
├── test
├── test_helper.exs
├── poetic_web
│ ├── views
│ │ ├── page_view_test.exs
│ │ ├── layout_view_test.exs
│ │ └── error_view_test.exs
│ └── controllers
│ │ └── page_controller_test.exs
└── support
│ ├── channel_case.ex
│ ├── conn_case.ex
│ └── data_case.ex
├── priv
├── repo
│ ├── migrations
│ │ ├── .formatter.exs
│ │ ├── 20190514143331_add_uploads_has_thumb.exs
│ │ └── 20190412141226_create_uploads.exs
│ └── seeds.exs
└── gettext
│ ├── en
│ └── LC_MESSAGES
│ │ └── errors.po
│ └── errors.pot
├── lib
├── poetic_web
│ ├── views
│ │ ├── layout_view.ex
│ │ ├── page_view.ex
│ │ ├── upload_view.ex
│ │ ├── error_view.ex
│ │ └── error_helpers.ex
│ ├── controllers
│ │ ├── page_controller.ex
│ │ └── upload_controller.ex
│ ├── templates
│ │ ├── upload
│ │ │ ├── upload_form.html.eex
│ │ │ └── index.html.eex
│ │ ├── page
│ │ │ └── index.html.eex
│ │ └── layout
│ │ │ └── app.html.eex
│ ├── router.ex
│ ├── gettext.ex
│ ├── channels
│ │ └── user_socket.ex
│ └── endpoint.ex
├── poetic
│ ├── repo.ex
│ ├── application.ex
│ ├── documents.ex
│ └── documents
│ │ └── upload.ex
├── poetic.ex
└── poetic_web.ex
├── .formatter.exs
├── config
├── test.exs
├── config.exs
├── dev.exs
└── prod.exs
├── README.md
├── .gitignore
├── mix.exs
└── mix.lock
/assets/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/test/test_helper.exs:
--------------------------------------------------------------------------------
1 | ExUnit.start()
2 | Ecto.Adapters.SQL.Sandbox.mode(Poetic.Repo, :manual)
3 |
--------------------------------------------------------------------------------
/priv/repo/migrations/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto_sql],
3 | inputs: ["*.exs"]
4 | ]
5 |
--------------------------------------------------------------------------------
/lib/poetic_web/views/layout_view.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.LayoutView do
2 | use PoeticWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/lib/poetic_web/views/page_view.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.PageView do
2 | use PoeticWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/lib/poetic_web/views/upload_view.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.UploadView do
2 | use PoeticWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/assets/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poeticoding/phoenix_uploads_articles/HEAD/assets/static/favicon.ico
--------------------------------------------------------------------------------
/assets/css/app.css:
--------------------------------------------------------------------------------
1 | /* This file is for your main application css. */
2 |
3 | @import "./phoenix.css";
4 |
5 | @import "./upload.css"
--------------------------------------------------------------------------------
/test/poetic_web/views/page_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.PageViewTest do
2 | use PoeticWeb.ConnCase, async: true
3 | end
4 |
--------------------------------------------------------------------------------
/assets/static/images/phoenix.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poeticoding/phoenix_uploads_articles/HEAD/assets/static/images/phoenix.png
--------------------------------------------------------------------------------
/test/poetic_web/views/layout_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.LayoutViewTest do
2 | use PoeticWeb.ConnCase, async: true
3 | end
4 |
--------------------------------------------------------------------------------
/lib/poetic/repo.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Repo do
2 | use Ecto.Repo,
3 | otp_app: :poetic,
4 | adapter: Ecto.Adapters.Postgres
5 | end
6 |
--------------------------------------------------------------------------------
/assets/static/images/phoenix_uploads.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poeticoding/phoenix_uploads_articles/HEAD/assets/static/images/phoenix_uploads.png
--------------------------------------------------------------------------------
/assets/static/images/generic_thumbnail.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poeticoding/phoenix_uploads_articles/HEAD/assets/static/images/generic_thumbnail.jpg
--------------------------------------------------------------------------------
/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto, :phoenix],
3 | inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
4 | subdirectories: ["priv/*/migrations"]
5 | ]
6 |
--------------------------------------------------------------------------------
/lib/poetic_web/controllers/page_controller.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.PageController do
2 | use PoeticWeb, :controller
3 |
4 | def index(conn, _params) do
5 | render(conn, "index.html")
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/assets/static/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/test/poetic_web/controllers/page_controller_test.exs:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.PageControllerTest do
2 | use PoeticWeb.ConnCase
3 |
4 | test "GET /", %{conn: conn} do
5 | conn = get(conn, "/")
6 | assert html_response(conn, 200) =~ "Welcome to Phoenix!"
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/priv/repo/migrations/20190514143331_add_uploads_has_thumb.exs:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Repo.Migrations.AddUploadsHasThumb do
2 | use Ecto.Migration
3 |
4 | def change do
5 | alter table(:uploads) do
6 | add :has_thumb, :boolean, default: false
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/lib/poetic.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic do
2 | @moduledoc """
3 | Poetic keeps the contexts that define your domain
4 | and business logic.
5 |
6 | Contexts are also responsible for managing your data, regardless
7 | if it comes from the database, an external API or others.
8 | """
9 | end
10 |
--------------------------------------------------------------------------------
/priv/repo/seeds.exs:
--------------------------------------------------------------------------------
1 | # Script for populating the database. You can run it as:
2 | #
3 | # mix run priv/repo/seeds.exs
4 | #
5 | # Inside the script, you can read and write to any of your
6 | # repositories directly:
7 | #
8 | # Poetic.Repo.insert!(%Poetic.SomeSchema{})
9 | #
10 | # We recommend using the bang functions (`insert!`, `update!`
11 | # and so on) as they will fail if something goes wrong.
12 |
--------------------------------------------------------------------------------
/priv/repo/migrations/20190412141226_create_uploads.exs:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Repo.Migrations.CreateUploads do
2 | use Ecto.Migration
3 |
4 | def change do
5 | create table(:uploads) do
6 | add :filename, :string
7 | add :size, :bigint
8 | add :content_type, :string
9 | add :hash, :string, size: 64
10 |
11 | timestamps()
12 | end
13 |
14 | create index(:uploads, [:hash])
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/test/poetic_web/views/error_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.ErrorViewTest do
2 | use PoeticWeb.ConnCase, async: true
3 |
4 | # Bring render/3 and render_to_string/3 for testing custom views
5 | import Phoenix.View
6 |
7 | test "renders 404.html" do
8 | assert render_to_string(PoeticWeb.ErrorView, "404.html", []) == "Not Found"
9 | end
10 |
11 | test "renders 500.html" do
12 | assert render_to_string(PoeticWeb.ErrorView, "500.html", []) == "Internal Server Error"
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/lib/poetic_web/templates/upload/upload_form.html.eex:
--------------------------------------------------------------------------------
1 | <%= form_for @conn, Routes.upload_path(@conn, :create), [multipart: true, id: "upload_form"], fn f-> %>
2 |
3 |
4 |
5 | <%= file_input f, :upload, class: "form-control" %>
6 |
7 |
8 |
12 |
13 | <% end %>
14 |
--------------------------------------------------------------------------------
/config/test.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # We don't run a server during test. If one is required,
4 | # you can enable the server option below.
5 | config :poetic, PoeticWeb.Endpoint,
6 | http: [port: 4002],
7 | server: false
8 |
9 | # Print only warnings and errors during test
10 | config :logger, level: :warn
11 |
12 | # Configure your database
13 | config :poetic, Poetic.Repo,
14 | username: "postgres",
15 | password: "postgres",
16 | database: "poetic_test",
17 | hostname: "localhost",
18 | pool: Ecto.Adapters.SQL.Sandbox
19 |
--------------------------------------------------------------------------------
/lib/poetic_web/views/error_view.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.ErrorView do
2 | use PoeticWeb, :view
3 |
4 | # If you want to customize a particular status code
5 | # for a certain format, you may uncomment below.
6 | # def render("500.html", _assigns) do
7 | # "Internal Server Error"
8 | # end
9 |
10 | # By default, Phoenix returns the status message from
11 | # the template name. For example, "404.html" becomes
12 | # "Not Found".
13 | def template_not_found(template, _assigns) do
14 | Phoenix.Controller.status_message_from_template(template)
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/assets/js/app.js:
--------------------------------------------------------------------------------
1 | // We need to import the CSS so that webpack will load it.
2 | // The MiniCssExtractPlugin is used to separate it out into
3 | // its own CSS file.
4 | import css from "../css/app.css"
5 |
6 | // webpack automatically bundles all modules in your
7 | // entry points. Those entry points can be configured
8 | // in "webpack.config.js".
9 | //
10 | // Import dependencies
11 | //
12 | import "phoenix_html"
13 |
14 | // Import local files
15 | //
16 | // Local files can be imported directly using relative paths, for example:
17 | // import socket from "./socket"
18 |
19 | import "./upload"
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ### [Step-by-Step Tutorial to Build a Phoenix App that Supports User Uploads](https://www.poeticoding.com/step-by-step-tutorial-to-build-a-phoenix-app-that-supports-user-uploads)
4 |
5 | In this step-by-step tutorial we see in depth how to:
6 |
7 | * **build a Phoenix app** from scratch
8 | * let users to **upload** their files using a **multipart form**
9 | * easily run PostgreSQL 🐘 with Docker 🐳
10 | * receive uploads using [**Plug**](https://github.com/elixir-plug/plug)
11 | * use [**Ecto**](https://github.com/elixir-ecto/ecto) to store upload details into the database
12 |
--------------------------------------------------------------------------------
/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "repository": {},
3 | "license": "MIT",
4 | "scripts": {
5 | "deploy": "webpack --mode production",
6 | "watch": "webpack --mode development --watch"
7 | },
8 | "dependencies": {
9 | "phoenix": "file:../deps/phoenix",
10 | "phoenix_html": "file:../deps/phoenix_html",
11 | "jquery": "^3.4.1"
12 | },
13 | "devDependencies": {
14 | "@babel/core": "^7.0.0",
15 | "@babel/preset-env": "^7.0.0",
16 | "babel-loader": "^8.0.0",
17 | "copy-webpack-plugin": "^5.1.1",
18 | "css-loader": "^3.4.0",
19 | "mini-css-extract-plugin": "^0.4.0",
20 | "optimize-css-assets-webpack-plugin": "^5.0.3",
21 | "uglifyjs-webpack-plugin": "^1.2.4",
22 | "webpack": "^4.41.5",
23 | "webpack-cli": "^3.3.10"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lib/poetic_web/router.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.Router do
2 | use PoeticWeb, :router
3 |
4 | pipeline :browser do
5 | plug :accepts, ["html"]
6 | plug :fetch_session
7 | plug :fetch_flash
8 | plug :protect_from_forgery
9 | plug :put_secure_browser_headers
10 | end
11 |
12 | pipeline :api do
13 | plug :accepts, ["json"]
14 | end
15 |
16 | scope "/", PoeticWeb do
17 | pipe_through :browser
18 |
19 | get "/", PageController, :index
20 |
21 | resources "/uploads", UploadController, only: [:index, :create, :show] do
22 | get "/thumbnail", UploadController, :thumbnail, as: "thumbnail"
23 | end
24 | end
25 |
26 | # Other scopes may use custom stacks.
27 | # scope "/api", PoeticWeb do
28 | # pipe_through :api
29 | # end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/poetic_web/gettext.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.Gettext do
2 | @moduledoc """
3 | A module providing Internationalization with a gettext-based API.
4 |
5 | By using [Gettext](https://hexdocs.pm/gettext),
6 | your module gains a set of macros for translations, for example:
7 |
8 | import PoeticWeb.Gettext
9 |
10 | # Simple translation
11 | gettext("Here is the string to translate")
12 |
13 | # Plural translation
14 | ngettext("Here is the string to translate",
15 | "Here are the strings to translate",
16 | 3)
17 |
18 | # Domain-based translation
19 | dgettext("errors", "Here is the error message to translate")
20 |
21 | See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
22 | """
23 | use Gettext, otp_app: :poetic
24 | end
25 |
--------------------------------------------------------------------------------
/lib/poetic_web/templates/upload/index.html.eex:
--------------------------------------------------------------------------------
1 | <%= PoeticWeb.UploadView.render("upload_form.html", conn: @conn) %>
2 |
3 |
4 |
5 | | Thumbnail |
6 | ID |
7 | Filename |
8 | Size |
9 | Type |
10 | Time |
11 |
12 |
13 |
14 | <%= for upload <- @uploads do %>
15 |
16 | |
17 | <%= if upload.thumbnail? do
18 | img_tag Routes.upload_thumbnail_path(@conn, :thumbnail, upload.id),
19 | class: "image"
20 | else
21 | img_tag "/images/generic_thumbnail.jpg", class: "image"
22 | end %>
23 | |
24 | <%= upload.id %> |
25 | <%= upload.filename %> |
26 | <%= upload.size %> |
27 | <%= upload.content_type %> |
28 | <%= upload.inserted_at %> |
29 |
30 | <%= link "download", to: Routes.upload_path(@conn, :show, upload.id) %>
31 | |
32 |
33 | <% end %>
34 |
35 |
36 |
--------------------------------------------------------------------------------
/assets/css/upload.css:
--------------------------------------------------------------------------------
1 | .upload-progress {
2 | position: relative;
3 | }
4 |
5 |
6 | progress {
7 | display: none;
8 | position:relative;
9 | width: 100%;
10 | height: 25px;
11 | appearance: none;
12 | -webkit-appearance: none;
13 | }
14 |
15 |
16 | progress::-webkit-progress-bar {
17 | background-color: #eee;
18 | border-radius: 8px;
19 | }
20 |
21 | progress::-webkit-progress-value {
22 | background-color: #276bd1;
23 | border-radius: 8px;
24 | }
25 |
26 | label.progress-percentage {
27 | position: absolute;
28 | top: 0;
29 | text-align: center;
30 | width: 100%;
31 | color: white;
32 | font-weight: bold;
33 | text-shadow: 1px 1px 1px #444;
34 | }
35 |
36 |
37 | .upload-btn-wrapper {
38 | position: relative;
39 | overflow: hidden;
40 | display: inline-block;
41 | }
42 | .upload-btn-wrapper input[type=file] {
43 | width: 100%;
44 | height: 100%;
45 | position: absolute;
46 | left: 0;
47 | top: 0;
48 | opacity: 0;
49 | }
50 |
--------------------------------------------------------------------------------
/lib/poetic/application.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Application do
2 | # See https://hexdocs.pm/elixir/Application.html
3 | # for more information on OTP Applications
4 | @moduledoc false
5 |
6 | use Application
7 |
8 | def start(_type, _args) do
9 | # List all child processes to be supervised
10 | children = [
11 | # Start the Ecto repository
12 | Poetic.Repo,
13 | # Start the endpoint when the application starts
14 | PoeticWeb.Endpoint
15 | # Starts a worker by calling: Poetic.Worker.start_link(arg)
16 | # {Poetic.Worker, arg},
17 | ]
18 |
19 | # See https://hexdocs.pm/elixir/Supervisor.html
20 | # for other strategies and supported options
21 | opts = [strategy: :one_for_one, name: Poetic.Supervisor]
22 | Supervisor.start_link(children, opts)
23 | end
24 |
25 | # Tell Phoenix to update the endpoint configuration
26 | # whenever the application is updated.
27 | def config_change(changed, _new, removed) do
28 | PoeticWeb.Endpoint.config_change(changed, removed)
29 | :ok
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/test/support/channel_case.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.ChannelCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | channel tests.
5 |
6 | Such tests rely on `Phoenix.ChannelTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | it cannot be async. For this reason, every test runs
12 | inside a transaction which is reset at the beginning
13 | of the test unless the test case is marked as async.
14 | """
15 |
16 | use ExUnit.CaseTemplate
17 |
18 | using do
19 | quote do
20 | # Import conveniences for testing with channels
21 | use Phoenix.ChannelTest
22 |
23 | # The default endpoint for testing
24 | @endpoint PoeticWeb.Endpoint
25 | end
26 | end
27 |
28 | setup tags do
29 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Poetic.Repo)
30 |
31 | unless tags[:async] do
32 | Ecto.Adapters.SQL.Sandbox.mode(Poetic.Repo, {:shared, self()})
33 | end
34 |
35 | :ok
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/config/config.exs:
--------------------------------------------------------------------------------
1 | # This file is responsible for configuring your application
2 | # and its dependencies with the aid of the Mix.Config module.
3 | #
4 | # This configuration file is loaded before any dependency and
5 | # is restricted to this project.
6 |
7 | # General application configuration
8 | use Mix.Config
9 |
10 | config :poetic,
11 | ecto_repos: [Poetic.Repo]
12 |
13 | # Configures the endpoint
14 | config :poetic, PoeticWeb.Endpoint,
15 | url: [host: "localhost"],
16 | secret_key_base: "iCvVlmFNnrlgRYUa8pTm/XVeYs8rr936EsXIPxGAqDmZ4yyPs2cVkJtGkR2328Kd",
17 | render_errors: [view: PoeticWeb.ErrorView, accepts: ~w(html json)],
18 | pubsub: [name: Poetic.PubSub, adapter: Phoenix.PubSub.PG2]
19 |
20 | # Configures Elixir's Logger
21 | config :logger, :console,
22 | format: "$time $metadata[$level] $message\n",
23 | metadata: [:request_id]
24 |
25 | # Use Jason for JSON parsing in Phoenix
26 | config :phoenix, :json_library, Jason
27 |
28 | # Import environment specific config. This must remain at the bottom
29 | # of this file so it overrides the configuration defined above.
30 | import_config "#{Mix.env()}.exs"
31 |
--------------------------------------------------------------------------------
/lib/poetic/documents.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Documents do
2 | import Ecto.Query, warn: false
3 |
4 | alias Poetic.Repo
5 | alias Poetic.Documents.Upload
6 |
7 | def get_upload!(id) do
8 | Upload
9 | |> Repo.get!(id)
10 | end
11 |
12 | def list_uploads do
13 | Repo.all(Upload)
14 | end
15 |
16 | def create_upload_from_plug_upload(%Plug.Upload{
17 | filename: filename,
18 | path: tmp_path,
19 | content_type: content_type
20 | }) do
21 |
22 | hash =
23 | File.stream!(tmp_path, [], 2048)
24 | |> Upload.sha256()
25 |
26 | Repo.transaction fn ->
27 | with {:ok, %File.Stat{size: size}} <- File.stat(tmp_path),
28 | {:ok, upload} <-
29 | Upload.changeset(%Upload{},%{
30 | filename: filename,
31 | content_type: content_type,
32 | hash: hash, size: size
33 | }) |> Repo.insert(),
34 |
35 | :ok <- File.cp(tmp_path, Upload.local_path(upload.id, filename)),
36 |
37 | {:ok, upload} <- Upload.create_thumbnail(upload) |> Repo.update()
38 | do
39 | upload
40 | else
41 | {:error, reason} ->
42 | Repo.rollback(reason)
43 | end
44 | end
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/lib/poetic_web/templates/page/index.html.eex:
--------------------------------------------------------------------------------
1 |
2 | <%= gettext "Welcome to %{name}!", name: "Phoenix" %>
3 | A productive web framework that
does not compromise speed and maintainability.
4 |
5 |
6 |
7 |
8 | Resources
9 |
20 |
21 |
22 | Help
23 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/test/support/conn_case.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.ConnCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | tests that require setting up a connection.
5 |
6 | Such tests rely on `Phoenix.ConnTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | it cannot be async. For this reason, every test runs
12 | inside a transaction which is reset at the beginning
13 | of the test unless the test case is marked as async.
14 | """
15 |
16 | use ExUnit.CaseTemplate
17 |
18 | using do
19 | quote do
20 | # Import conveniences for testing with connections
21 | use Phoenix.ConnTest
22 | alias PoeticWeb.Router.Helpers, as: Routes
23 |
24 | # The default endpoint for testing
25 | @endpoint PoeticWeb.Endpoint
26 | end
27 | end
28 |
29 | setup tags do
30 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Poetic.Repo)
31 |
32 | unless tags[:async] do
33 | Ecto.Adapters.SQL.Sandbox.mode(Poetic.Repo, {:shared, self()})
34 | end
35 |
36 | {:ok, conn: Phoenix.ConnTest.build_conn()}
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/lib/poetic_web/channels/user_socket.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.UserSocket do
2 | use Phoenix.Socket
3 |
4 | ## Channels
5 | # channel "room:*", PoeticWeb.RoomChannel
6 |
7 | # Socket params are passed from the client and can
8 | # be used to verify and authenticate a user. After
9 | # verification, you can put default assigns into
10 | # the socket that will be set for all channels, ie
11 | #
12 | # {:ok, assign(socket, :user_id, verified_user_id)}
13 | #
14 | # To deny connection, return `:error`.
15 | #
16 | # See `Phoenix.Token` documentation for examples in
17 | # performing token verification on connect.
18 | def connect(_params, socket, _connect_info) do
19 | {:ok, socket}
20 | end
21 |
22 | # Socket id's are topics that allow you to identify all sockets for a given user:
23 | #
24 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
25 | #
26 | # Would allow you to broadcast a "disconnect" event and terminate
27 | # all active sockets and channels for a given user:
28 | #
29 | # PoeticWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
30 | #
31 | # Returning `nil` makes this socket anonymous.
32 | def id(_socket), do: nil
33 | end
34 |
--------------------------------------------------------------------------------
/lib/poetic_web/controllers/upload_controller.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.UploadController do
2 | use PoeticWeb, :controller
3 |
4 | alias Poetic.Documents
5 | alias Poetic.Documents.Upload
6 |
7 | def index(conn, _params) do
8 | uploads = Documents.list_uploads()
9 | render(conn, "index.html", uploads: uploads)
10 | end
11 |
12 |
13 | def create(conn, %{"upload" => %Plug.Upload{}=upload}) do
14 | case Documents.create_upload_from_plug_upload(upload) do
15 | {:ok, upload}->
16 | conn
17 | |> put_flash(:info, "file uploaded correctly")
18 | |> redirect(to: Routes.upload_path(conn,:index))
19 | {:error, reason}->
20 | conn
21 | |> put_flash(:error, "error upload file: #{inspect(reason)}")
22 | |> redirect(to: Routes.upload_path(conn, :new))
23 | end
24 | end
25 |
26 |
27 | def show(conn, %{"id" => id}) do
28 | upload = Documents.get_upload!(id)
29 | local_path = Upload.local_path(upload.id, upload.filename)
30 | send_download conn, {:file, local_path}, filename: upload.filename
31 | end
32 |
33 | def thumbnail(conn, %{"upload_id" => id}) do
34 | thumb_path = Upload.thumbnail_path(id)
35 | conn
36 | |> put_resp_content_type("image/jpeg")
37 | |> send_file(200, thumb_path)
38 | end
39 |
40 | end
41 |
--------------------------------------------------------------------------------
/assets/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const glob = require('glob');
3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
5 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
6 | const CopyWebpackPlugin = require('copy-webpack-plugin');
7 |
8 | module.exports = (env, options) => ({
9 | optimization: {
10 | minimizer: [
11 | new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }),
12 | new OptimizeCSSAssetsPlugin({})
13 | ]
14 | },
15 | entry: {
16 | './js/app.js': ['./js/app.js'].concat(glob.sync('./vendor/**/*.js'))
17 | },
18 | output: {
19 | filename: 'app.js',
20 | path: path.resolve(__dirname, '../priv/static/js')
21 | },
22 | module: {
23 | rules: [
24 | {
25 | test: /\.js$/,
26 | exclude: /node_modules/,
27 | use: {
28 | loader: 'babel-loader'
29 | }
30 | },
31 | {
32 | test: /\.css$/,
33 | use: [MiniCssExtractPlugin.loader, 'css-loader']
34 | }
35 | ]
36 | },
37 | plugins: [
38 | new MiniCssExtractPlugin({ filename: '../css/app.css' }),
39 | new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
40 | ]
41 | });
42 |
--------------------------------------------------------------------------------
/lib/poetic_web/templates/layout/app.html.eex:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Poetic · Phoenix Framework
8 | "/>
9 |
10 |
11 |
23 |
24 | <%= get_flash(@conn, :info) %>
25 | <%= get_flash(@conn, :error) %>
26 | <%= render @view_module, @view_template, assigns %>
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # The directory Mix will write compiled artifacts to.
2 | /_build/
3 |
4 | # If you run "mix test --cover", coverage assets end up here.
5 | /cover/
6 |
7 | # The directory Mix downloads your dependencies sources to.
8 | /deps/
9 |
10 | # Where 3rd-party dependencies like ExDoc output generated docs.
11 | /doc/
12 |
13 | # Ignore .fetch files in case you like to edit your project deps locally.
14 | /.fetch
15 |
16 | # If the VM crashes, it generates a dump, let's ignore it too.
17 | erl_crash.dump
18 |
19 | # Also ignore archive artifacts (built via "mix archive.build").
20 | *.ez
21 |
22 | # Ignore package tarball (built via "mix hex.build").
23 | poetic-*.tar
24 |
25 | # If NPM crashes, it generates a log, let's ignore it too.
26 | npm-debug.log
27 |
28 | # The directory NPM downloads your dependencies sources to.
29 | /assets/node_modules/
30 |
31 | # Since we are building assets from assets/,
32 | # we ignore priv/static. You may want to comment
33 | # this depending on your deployment strategy.
34 | /priv/static/
35 |
36 | # Files matching config/*.secret.exs pattern contain sensitive
37 | # data and you should not commit them into version control.
38 | #
39 | # Alternatively, you may comment the line below and commit the
40 | # secrets files as long as you replace their contents by environment
41 | # variables.
42 | /config/*.secret.exs
43 |
44 | .elixir_ls/
--------------------------------------------------------------------------------
/lib/poetic_web/endpoint.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.Endpoint do
2 | use Phoenix.Endpoint, otp_app: :poetic
3 |
4 | socket "/socket", PoeticWeb.UserSocket,
5 | websocket: true,
6 | longpoll: false
7 |
8 | # Serve at "/" the static files from "priv/static" directory.
9 | #
10 | # You should set gzip to true if you are running phx.digest
11 | # when deploying your static files in production.
12 | plug Plug.Static,
13 | at: "/",
14 | from: :poetic,
15 | gzip: false,
16 | only: ~w(css fonts images js favicon.ico robots.txt)
17 |
18 | # Code reloading can be explicitly enabled under the
19 | # :code_reloader configuration of your endpoint.
20 | if code_reloading? do
21 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
22 | plug Phoenix.LiveReloader
23 | plug Phoenix.CodeReloader
24 | end
25 |
26 | plug Plug.RequestId
27 | plug Plug.Logger
28 |
29 | plug Plug.Parsers,
30 | parsers: [:urlencoded, {:multipart, length: 500_000_000}, :json],
31 | pass: ["*/*"],
32 | json_decoder: Phoenix.json_library()
33 |
34 | plug Plug.MethodOverride
35 | plug Plug.Head
36 |
37 | # The session will be stored in the cookie and signed,
38 | # this means its contents can be read but not tampered with.
39 | # Set :encryption_salt if you would also like to encrypt it.
40 | plug Plug.Session,
41 | store: :cookie,
42 | key: "_poetic_key",
43 | signing_salt: "4H2c0Jhy"
44 |
45 | plug PoeticWeb.Router
46 | end
47 |
--------------------------------------------------------------------------------
/test/support/data_case.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic.DataCase do
2 | @moduledoc """
3 | This module defines the setup for tests requiring
4 | access to the application's data layer.
5 |
6 | You may define functions here to be used as helpers in
7 | your tests.
8 |
9 | Finally, if the test case interacts with the database,
10 | it cannot be async. For this reason, every test runs
11 | inside a transaction which is reset at the beginning
12 | of the test unless the test case is marked as async.
13 | """
14 |
15 | use ExUnit.CaseTemplate
16 |
17 | using do
18 | quote do
19 | alias Poetic.Repo
20 |
21 | import Ecto
22 | import Ecto.Changeset
23 | import Ecto.Query
24 | import Poetic.DataCase
25 | end
26 | end
27 |
28 | setup tags do
29 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Poetic.Repo)
30 |
31 | unless tags[:async] do
32 | Ecto.Adapters.SQL.Sandbox.mode(Poetic.Repo, {:shared, self()})
33 | end
34 |
35 | :ok
36 | end
37 |
38 | @doc """
39 | A helper that transforms changeset errors into a map of messages.
40 |
41 | assert {:error, changeset} = Accounts.create_user(%{password: "short"})
42 | assert "password is too short" in errors_on(changeset).password
43 | assert %{password: ["password is too short"]} = errors_on(changeset)
44 |
45 | """
46 | def errors_on(changeset) do
47 | Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
48 | Enum.reduce(opts, message, fn {key, value}, acc ->
49 | String.replace(acc, "%{#{key}}", to_string(value))
50 | end)
51 | end)
52 | end
53 | end
54 |
--------------------------------------------------------------------------------
/lib/poetic_web/views/error_helpers.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb.ErrorHelpers do
2 | @moduledoc """
3 | Conveniences for translating and building error messages.
4 | """
5 |
6 | use Phoenix.HTML
7 |
8 | @doc """
9 | Generates tag for inlined form input errors.
10 | """
11 | def error_tag(form, field) do
12 | Enum.map(Keyword.get_values(form.errors, field), fn error ->
13 | content_tag(:span, translate_error(error), class: "help-block")
14 | end)
15 | end
16 |
17 | @doc """
18 | Translates an error message using gettext.
19 | """
20 | def translate_error({msg, opts}) do
21 | # When using gettext, we typically pass the strings we want
22 | # to translate as a static argument:
23 | #
24 | # # Translate "is invalid" in the "errors" domain
25 | # dgettext("errors", "is invalid")
26 | #
27 | # # Translate the number of files with plural rules
28 | # dngettext("errors", "1 file", "%{count} files", count)
29 | #
30 | # Because the error messages we show in our forms and APIs
31 | # are defined inside Ecto, we need to translate them dynamically.
32 | # This requires us to call the Gettext module passing our gettext
33 | # backend as first argument.
34 | #
35 | # Note we use the "errors" domain, which means translations
36 | # should be written to the errors.po file. The :count option is
37 | # set by Ecto and indicates we should also apply plural rules.
38 | if count = opts[:count] do
39 | Gettext.dngettext(PoeticWeb.Gettext, "errors", msg, msg, count, opts)
40 | else
41 | Gettext.dgettext(PoeticWeb.Gettext, "errors", msg, opts)
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/poetic_web.ex:
--------------------------------------------------------------------------------
1 | defmodule PoeticWeb do
2 | @moduledoc """
3 | The entrypoint for defining your web interface, such
4 | as controllers, views, channels and so on.
5 |
6 | This can be used in your application as:
7 |
8 | use PoeticWeb, :controller
9 | use PoeticWeb, :view
10 |
11 | The definitions below will be executed for every view,
12 | controller, etc, so keep them short and clean, focused
13 | on imports, uses and aliases.
14 |
15 | Do NOT define functions inside the quoted expressions
16 | below. Instead, define any helper function in modules
17 | and import those modules here.
18 | """
19 |
20 | def controller do
21 | quote do
22 | use Phoenix.Controller, namespace: PoeticWeb
23 |
24 | import Plug.Conn
25 | import PoeticWeb.Gettext
26 | alias PoeticWeb.Router.Helpers, as: Routes
27 | end
28 | end
29 |
30 | def view do
31 | quote do
32 | use Phoenix.View,
33 | root: "lib/poetic_web/templates",
34 | namespace: PoeticWeb
35 |
36 | # Import convenience functions from controllers
37 | import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
38 |
39 | # Use all HTML functionality (forms, tags, etc)
40 | use Phoenix.HTML
41 |
42 | import PoeticWeb.ErrorHelpers
43 | import PoeticWeb.Gettext
44 | alias PoeticWeb.Router.Helpers, as: Routes
45 | end
46 | end
47 |
48 | def router do
49 | quote do
50 | use Phoenix.Router
51 | import Plug.Conn
52 | import Phoenix.Controller
53 | end
54 | end
55 |
56 | def channel do
57 | quote do
58 | use Phoenix.Channel
59 | import PoeticWeb.Gettext
60 | end
61 | end
62 |
63 | @doc """
64 | When used, dispatch to the appropriate controller/view/etc.
65 | """
66 | defmacro __using__(which) when is_atom(which) do
67 | apply(__MODULE__, which, [])
68 | end
69 | end
70 |
--------------------------------------------------------------------------------
/mix.exs:
--------------------------------------------------------------------------------
1 | defmodule Poetic.MixProject do
2 | use Mix.Project
3 |
4 | def project do
5 | [
6 | app: :poetic,
7 | version: "0.1.0",
8 | elixir: "~> 1.5",
9 | elixirc_paths: elixirc_paths(Mix.env()),
10 | compilers: [:phoenix, :gettext] ++ Mix.compilers(),
11 | start_permanent: Mix.env() == :prod,
12 | aliases: aliases(),
13 | deps: deps()
14 | ]
15 | end
16 |
17 | # Configuration for the OTP application.
18 | #
19 | # Type `mix help compile.app` for more information.
20 | def application do
21 | [
22 | mod: {Poetic.Application, []},
23 | extra_applications: [:logger, :runtime_tools]
24 | ]
25 | end
26 |
27 | # Specifies which paths to compile per environment.
28 | defp elixirc_paths(:test), do: ["lib", "test/support"]
29 | defp elixirc_paths(_), do: ["lib"]
30 |
31 | # Specifies your project dependencies.
32 | #
33 | # Type `mix help deps` for examples and options.
34 | defp deps do
35 | [
36 | {:phoenix, "~> 1.4.0"},
37 | {:phoenix_pubsub, "~> 1.1"},
38 | {:phoenix_ecto, "~> 4.0"},
39 | {:ecto_sql, "~> 3.0"},
40 | {:postgrex, ">= 0.0.0"},
41 | {:phoenix_html, "~> 2.11"},
42 | {:phoenix_live_reload, "~> 1.2", only: :dev},
43 | {:gettext, "~> 0.11"},
44 | {:jason, "~> 1.0"},
45 | {:plug_cowboy, "~> 2.0"},
46 | {:mogrify, "~> 0.7.2"}
47 | ]
48 | end
49 |
50 | # Aliases are shortcuts or tasks specific to the current project.
51 | # For example, to create, migrate and run the seeds file at once:
52 | #
53 | # $ mix ecto.setup
54 | #
55 | # See the documentation for `Mix` for more info on aliases.
56 | defp aliases do
57 | [
58 | "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
59 | "ecto.reset": ["ecto.drop", "ecto.setup"],
60 | test: ["ecto.create --quiet", "ecto.migrate", "test"]
61 | ]
62 | end
63 | end
64 |
--------------------------------------------------------------------------------
/assets/js/upload.js:
--------------------------------------------------------------------------------
1 | import jQuery from "jquery"
2 |
3 |
4 | function createProgressHandler($form) {
5 | let $progress = $form.find("progress"),
6 | $label = $form.find("label.progress-percentage");
7 |
8 | return function handleProgressEvent(progressEvent) {
9 | let progress = progressEvent.loaded / progressEvent.total,
10 | percentage = progress * 100,
11 | percentageStr = `${percentage.toFixed(2)}%`; //xx.xx%
12 |
13 | $label.text(percentageStr)
14 |
15 | $progress
16 | .attr("max", progressEvent.total)
17 | .attr("value", progressEvent.loaded);
18 | }
19 | }
20 |
21 |
22 |
23 | function startUpload(formData, $form) {
24 | let $progress = $form.find("progress");
25 | $progress.show()
26 |
27 | jQuery.ajax({
28 | type: 'POST',
29 | url: '/uploads',
30 | data: formData,
31 | processData: false, //IMPORTANT!
32 | xhr: function () {
33 | let xhr = jQuery.ajaxSettings.xhr();
34 | if (xhr.upload) {
35 | xhr.upload.addEventListener('progress', createProgressHandler($form), false);
36 | }
37 | return xhr;
38 | },
39 |
40 | cache: false,
41 | contentType: false,
42 |
43 | success: function (data) {
44 | window.location = "/uploads"
45 | },
46 |
47 | error: function (data) {
48 | console.error(data);
49 | }
50 | })
51 | }
52 |
53 | jQuery(document).ready(function ($) {
54 | let $form = $("#upload_form"),
55 | $fileInput = $form.find("input[type='file']");
56 |
57 | $form.submit(function (event) {
58 | let formData = new FormData(this);
59 | startUpload(formData, $form);
60 |
61 | event.preventDefault();
62 | })
63 |
64 | $fileInput.on("change", function (e) {
65 | $form.trigger("submit");
66 | });
67 |
68 |
69 | })
70 |
71 |
--------------------------------------------------------------------------------
/config/dev.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # For development, we disable any cache and enable
4 | # debugging and code reloading.
5 | #
6 | # The watchers configuration can be used to run external
7 | # watchers to your application. For example, we use it
8 | # with webpack to recompile .js and .css sources.
9 | config :poetic, PoeticWeb.Endpoint,
10 | http: [port: 4000],
11 | debug_errors: true,
12 | code_reloader: true,
13 | check_origin: false,
14 | watchers: [
15 | node: [
16 | "node_modules/webpack/bin/webpack.js",
17 | "--mode",
18 | "development",
19 | "--watch-stdin",
20 | cd: Path.expand("../assets", __DIR__)
21 | ]
22 | ]
23 |
24 | # ## SSL Support
25 | #
26 | # In order to use HTTPS in development, a self-signed
27 | # certificate can be generated by running the following
28 | # Mix task:
29 | #
30 | # mix phx.gen.cert
31 | #
32 | # Note that this task requires Erlang/OTP 20 or later.
33 | # Run `mix help phx.gen.cert` for more information.
34 | #
35 | # The `http:` config above can be replaced with:
36 | #
37 | # https: [
38 | # port: 4001,
39 | # cipher_suite: :strong,
40 | # keyfile: "priv/cert/selfsigned_key.pem",
41 | # certfile: "priv/cert/selfsigned.pem"
42 | # ],
43 | #
44 | # If desired, both `http:` and `https:` keys can be
45 | # configured to run both http and https servers on
46 | # different ports.
47 |
48 | # Watch static and templates for browser reloading.
49 | config :poetic, PoeticWeb.Endpoint,
50 | live_reload: [
51 | patterns: [
52 | ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
53 | ~r{priv/gettext/.*(po)$},
54 | ~r{lib/poetic_web/views/.*(ex)$},
55 | ~r{lib/poetic_web/templates/.*(eex)$}
56 | ]
57 | ]
58 |
59 | # Do not include metadata nor timestamps in development logs
60 | config :logger, :console, format: "[$level] $message\n"
61 |
62 | # Set a higher stacktrace during development. Avoid configuring such
63 | # in production as building large stacktraces may be expensive.
64 | config :phoenix, :stacktrace_depth, 20
65 |
66 | # Initialize plugs at runtime for faster development compilation
67 | config :phoenix, :plug_init_mode, :runtime
68 |
69 | # Configure your database
70 | config :poetic, Poetic.Repo,
71 | username: "postgres",
72 | password: "postgres",
73 | database: "poetic_dev",
74 | hostname: "localhost",
75 | pool_size: 10
76 |
77 |
78 | config :poetic,
79 | uploads_directory: "/Users/alvise/uploads_dev"
80 |
--------------------------------------------------------------------------------
/assets/js/socket.js:
--------------------------------------------------------------------------------
1 | // NOTE: The contents of this file will only be executed if
2 | // you uncomment its entry in "assets/js/app.js".
3 |
4 | // To use Phoenix channels, the first step is to import Socket,
5 | // and connect at the socket path in "lib/web/endpoint.ex".
6 | //
7 | // Pass the token on params as below. Or remove it
8 | // from the params if you are not using authentication.
9 | import {Socket} from "phoenix"
10 |
11 | let socket = new Socket("/socket", {params: {token: window.userToken}})
12 |
13 | // When you connect, you'll often need to authenticate the client.
14 | // For example, imagine you have an authentication plug, `MyAuth`,
15 | // which authenticates the session and assigns a `:current_user`.
16 | // If the current user exists you can assign the user's token in
17 | // the connection for use in the layout.
18 | //
19 | // In your "lib/web/router.ex":
20 | //
21 | // pipeline :browser do
22 | // ...
23 | // plug MyAuth
24 | // plug :put_user_token
25 | // end
26 | //
27 | // defp put_user_token(conn, _) do
28 | // if current_user = conn.assigns[:current_user] do
29 | // token = Phoenix.Token.sign(conn, "user socket", current_user.id)
30 | // assign(conn, :user_token, token)
31 | // else
32 | // conn
33 | // end
34 | // end
35 | //
36 | // Now you need to pass this token to JavaScript. You can do so
37 | // inside a script tag in "lib/web/templates/layout/app.html.eex":
38 | //
39 | //
40 | //
41 | // You will need to verify the user token in the "connect/3" function
42 | // in "lib/web/channels/user_socket.ex":
43 | //
44 | // def connect(%{"token" => token}, socket, _connect_info) do
45 | // # max_age: 1209600 is equivalent to two weeks in seconds
46 | // case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
47 | // {:ok, user_id} ->
48 | // {:ok, assign(socket, :user, user_id)}
49 | // {:error, reason} ->
50 | // :error
51 | // end
52 | // end
53 | //
54 | // Finally, connect to the socket:
55 | socket.connect()
56 |
57 | // Now that you are connected, you can join channels with a topic:
58 | let channel = socket.channel("topic:subtopic", {})
59 | channel.join()
60 | .receive("ok", resp => { console.log("Joined successfully", resp) })
61 | .receive("error", resp => { console.log("Unable to join", resp) })
62 |
63 | export default socket
64 |
--------------------------------------------------------------------------------
/priv/gettext/en/LC_MESSAGES/errors.po:
--------------------------------------------------------------------------------
1 | ## `msgid`s in this file come from POT (.pot) files.
2 | ##
3 | ## Do not add, change, or remove `msgid`s manually here as
4 | ## they're tied to the ones in the corresponding POT file
5 | ## (with the same domain).
6 | ##
7 | ## Use `mix gettext.extract --merge` or `mix gettext.merge`
8 | ## to merge POT files into PO files.
9 | msgid ""
10 | msgstr ""
11 | "Language: en\n"
12 |
13 | ## From Ecto.Changeset.cast/4
14 | msgid "can't be blank"
15 | msgstr ""
16 |
17 | ## From Ecto.Changeset.unique_constraint/3
18 | msgid "has already been taken"
19 | msgstr ""
20 |
21 | ## From Ecto.Changeset.put_change/3
22 | msgid "is invalid"
23 | msgstr ""
24 |
25 | ## From Ecto.Changeset.validate_acceptance/3
26 | msgid "must be accepted"
27 | msgstr ""
28 |
29 | ## From Ecto.Changeset.validate_format/3
30 | msgid "has invalid format"
31 | msgstr ""
32 |
33 | ## From Ecto.Changeset.validate_subset/3
34 | msgid "has an invalid entry"
35 | msgstr ""
36 |
37 | ## From Ecto.Changeset.validate_exclusion/3
38 | msgid "is reserved"
39 | msgstr ""
40 |
41 | ## From Ecto.Changeset.validate_confirmation/3
42 | msgid "does not match confirmation"
43 | msgstr ""
44 |
45 | ## From Ecto.Changeset.no_assoc_constraint/3
46 | msgid "is still associated with this entry"
47 | msgstr ""
48 |
49 | msgid "are still associated with this entry"
50 | msgstr ""
51 |
52 | ## From Ecto.Changeset.validate_length/3
53 | msgid "should be %{count} character(s)"
54 | msgid_plural "should be %{count} character(s)"
55 | msgstr[0] ""
56 | msgstr[1] ""
57 |
58 | msgid "should have %{count} item(s)"
59 | msgid_plural "should have %{count} item(s)"
60 | msgstr[0] ""
61 | msgstr[1] ""
62 |
63 | msgid "should be at least %{count} character(s)"
64 | msgid_plural "should be at least %{count} character(s)"
65 | msgstr[0] ""
66 | msgstr[1] ""
67 |
68 | msgid "should have at least %{count} item(s)"
69 | msgid_plural "should have at least %{count} item(s)"
70 | msgstr[0] ""
71 | msgstr[1] ""
72 |
73 | msgid "should be at most %{count} character(s)"
74 | msgid_plural "should be at most %{count} character(s)"
75 | msgstr[0] ""
76 | msgstr[1] ""
77 |
78 | msgid "should have at most %{count} item(s)"
79 | msgid_plural "should have at most %{count} item(s)"
80 | msgstr[0] ""
81 | msgstr[1] ""
82 |
83 | ## From Ecto.Changeset.validate_number/3
84 | msgid "must be less than %{number}"
85 | msgstr ""
86 |
87 | msgid "must be greater than %{number}"
88 | msgstr ""
89 |
90 | msgid "must be less than or equal to %{number}"
91 | msgstr ""
92 |
93 | msgid "must be greater than or equal to %{number}"
94 | msgstr ""
95 |
96 | msgid "must be equal to %{number}"
97 | msgstr ""
98 |
--------------------------------------------------------------------------------
/priv/gettext/errors.pot:
--------------------------------------------------------------------------------
1 | ## This is a PO Template file.
2 | ##
3 | ## `msgid`s here are often extracted from source code.
4 | ## Add new translations manually only if they're dynamic
5 | ## translations that can't be statically extracted.
6 | ##
7 | ## Run `mix gettext.extract` to bring this file up to
8 | ## date. Leave `msgstr`s empty as changing them here has no
9 | ## effect: edit them in PO (`.po`) files instead.
10 |
11 | ## From Ecto.Changeset.cast/4
12 | msgid "can't be blank"
13 | msgstr ""
14 |
15 | ## From Ecto.Changeset.unique_constraint/3
16 | msgid "has already been taken"
17 | msgstr ""
18 |
19 | ## From Ecto.Changeset.put_change/3
20 | msgid "is invalid"
21 | msgstr ""
22 |
23 | ## From Ecto.Changeset.validate_acceptance/3
24 | msgid "must be accepted"
25 | msgstr ""
26 |
27 | ## From Ecto.Changeset.validate_format/3
28 | msgid "has invalid format"
29 | msgstr ""
30 |
31 | ## From Ecto.Changeset.validate_subset/3
32 | msgid "has an invalid entry"
33 | msgstr ""
34 |
35 | ## From Ecto.Changeset.validate_exclusion/3
36 | msgid "is reserved"
37 | msgstr ""
38 |
39 | ## From Ecto.Changeset.validate_confirmation/3
40 | msgid "does not match confirmation"
41 | msgstr ""
42 |
43 | ## From Ecto.Changeset.no_assoc_constraint/3
44 | msgid "is still associated with this entry"
45 | msgstr ""
46 |
47 | msgid "are still associated with this entry"
48 | msgstr ""
49 |
50 | ## From Ecto.Changeset.validate_length/3
51 | msgid "should be %{count} character(s)"
52 | msgid_plural "should be %{count} character(s)"
53 | msgstr[0] ""
54 | msgstr[1] ""
55 |
56 | msgid "should have %{count} item(s)"
57 | msgid_plural "should have %{count} item(s)"
58 | msgstr[0] ""
59 | msgstr[1] ""
60 |
61 | msgid "should be at least %{count} character(s)"
62 | msgid_plural "should be at least %{count} character(s)"
63 | msgstr[0] ""
64 | msgstr[1] ""
65 |
66 | msgid "should have at least %{count} item(s)"
67 | msgid_plural "should have at least %{count} item(s)"
68 | msgstr[0] ""
69 | msgstr[1] ""
70 |
71 | msgid "should be at most %{count} character(s)"
72 | msgid_plural "should be at most %{count} character(s)"
73 | msgstr[0] ""
74 | msgstr[1] ""
75 |
76 | msgid "should have at most %{count} item(s)"
77 | msgid_plural "should have at most %{count} item(s)"
78 | msgstr[0] ""
79 | msgstr[1] ""
80 |
81 | ## From Ecto.Changeset.validate_number/3
82 | msgid "must be less than %{number}"
83 | msgstr ""
84 |
85 | msgid "must be greater than %{number}"
86 | msgstr ""
87 |
88 | msgid "must be less than or equal to %{number}"
89 | msgstr ""
90 |
91 | msgid "must be greater than or equal to %{number}"
92 | msgstr ""
93 |
94 | msgid "must be equal to %{number}"
95 | msgstr ""
96 |
--------------------------------------------------------------------------------
/config/prod.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # For production, don't forget to configure the url host
4 | # to something meaningful, Phoenix uses this information
5 | # when generating URLs.
6 | #
7 | # Note we also include the path to a cache manifest
8 | # containing the digested version of static files. This
9 | # manifest is generated by the `mix phx.digest` task,
10 | # which you should run after static files are built and
11 | # before starting your production server.
12 | config :poetic, PoeticWeb.Endpoint,
13 | http: [:inet6, port: System.get_env("PORT") || 4000],
14 | url: [host: "example.com", port: 80],
15 | cache_static_manifest: "priv/static/cache_manifest.json"
16 |
17 | # Do not print debug messages in production
18 | config :logger, level: :info
19 |
20 | # ## SSL Support
21 | #
22 | # To get SSL working, you will need to add the `https` key
23 | # to the previous section and set your `:url` port to 443:
24 | #
25 | # config :poetic, PoeticWeb.Endpoint,
26 | # ...
27 | # url: [host: "example.com", port: 443],
28 | # https: [
29 | # :inet6,
30 | # port: 443,
31 | # cipher_suite: :strong,
32 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
33 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
34 | # ]
35 | #
36 | # The `cipher_suite` is set to `:strong` to support only the
37 | # latest and more secure SSL ciphers. This means old browsers
38 | # and clients may not be supported. You can set it to
39 | # `:compatible` for wider support.
40 | #
41 | # `:keyfile` and `:certfile` expect an absolute path to the key
42 | # and cert in disk or a relative path inside priv, for example
43 | # "priv/ssl/server.key". For all supported SSL configuration
44 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
45 | #
46 | # We also recommend setting `force_ssl` in your endpoint, ensuring
47 | # no data is ever sent via http, always redirecting to https:
48 | #
49 | # config :poetic, PoeticWeb.Endpoint,
50 | # force_ssl: [hsts: true]
51 | #
52 | # Check `Plug.SSL` for all available options in `force_ssl`.
53 |
54 | # ## Using releases (distillery)
55 | #
56 | # If you are doing OTP releases, you need to instruct Phoenix
57 | # to start the server for all endpoints:
58 | #
59 | # config :phoenix, :serve_endpoints, true
60 | #
61 | # Alternatively, you can configure exactly which server to
62 | # start per endpoint:
63 | #
64 | # config :poetic, PoeticWeb.Endpoint, server: true
65 | #
66 | # Note you can't rely on `System.get_env/1` when using releases.
67 | # See the releases documentation accordingly.
68 |
69 | # Finally import the config/prod.secret.exs which should be versioned
70 | # separately.
71 | import_config "prod.secret.exs"
72 |
--------------------------------------------------------------------------------
/lib/poetic/documents/upload.ex:
--------------------------------------------------------------------------------
1 | defmodule Poetic.Documents.Upload do
2 | use Ecto.Schema
3 | import Ecto.Changeset
4 |
5 | def upload_directory do
6 | Application.get_env(:poetic, :uploads_directory)
7 | end
8 |
9 | schema "uploads" do
10 | field :content_type, :string
11 | field :filename, :string
12 | field :hash, :string
13 | field :size, :integer
14 | field :thumbnail?, :boolean, source: :has_thumb
15 |
16 | timestamps()
17 | end
18 |
19 | @doc false
20 | def changeset(upload, attrs) do
21 | upload
22 | |> cast(attrs, [:filename, :size, :content_type, :hash, :thumbnail?])
23 | |> validate_required([:filename, :size, :content_type, :hash])
24 | #doesn't allow empty files
25 | |> validate_number(:size, greater_than: 0)
26 | |> validate_length(:hash, is: 64)
27 | end
28 |
29 | def sha256(enum) do
30 | enum
31 | |> Enum.reduce(:crypto.hash_init(:sha256),&(:crypto.hash_update(&2, &1)))
32 | |> :crypto.hash_final()
33 | |> Base.encode16()
34 | |> String.downcase()
35 | end
36 |
37 | def local_path(id, filename) do
38 | [upload_directory(), "#{id}-#{filename}"]
39 | |> Path.join()
40 | end
41 |
42 |
43 | def thumbnail_path(id) do
44 | [upload_directory(), "thumb-#{id}.jpg"]
45 | |> Path.join()
46 | end
47 |
48 | def create_thumbnail(%__MODULE__{content_type: "image/" <> _img_type}=upload) do
49 | original_path = local_path(upload.id, upload.filename)
50 | thumb_path = thumbnail_path(upload.id)
51 | {:ok, _} = mogrify_thumbnail(original_path, thumb_path)
52 | changeset(upload, %{thumbnail?: true})
53 | end
54 |
55 | def create_thumbnail(%__MODULE__{content_type: "application/pdf"}=upload) do
56 | original_path = local_path(upload.id, upload.filename)
57 | thumb_path = thumbnail_path(upload.id)
58 | {:ok, _} = pdf_thumbnail(original_path, thumb_path)
59 | changeset(upload, %{thumbnail?: true})
60 | end
61 |
62 |
63 | def create_thumbnail(%__MODULE__{}=upload), do: changeset(upload, %{})
64 |
65 | def mogrify_thumbnail(src_path, dst_path) do
66 | try do
67 | Mogrify.open(src_path)
68 | |> Mogrify.resize_to_limit("300x300")
69 | |> Mogrify.save(path: dst_path)
70 | rescue
71 | File.Error -> {:error, :invalid_src_path}
72 | error -> {:error, error}
73 | else
74 | _image -> {:ok, dst_path}
75 | end
76 | end
77 |
78 | def pdf_thumbnail(pdf_path, thumb_path) do
79 | args = ["-density", "300", "-resize",
80 | "300x300","#{pdf_path}[0]",
81 | thumb_path]
82 |
83 | case System.cmd("convert", args, stderr_to_stdout: true) do
84 | {_, 0} -> {:ok, thumb_path}
85 | {reason, _} -> {:error, reason}
86 | end
87 |
88 | end
89 |
90 |
91 | end
92 |
--------------------------------------------------------------------------------
/mix.lock:
--------------------------------------------------------------------------------
1 | %{
2 | "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
3 | "cowboy": {:hex, :cowboy, "2.6.3", "99aa50e94e685557cad82e704457336a453d4abcb77839ad22dbe71f311fcc06", [:rebar3], [{:cowlib, "~> 2.7.3", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
4 | "cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
5 | "db_connection": {:hex, :db_connection, "2.0.6", "bde2f85d047969c5b5800cb8f4b3ed6316c8cb11487afedac4aa5f93fd39abfa", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
6 | "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
7 | "ecto": {:hex, :ecto, "3.1.1", "d6677f95f1e0bd39bc3db3db6b23a59977cb154ed2cceec69a56becd805128be", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
8 | "ecto_sql": {:hex, :ecto_sql, "3.1.0", "20d773799db0ed112dc4109305df679f1c8b0a59cf75e6d15ee05656af5bd708", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
9 | "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
10 | "gettext": {:hex, :gettext, "0.16.1", "e2130b25eebcbe02bb343b119a07ae2c7e28bd4b146c4a154da2ffb2b3507af2", [:mix], [], "hexpm"},
11 | "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
12 | "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
13 | "mogrify": {:hex, :mogrify, "0.7.2", "4d00b60288e338028e2af4cccff9b0da365d83b7e5da52e58fb2de513ef5fedd", [:mix], [], "hexpm"},
14 | "phoenix": {:hex, :phoenix, "1.4.3", "8eed4a64ff1e12372cd634724bddd69185938f52c18e1396ebac76375d85677d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
15 | "phoenix_ecto": {:hex, :phoenix_ecto, "4.0.0", "c43117a136e7399ea04ecaac73f8f23ee0ffe3e07acfcb8062fe5f4c9f0f6531", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
16 | "phoenix_html": {:hex, :phoenix_html, "2.13.2", "f5d27c9b10ce881a60177d2b5227314fc60881e6b66b41dfe3349db6ed06cf57", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
17 | "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.0", "3bb31a9fbd40ffe8652e60c8660dffd72dd231efcdf49b744fb75b9ef7db5dd2", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
18 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm"},
19 | "plug": {:hex, :plug, "1.8.0", "9d2685cb007fe5e28ed9ac27af2815bc262b7817a00929ac10f56f169f43b977", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"},
20 | "plug_cowboy": {:hex, :plug_cowboy, "2.0.2", "6055f16868cc4882b24b6e1d63d2bada94fb4978413377a3b32ac16c18dffba2", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
21 | "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
22 | "postgrex": {:hex, :postgrex, "0.14.2", "6680591bbce28d92f043249205e8b01b36cab9ef2a7911abc43649242e1a3b78", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
23 | "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
24 | "telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
25 | }
26 |
--------------------------------------------------------------------------------
/assets/css/phoenix.css:
--------------------------------------------------------------------------------
1 | /* Includes some default style for the starter application.
2 | * This can be safely deleted to start fresh.
3 | */
4 |
5 | /* Milligram v1.3.0 https://milligram.github.io
6 | * Copyright (c) 2017 CJ Patoilo Licensed under the MIT license
7 | */
8 |
9 | *,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='email'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem;width:100%}input[type='email']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{-ms-grid-row-align:center;align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem;text-align:left}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right}
10 |
11 | /* General style */
12 | h1{font-size: 3.6rem; line-height: 1.25}
13 | h2{font-size: 2.8rem; line-height: 1.3}
14 | h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35}
15 | h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5}
16 | h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4}
17 | h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2}
18 |
19 | .container{
20 | margin: 0 auto;
21 | max-width: 80.0rem;
22 | padding: 0 2.0rem;
23 | position: relative;
24 | width: 100%
25 | }
26 | select {
27 | width: auto;
28 | }
29 |
30 | /* Alerts and form errors */
31 | .alert {
32 | padding: 15px;
33 | margin-bottom: 20px;
34 | border: 1px solid transparent;
35 | border-radius: 4px;
36 | }
37 | .alert-info {
38 | color: #31708f;
39 | background-color: #d9edf7;
40 | border-color: #bce8f1;
41 | }
42 | .alert-warning {
43 | color: #8a6d3b;
44 | background-color: #fcf8e3;
45 | border-color: #faebcc;
46 | }
47 | .alert-danger {
48 | color: #a94442;
49 | background-color: #f2dede;
50 | border-color: #ebccd1;
51 | }
52 | .alert p {
53 | margin-bottom: 0;
54 | }
55 | .alert:empty {
56 | display: none;
57 | }
58 | .help-block {
59 | color: #a94442;
60 | display: block;
61 | margin: -1rem 0 2rem;
62 | }
63 |
64 | /* Phoenix promo and logo */
65 | .phx-hero {
66 | text-align: center;
67 | border-bottom: 1px solid #e3e3e3;
68 | background: #eee;
69 | border-radius: 6px;
70 | padding: 3em;
71 | margin-bottom: 3rem;
72 | font-weight: 200;
73 | font-size: 120%;
74 | }
75 | .phx-hero p {
76 | margin: 0;
77 | }
78 | .phx-logo {
79 | min-width: 300px;
80 | margin: 1rem;
81 | display: block;
82 | }
83 | .phx-logo img {
84 | width: auto;
85 | display: block;
86 | }
87 |
88 | /* Headers */
89 | header {
90 | width: 100%;
91 | background: #fdfdfd;
92 | border-bottom: 1px solid #eaeaea;
93 | margin-bottom: 2rem;
94 | }
95 | header section {
96 | align-items: center;
97 | display: flex;
98 | flex-direction: column;
99 | justify-content: space-between;
100 | }
101 | header section :first-child {
102 | order: 2;
103 | }
104 | header section :last-child {
105 | order: 1;
106 | }
107 | header nav ul,
108 | header nav li {
109 | margin: 0;
110 | padding: 0;
111 | display: block;
112 | text-align: right;
113 | white-space: nowrap;
114 | }
115 | header nav ul {
116 | margin: 1rem;
117 | margin-top: 0;
118 | }
119 | header nav a {
120 | display: block;
121 | }
122 |
123 | @media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */
124 | header section {
125 | flex-direction: row;
126 | }
127 | header nav ul {
128 | margin: 1rem;
129 | }
130 | .phx-logo {
131 | flex-basis: 527px;
132 | margin: 2rem 1rem;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------