├── lib
├── chat_web
│ ├── views
│ │ ├── page_view.ex
│ │ ├── layout_view.ex
│ │ ├── error_view.ex
│ │ └── error_helpers.ex
│ ├── controllers
│ │ └── page_controller.ex
│ ├── templates
│ │ ├── page
│ │ │ └── index.html.eex
│ │ └── layout
│ │ │ └── app.html.eex
│ ├── channels
│ │ ├── water_cooler_channel.ex
│ │ └── user_socket.ex
│ ├── router.ex
│ ├── gettext.ex
│ └── endpoint.ex
├── chat.ex
├── chat
│ ├── repo.ex
│ ├── chats
│ │ ├── message.ex
│ │ └── chats.ex
│ └── application.ex
└── chat_web.ex
├── test
├── test_helper.exs
├── chat_web
│ ├── views
│ │ ├── layout_view_test.exs
│ │ ├── page_view_test.exs
│ │ └── error_view_test.exs
│ ├── controllers
│ │ └── page_controller_test.exs
│ └── channels
│ │ └── water_cooler_channel_test.exs
├── support
│ ├── channel_case.ex
│ ├── conn_case.ex
│ └── data_case.ex
└── chat
│ └── chats
│ └── chats_test.exs
├── assets
├── static
│ ├── favicon.ico
│ ├── images
│ │ └── phoenix.png
│ └── robots.txt
├── package.json
├── js
│ ├── app.js
│ ├── water_cooler.js
│ └── socket.js
├── brunch-config.js
└── css
│ └── app.css
├── priv
├── repo
│ ├── migrations
│ │ └── 20180318184738_create_messages.exs
│ └── seeds.exs
└── gettext
│ ├── en
│ └── LC_MESSAGES
│ │ └── errors.po
│ └── errors.pot
├── config
├── test.exs
├── config.exs
├── dev.exs
└── prod.exs
├── .gitignore
├── README.md
├── mix.exs
└── mix.lock
/lib/chat_web/views/page_view.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.PageView do
2 | use ChatWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/lib/chat_web/views/layout_view.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.LayoutView do
2 | use ChatWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/test/test_helper.exs:
--------------------------------------------------------------------------------
1 | ExUnit.start()
2 |
3 | Ecto.Adapters.SQL.Sandbox.mode(Chat.Repo, :manual)
4 |
5 |
--------------------------------------------------------------------------------
/assets/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixircastsio/038-chat-app-in-8-minutes/HEAD/assets/static/favicon.ico
--------------------------------------------------------------------------------
/test/chat_web/views/layout_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.LayoutViewTest do
2 | use ChatWeb.ConnCase, async: true
3 | end
4 |
--------------------------------------------------------------------------------
/test/chat_web/views/page_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.PageViewTest do
2 | use ChatWeb.ConnCase, async: true
3 | end
4 |
--------------------------------------------------------------------------------
/assets/static/images/phoenix.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixircastsio/038-chat-app-in-8-minutes/HEAD/assets/static/images/phoenix.png
--------------------------------------------------------------------------------
/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/chat_web/controllers/page_controller_test.exs:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.PageControllerTest do
2 | use ChatWeb.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 |
--------------------------------------------------------------------------------
/lib/chat.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat do
2 | @moduledoc """
3 | Chat 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 |
--------------------------------------------------------------------------------
/lib/chat_web/controllers/page_controller.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.PageController do
2 | use ChatWeb, :controller
3 |
4 | alias Chat.Chats
5 |
6 | def index(conn, _params) do
7 | messages = Chats.list_messages()
8 | render conn, "index.html", messages: messages
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/priv/repo/migrations/20180318184738_create_messages.exs:
--------------------------------------------------------------------------------
1 | defmodule Chat.Repo.Migrations.CreateMessages do
2 | use Ecto.Migration
3 |
4 | def change do
5 | create table(:messages) do
6 | add :name, :string
7 | add :body, :text
8 |
9 | timestamps()
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/chat/repo.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat.Repo do
2 | use Ecto.Repo, otp_app: :chat
3 |
4 | @doc """
5 | Dynamically loads the repository url from the
6 | DATABASE_URL environment variable.
7 | """
8 | def init(_, opts) do
9 | {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/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 | # Chat.Repo.insert!(%Chat.SomeSchema{})
9 | #
10 | # We recommend using the bang functions (`insert!`, `update!`
11 | # and so on) as they will fail if something goes wrong.
12 |
--------------------------------------------------------------------------------
/lib/chat/chats/message.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat.Chats.Message do
2 | use Ecto.Schema
3 | import Ecto.Changeset
4 |
5 |
6 | schema "messages" do
7 | field :body, :string
8 | field :name, :string
9 |
10 | timestamps()
11 | end
12 |
13 | @doc false
14 | def changeset(message, attrs) do
15 | message
16 | |> cast(attrs, [:name, :body])
17 | |> validate_required([:name, :body])
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/chat_web/templates/page/index.html.eex:
--------------------------------------------------------------------------------
1 |
The Water Cooler
2 |
3 | <%= for message <- @messages do %>
4 |
<%= message.name %>: <%= message.body %>
5 | <% end %>
6 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/lib/chat_web/views/error_view.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.ErrorView do
2 | use ChatWeb, :view
3 |
4 | def render("404.html", _assigns) do
5 | "Page not found"
6 | end
7 |
8 | def render("500.html", _assigns) do
9 | "Internal server error"
10 | end
11 |
12 | # In case no render clause matches or no
13 | # template is found, let's render it as 500
14 | def template_not_found(_template, assigns) do
15 | render "500.html", assigns
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "repository": {},
3 | "license": "MIT",
4 | "scripts": {
5 | "deploy": "brunch build --production",
6 | "watch": "brunch watch --stdin"
7 | },
8 | "dependencies": {
9 | "phoenix": "file:../deps/phoenix",
10 | "phoenix_html": "file:../deps/phoenix_html"
11 | },
12 | "devDependencies": {
13 | "babel-brunch": "6.1.1",
14 | "brunch": "2.10.9",
15 | "clean-css-brunch": "2.10.0",
16 | "uglify-js-brunch": "2.10.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lib/chat_web/channels/water_cooler_channel.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.WaterCoolerChannel do
2 | use ChatWeb, :channel
3 |
4 | alias Chat.Chats
5 |
6 | def join("water_cooler:lobby", _payload, socket) do
7 | {:ok, socket}
8 | end
9 |
10 | # It is also common to receive messages from the client and
11 | # broadcast to everyone in the current topic (water_cooler:lobby).
12 | def handle_in("shout", payload, socket) do
13 | Chats.create_message(payload)
14 | broadcast socket, "shout", payload
15 | {:noreply, socket}
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/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 :chat, ChatWeb.Endpoint,
6 | http: [port: 4001],
7 | server: false
8 |
9 | # Print only warnings and errors during test
10 | config :logger, level: :warn
11 |
12 | # Configure your database
13 | config :chat, Chat.Repo,
14 | adapter: Ecto.Adapters.Postgres,
15 | username: "postgres",
16 | password: "postgres",
17 | database: "chat_test",
18 | hostname: "localhost",
19 | pool: Ecto.Adapters.SQL.Sandbox
20 |
--------------------------------------------------------------------------------
/lib/chat_web/router.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.Router do
2 | use ChatWeb, :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 "/", ChatWeb do
17 | pipe_through :browser # Use the default browser stack
18 |
19 | get "/", PageController, :index
20 | end
21 |
22 | # Other scopes may use custom stacks.
23 | # scope "/api", ChatWeb do
24 | # pipe_through :api
25 | # end
26 | end
27 |
--------------------------------------------------------------------------------
/test/chat_web/views/error_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.ErrorViewTest do
2 | use ChatWeb.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(ChatWeb.ErrorView, "404.html", []) ==
9 | "Page not found"
10 | end
11 |
12 | test "render 500.html" do
13 | assert render_to_string(ChatWeb.ErrorView, "500.html", []) ==
14 | "Internal server error"
15 | end
16 |
17 | test "render any other" do
18 | assert render_to_string(ChatWeb.ErrorView, "505.html", []) ==
19 | "Internal server error"
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # App artifacts
2 | /_build
3 | /db
4 | /deps
5 | /*.ez
6 |
7 | # Generated on crash by the VM
8 | erl_crash.dump
9 |
10 | # Generated on crash by NPM
11 | npm-debug.log
12 |
13 | # Static artifacts
14 | /assets/node_modules
15 |
16 | # Since we are building assets from assets/,
17 | # we ignore priv/static. You may want to comment
18 | # this depending on your deployment strategy.
19 | /priv/static/
20 |
21 | # Files matching config/*.secret.exs pattern contain sensitive
22 | # data and you should not commit them into version control.
23 | #
24 | # Alternatively, you may comment the line below and commit the
25 | # secrets files as long as you replace their contents by environment
26 | # variables.
27 | /config/*.secret.exs
--------------------------------------------------------------------------------
/lib/chat_web/gettext.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.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 ChatWeb.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: :chat
24 | end
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chat
2 |
3 | To start your Phoenix server:
4 |
5 | * Install dependencies with `mix deps.get`
6 | * Create and migrate your database with `mix ecto.create && mix ecto.migrate`
7 | * Install Node.js dependencies with `cd assets && npm install`
8 | * Start Phoenix endpoint with `mix phx.server`
9 |
10 | Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
11 |
12 | Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).
13 |
14 | ## Learn more
15 |
16 | * Official website: http://www.phoenixframework.org/
17 | * Guides: http://phoenixframework.org/docs/overview
18 | * Docs: https://hexdocs.pm/phoenix
19 | * Mailing list: http://groups.google.com/group/phoenix-talk
20 | * Source: https://github.com/phoenixframework/phoenix
21 |
--------------------------------------------------------------------------------
/assets/js/app.js:
--------------------------------------------------------------------------------
1 | // Brunch automatically concatenates all files in your
2 | // watched paths. Those paths can be configured at
3 | // config.paths.watched in "brunch-config.js".
4 | //
5 | // However, those files will only be executed if
6 | // explicitly imported. The only exception are files
7 | // in vendor, which are never wrapped in imports and
8 | // therefore are always executed.
9 |
10 | // Import dependencies
11 | //
12 | // If you no longer want to use a dependency, remember
13 | // to also remove its path from "config.paths.watched".
14 | import "phoenix_html"
15 |
16 | // Import local files
17 | //
18 | // Local files can be imported directly using relative
19 | // paths "./socket" or full ones "web/static/js/socket".
20 |
21 | import socket from "./socket"
22 | import WaterCooler from "./water_cooler"
23 |
24 | WaterCooler.init(socket)
25 |
--------------------------------------------------------------------------------
/lib/chat_web/templates/layout/app.html.eex:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | Hello Chat!
11 | ">
12 |
13 |
14 |
15 |
16 |
17 |
<%= get_flash(@conn, :info) %>
18 |
<%= get_flash(@conn, :error) %>
19 |
20 |
21 | <%= render @view_module, @view_template, assigns %>
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/test/chat_web/channels/water_cooler_channel_test.exs:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.WaterCoolerChannelTest do
2 | use ChatWeb.ChannelCase
3 |
4 | alias ChatWeb.WaterCoolerChannel
5 |
6 | setup do
7 | {:ok, _, socket} =
8 | socket("user_id", %{some: :assign})
9 | |> subscribe_and_join(WaterCoolerChannel, "water_cooler:lobby")
10 |
11 | {:ok, socket: socket}
12 | end
13 |
14 | test "ping replies with status ok", %{socket: socket} do
15 | ref = push socket, "ping", %{"hello" => "there"}
16 | assert_reply ref, :ok, %{"hello" => "there"}
17 | end
18 |
19 | test "shout broadcasts to water_cooler:lobby", %{socket: socket} do
20 | push socket, "shout", %{"hello" => "all"}
21 | assert_broadcast "shout", %{"hello" => "all"}
22 | end
23 |
24 | test "broadcasts are pushed to the client", %{socket: socket} do
25 | broadcast_from! socket, "broadcast", %{"some" => "data"}
26 | assert_push "broadcast", %{"some" => "data"}
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/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 | use Mix.Config
7 |
8 | # General application configuration
9 | config :chat,
10 | ecto_repos: [Chat.Repo]
11 |
12 | # Configures the endpoint
13 | config :chat, ChatWeb.Endpoint,
14 | url: [host: "localhost"],
15 | secret_key_base: "B7HE27jtI+k0d6B3QtLmJjnjC6PP6e+e0wyVppUKcjyV6ZX+PIGB+4E3Gi1f4+kY",
16 | render_errors: [view: ChatWeb.ErrorView, accepts: ~w(html json)],
17 | pubsub: [name: Chat.PubSub,
18 | 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 | # Import environment specific config. This must remain at the bottom
26 | # of this file so it overrides the configuration defined above.
27 | import_config "#{Mix.env}.exs"
28 |
--------------------------------------------------------------------------------
/assets/js/water_cooler.js:
--------------------------------------------------------------------------------
1 | let WaterCooler = {
2 | init(socket) {
3 | let channel = socket.channel('water_cooler:lobby', {})
4 | channel.join()
5 | this.listenForChats(channel)
6 | },
7 |
8 | listenForChats(channel) {
9 | document.getElementById('chat-form').addEventListener('submit', function(e){
10 | e.preventDefault()
11 |
12 | let userName = document.getElementById('user-name').value
13 | let userMsg = document.getElementById('user-msg').value
14 |
15 | channel.push('shout', {name: userName, body: userMsg})
16 |
17 | document.getElementById('user-name').value = ''
18 | document.getElementById('user-msg').value = ''
19 | })
20 |
21 | channel.on('shout', payload => {
22 | let chatBox = document.querySelector('#chat-box')
23 | let msgBlock = document.createElement('p')
24 |
25 | msgBlock.insertAdjacentHTML('beforeend', `${payload.name}: ${payload.body}`)
26 | chatBox.appendChild(msgBlock)
27 | })
28 | }
29 | }
30 |
31 | export default WaterCooler
32 |
--------------------------------------------------------------------------------
/test/support/channel_case.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.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 datastructures 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 ChatWeb.Endpoint
25 | end
26 | end
27 |
28 |
29 | setup tags do
30 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Chat.Repo)
31 | unless tags[:async] do
32 | Ecto.Adapters.SQL.Sandbox.mode(Chat.Repo, {:shared, self()})
33 | end
34 | :ok
35 | end
36 |
37 | end
38 |
--------------------------------------------------------------------------------
/lib/chat/application.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat.Application do
2 | use Application
3 |
4 | # See https://hexdocs.pm/elixir/Application.html
5 | # for more information on OTP Applications
6 | def start(_type, _args) do
7 | import Supervisor.Spec
8 |
9 | # Define workers and child supervisors to be supervised
10 | children = [
11 | # Start the Ecto repository
12 | supervisor(Chat.Repo, []),
13 | # Start the endpoint when the application starts
14 | supervisor(ChatWeb.Endpoint, []),
15 | # Start your own worker by calling: Chat.Worker.start_link(arg1, arg2, arg3)
16 | # worker(Chat.Worker, [arg1, arg2, arg3]),
17 | ]
18 |
19 | # See https://hexdocs.pm/elixir/Supervisor.html
20 | # for other strategies and supported options
21 | opts = [strategy: :one_for_one, name: Chat.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 | ChatWeb.Endpoint.config_change(changed, removed)
29 | :ok
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/test/support/conn_case.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.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 datastructures 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 | import ChatWeb.Router.Helpers
23 |
24 | # The default endpoint for testing
25 | @endpoint ChatWeb.Endpoint
26 | end
27 | end
28 |
29 |
30 | setup tags do
31 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Chat.Repo)
32 | unless tags[:async] do
33 | Ecto.Adapters.SQL.Sandbox.mode(Chat.Repo, {:shared, self()})
34 | end
35 | {:ok, conn: Phoenix.ConnTest.build_conn()}
36 | end
37 |
38 | end
39 |
--------------------------------------------------------------------------------
/lib/chat_web/channels/user_socket.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.UserSocket do
2 | use Phoenix.Socket
3 |
4 | ## Channels
5 | # channel "room:*", ChatWeb.RoomChannel
6 | channel "water_cooler:*", ChatWeb.WaterCoolerChannel
7 |
8 | ## Transports
9 | transport :websocket, Phoenix.Transports.WebSocket
10 | # transport :longpoll, Phoenix.Transports.LongPoll
11 |
12 | # Socket params are passed from the client and can
13 | # be used to verify and authenticate a user. After
14 | # verification, you can put default assigns into
15 | # the socket that will be set for all channels, ie
16 | #
17 | # {:ok, assign(socket, :user_id, verified_user_id)}
18 | #
19 | # To deny connection, return `:error`.
20 | #
21 | # See `Phoenix.Token` documentation for examples in
22 | # performing token verification on connect.
23 | def connect(_params, socket) do
24 | {:ok, socket}
25 | end
26 |
27 | # Socket id's are topics that allow you to identify all sockets for a given user:
28 | #
29 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
30 | #
31 | # Would allow you to broadcast a "disconnect" event and terminate
32 | # all active sockets and channels for a given user:
33 | #
34 | # ChatWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
35 | #
36 | # Returning `nil` makes this socket anonymous.
37 | def id(_socket), do: nil
38 | end
39 |
--------------------------------------------------------------------------------
/lib/chat_web/views/error_helpers.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.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 | # Because error messages were defined within Ecto, we must
22 | # call the Gettext module passing our Gettext backend. We
23 | # also use the "errors" domain as translations are placed
24 | # in the errors.po file.
25 | # Ecto will pass the :count keyword if the error message is
26 | # meant to be pluralized.
27 | # On your own code and templates, depending on whether you
28 | # need the message to be pluralized or not, this could be
29 | # written simply as:
30 | #
31 | # dngettext "errors", "1 file", "%{count} files", count
32 | # dgettext "errors", "is invalid"
33 | #
34 | if count = opts[:count] do
35 | Gettext.dngettext(ChatWeb.Gettext, "errors", msg, msg, count, opts)
36 | else
37 | Gettext.dgettext(ChatWeb.Gettext, "errors", msg, opts)
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/test/support/data_case.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat.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 Chat.Repo
20 |
21 | import Ecto
22 | import Ecto.Changeset
23 | import Ecto.Query
24 | import Chat.DataCase
25 | end
26 | end
27 |
28 | setup tags do
29 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Chat.Repo)
30 |
31 | unless tags[:async] do
32 | Ecto.Adapters.SQL.Sandbox.mode(Chat.Repo, {:shared, self()})
33 | end
34 |
35 | :ok
36 | end
37 |
38 | @doc """
39 | A helper that transform changeset errors to 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 |
--------------------------------------------------------------------------------
/assets/brunch-config.js:
--------------------------------------------------------------------------------
1 | exports.config = {
2 | // See http://brunch.io/#documentation for docs.
3 | files: {
4 | javascripts: {
5 | joinTo: "js/app.js"
6 |
7 | // To use a separate vendor.js bundle, specify two files path
8 | // http://brunch.io/docs/config#-files-
9 | // joinTo: {
10 | // "js/app.js": /^js/,
11 | // "js/vendor.js": /^(?!js)/
12 | // }
13 | //
14 | // To change the order of concatenation of files, explicitly mention here
15 | // order: {
16 | // before: [
17 | // "vendor/js/jquery-2.1.1.js",
18 | // "vendor/js/bootstrap.min.js"
19 | // ]
20 | // }
21 | },
22 | stylesheets: {
23 | joinTo: "css/app.css"
24 | },
25 | templates: {
26 | joinTo: "js/app.js"
27 | }
28 | },
29 |
30 | conventions: {
31 | // This option sets where we should place non-css and non-js assets in.
32 | // By default, we set this to "/assets/static". Files in this directory
33 | // will be copied to `paths.public`, which is "priv/static" by default.
34 | assets: /^(static)/
35 | },
36 |
37 | // Phoenix paths configuration
38 | paths: {
39 | // Dependencies and current project directories to watch
40 | watched: ["static", "css", "js", "vendor"],
41 | // Where to compile files to
42 | public: "../priv/static"
43 | },
44 |
45 | // Configure your plugins
46 | plugins: {
47 | babel: {
48 | // Do not use ES6 compiler in vendor code
49 | ignore: [/vendor/]
50 | }
51 | },
52 |
53 | modules: {
54 | autoRequire: {
55 | "js/app.js": ["js/app"]
56 | }
57 | },
58 |
59 | npm: {
60 | enabled: true
61 | }
62 | };
63 |
--------------------------------------------------------------------------------
/mix.exs:
--------------------------------------------------------------------------------
1 | defmodule Chat.Mixfile do
2 | use Mix.Project
3 |
4 | def project do
5 | [
6 | app: :chat,
7 | version: "0.0.1",
8 | elixir: "~> 1.4",
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: {Chat.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.3.0"},
37 | {:phoenix_pubsub, "~> 1.0"},
38 | {:phoenix_ecto, "~> 3.2"},
39 | {:postgrex, ">= 0.0.0"},
40 | {:phoenix_html, "~> 2.10"},
41 | {:phoenix_live_reload, "~> 1.0", only: :dev},
42 | {:gettext, "~> 0.11"},
43 | {:cowboy, "~> 1.0"}
44 | ]
45 | end
46 |
47 | # Aliases are shortcuts or tasks specific to the current project.
48 | # For example, to create, migrate and run the seeds file at once:
49 | #
50 | # $ mix ecto.setup
51 | #
52 | # See the documentation for `Mix` for more info on aliases.
53 | defp aliases do
54 | [
55 | "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
56 | "ecto.reset": ["ecto.drop", "ecto.setup"],
57 | "test": ["ecto.create --quiet", "ecto.migrate", "test"]
58 | ]
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/lib/chat_web.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb 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 ChatWeb, :controller
9 | use ChatWeb, :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: ChatWeb
23 | import Plug.Conn
24 | import ChatWeb.Router.Helpers
25 | import ChatWeb.Gettext
26 | end
27 | end
28 |
29 | def view do
30 | quote do
31 | use Phoenix.View, root: "lib/chat_web/templates",
32 | namespace: ChatWeb
33 |
34 | # Import convenience functions from controllers
35 | import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
36 |
37 | # Use all HTML functionality (forms, tags, etc)
38 | use Phoenix.HTML
39 |
40 | import ChatWeb.Router.Helpers
41 | import ChatWeb.ErrorHelpers
42 | import ChatWeb.Gettext
43 | end
44 | end
45 |
46 | def router do
47 | quote do
48 | use Phoenix.Router
49 | import Plug.Conn
50 | import Phoenix.Controller
51 | end
52 | end
53 |
54 | def channel do
55 | quote do
56 | use Phoenix.Channel
57 | import ChatWeb.Gettext
58 | end
59 | end
60 |
61 | @doc """
62 | When used, dispatch to the appropriate controller/view/etc.
63 | """
64 | defmacro __using__(which) when is_atom(which) do
65 | apply(__MODULE__, which, [])
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/lib/chat_web/endpoint.ex:
--------------------------------------------------------------------------------
1 | defmodule ChatWeb.Endpoint do
2 | use Phoenix.Endpoint, otp_app: :chat
3 |
4 | socket "/socket", ChatWeb.UserSocket
5 |
6 | # Serve at "/" the static files from "priv/static" directory.
7 | #
8 | # You should set gzip to true if you are running phoenix.digest
9 | # when deploying your static files in production.
10 | plug Plug.Static,
11 | at: "/", from: :chat, gzip: false,
12 | only: ~w(css fonts images js favicon.ico robots.txt)
13 |
14 | # Code reloading can be explicitly enabled under the
15 | # :code_reloader configuration of your endpoint.
16 | if code_reloading? do
17 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
18 | plug Phoenix.LiveReloader
19 | plug Phoenix.CodeReloader
20 | end
21 |
22 | plug Plug.RequestId
23 | plug Plug.Logger
24 |
25 | plug Plug.Parsers,
26 | parsers: [:urlencoded, :multipart, :json],
27 | pass: ["*/*"],
28 | json_decoder: Poison
29 |
30 | plug Plug.MethodOverride
31 | plug Plug.Head
32 |
33 | # The session will be stored in the cookie and signed,
34 | # this means its contents can be read but not tampered with.
35 | # Set :encryption_salt if you would also like to encrypt it.
36 | plug Plug.Session,
37 | store: :cookie,
38 | key: "_chat_key",
39 | signing_salt: "XfSsKWp6"
40 |
41 | plug ChatWeb.Router
42 |
43 | @doc """
44 | Callback invoked for dynamically configuring the endpoint.
45 |
46 | It receives the endpoint configuration and checks if
47 | configuration should be loaded from the system environment.
48 | """
49 | def init(_key, config) do
50 | if config[:load_from_system_env] do
51 | port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
52 | {:ok, Keyword.put(config, :http, [:inet6, port: port])}
53 | else
54 | {:ok, config}
55 | end
56 | end
57 | end
58 |
--------------------------------------------------------------------------------
/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 brunch.io to recompile .js and .css sources.
9 | config :chat, ChatWeb.Endpoint,
10 | http: [port: 4000],
11 | debug_errors: true,
12 | code_reloader: true,
13 | check_origin: false,
14 | watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
15 | cd: Path.expand("../assets", __DIR__)]]
16 |
17 | # ## SSL Support
18 | #
19 | # In order to use HTTPS in development, a self-signed
20 | # certificate can be generated by running the following
21 | # command from your terminal:
22 | #
23 | # openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
24 | #
25 | # The `http:` config above can be replaced with:
26 | #
27 | # https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"],
28 | #
29 | # If desired, both `http:` and `https:` keys can be
30 | # configured to run both http and https servers on
31 | # different ports.
32 |
33 | # Watch static and templates for browser reloading.
34 | config :chat, ChatWeb.Endpoint,
35 | live_reload: [
36 | patterns: [
37 | ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
38 | ~r{priv/gettext/.*(po)$},
39 | ~r{lib/chat_web/views/.*(ex)$},
40 | ~r{lib/chat_web/templates/.*(eex)$}
41 | ]
42 | ]
43 |
44 | # Do not include metadata nor timestamps in development logs
45 | config :logger, :console, format: "[$level] $message\n"
46 |
47 | # Set a higher stacktrace during development. Avoid configuring such
48 | # in production as building large stacktraces may be expensive.
49 | config :phoenix, :stacktrace_depth, 20
50 |
51 | # Configure your database
52 | config :chat, Chat.Repo,
53 | adapter: Ecto.Adapters.Postgres,
54 | username: "postgres",
55 | password: "postgres",
56 | database: "chat_dev",
57 | hostname: "localhost",
58 | pool_size: 10
59 |
--------------------------------------------------------------------------------
/lib/chat/chats/chats.ex:
--------------------------------------------------------------------------------
1 | defmodule Chat.Chats do
2 | @moduledoc """
3 | The Chats context.
4 | """
5 |
6 | import Ecto.Query, warn: false
7 | alias Chat.Repo
8 |
9 | alias Chat.Chats.Message
10 |
11 | @doc """
12 | Returns the list of messages.
13 |
14 | ## Examples
15 |
16 | iex> list_messages()
17 | [%Message{}, ...]
18 |
19 | """
20 | def list_messages do
21 | Repo.all(Message)
22 | end
23 |
24 | @doc """
25 | Gets a single message.
26 |
27 | Raises `Ecto.NoResultsError` if the Message does not exist.
28 |
29 | ## Examples
30 |
31 | iex> get_message!(123)
32 | %Message{}
33 |
34 | iex> get_message!(456)
35 | ** (Ecto.NoResultsError)
36 |
37 | """
38 | def get_message!(id), do: Repo.get!(Message, id)
39 |
40 | @doc """
41 | Creates a message.
42 |
43 | ## Examples
44 |
45 | iex> create_message(%{field: value})
46 | {:ok, %Message{}}
47 |
48 | iex> create_message(%{field: bad_value})
49 | {:error, %Ecto.Changeset{}}
50 |
51 | """
52 | def create_message(attrs \\ %{}) do
53 | %Message{}
54 | |> Message.changeset(attrs)
55 | |> Repo.insert()
56 | end
57 |
58 | @doc """
59 | Updates a message.
60 |
61 | ## Examples
62 |
63 | iex> update_message(message, %{field: new_value})
64 | {:ok, %Message{}}
65 |
66 | iex> update_message(message, %{field: bad_value})
67 | {:error, %Ecto.Changeset{}}
68 |
69 | """
70 | def update_message(%Message{} = message, attrs) do
71 | message
72 | |> Message.changeset(attrs)
73 | |> Repo.update()
74 | end
75 |
76 | @doc """
77 | Deletes a Message.
78 |
79 | ## Examples
80 |
81 | iex> delete_message(message)
82 | {:ok, %Message{}}
83 |
84 | iex> delete_message(message)
85 | {:error, %Ecto.Changeset{}}
86 |
87 | """
88 | def delete_message(%Message{} = message) do
89 | Repo.delete(message)
90 | end
91 |
92 | @doc """
93 | Returns an `%Ecto.Changeset{}` for tracking message changes.
94 |
95 | ## Examples
96 |
97 | iex> change_message(message)
98 | %Ecto.Changeset{source: %Message{}}
99 |
100 | """
101 | def change_message(%Message{} = message) do
102 | Message.changeset(message, %{})
103 | end
104 | end
105 |
--------------------------------------------------------------------------------
/config/prod.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # For production, we often load configuration from external
4 | # sources, such as your system environment. For this reason,
5 | # you won't find the :http configuration below, but set inside
6 | # ChatWeb.Endpoint.init/2 when load_from_system_env is
7 | # true. Any dynamic configuration should be done there.
8 | #
9 | # Don't forget to configure the url host to something meaningful,
10 | # Phoenix uses this information when generating URLs.
11 | #
12 | # Finally, we also include the path to a cache manifest
13 | # containing the digested version of static files. This
14 | # manifest is generated by the mix phx.digest task
15 | # which you typically run after static files are built.
16 | config :chat, ChatWeb.Endpoint,
17 | load_from_system_env: true,
18 | url: [host: "example.com", port: 80],
19 | cache_static_manifest: "priv/static/cache_manifest.json"
20 |
21 | # Do not print debug messages in production
22 | config :logger, level: :info
23 |
24 | # ## SSL Support
25 | #
26 | # To get SSL working, you will need to add the `https` key
27 | # to the previous section and set your `:url` port to 443:
28 | #
29 | # config :chat, ChatWeb.Endpoint,
30 | # ...
31 | # url: [host: "example.com", port: 443],
32 | # https: [:inet6,
33 | # port: 443,
34 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
35 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
36 | #
37 | # Where those two env variables return an absolute path to
38 | # the key and cert in disk or a relative path inside priv,
39 | # for example "priv/ssl/server.key".
40 | #
41 | # We also recommend setting `force_ssl`, ensuring no data is
42 | # ever sent via http, always redirecting to https:
43 | #
44 | # config :chat, ChatWeb.Endpoint,
45 | # force_ssl: [hsts: true]
46 | #
47 | # Check `Plug.SSL` for all available options in `force_ssl`.
48 |
49 | # ## Using releases
50 | #
51 | # If you are doing OTP releases, you need to instruct Phoenix
52 | # to start the server for all endpoints:
53 | #
54 | # config :phoenix, :serve_endpoints, true
55 | #
56 | # Alternatively, you can configure exactly which server to
57 | # start per endpoint:
58 | #
59 | # config :chat, ChatWeb.Endpoint, server: true
60 | #
61 |
62 | # Finally import the config/prod.secret.exs
63 | # which should be versioned separately.
64 | import_config "prod.secret.exs"
65 |
--------------------------------------------------------------------------------
/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 | import {Socket} from "phoenix"
7 |
8 | let socket = new Socket("/socket", {params: {token: window.userToken}})
9 |
10 | // When you connect, you'll often need to authenticate the client.
11 | // For example, imagine you have an authentication plug, `MyAuth`,
12 | // which authenticates the session and assigns a `:current_user`.
13 | // If the current user exists you can assign the user's token in
14 | // the connection for use in the layout.
15 | //
16 | // In your "lib/web/router.ex":
17 | //
18 | // pipeline :browser do
19 | // ...
20 | // plug MyAuth
21 | // plug :put_user_token
22 | // end
23 | //
24 | // defp put_user_token(conn, _) do
25 | // if current_user = conn.assigns[:current_user] do
26 | // token = Phoenix.Token.sign(conn, "user socket", current_user.id)
27 | // assign(conn, :user_token, token)
28 | // else
29 | // conn
30 | // end
31 | // end
32 | //
33 | // Now you need to pass this token to JavaScript. You can do so
34 | // inside a script tag in "lib/web/templates/layout/app.html.eex":
35 | //
36 | //
37 | //
38 | // You will need to verify the user token in the "connect/2" function
39 | // in "lib/web/channels/user_socket.ex":
40 | //
41 | // def connect(%{"token" => token}, socket) do
42 | // # max_age: 1209600 is equivalent to two weeks in seconds
43 | // case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
44 | // {:ok, user_id} ->
45 | // {:ok, assign(socket, :user, user_id)}
46 | // {:error, reason} ->
47 | // :error
48 | // end
49 | // end
50 | //
51 | // Finally, pass the token on connect as below. Or remove it
52 | // from connect if you don't care about authentication.
53 |
54 | socket.connect()
55 |
56 | // Now that you are connected, you can join channels with a topic:
57 | let channel = socket.channel("water_cooler:lobby", {})
58 | channel.join()
59 | .receive("ok", resp => { console.log("Joined successfully", resp) })
60 | .receive("error", resp => { console.log("Unable to join", resp) })
61 |
62 | export default socket
63 |
--------------------------------------------------------------------------------
/test/chat/chats/chats_test.exs:
--------------------------------------------------------------------------------
1 | defmodule Chat.ChatsTest do
2 | use Chat.DataCase
3 |
4 | alias Chat.Chats
5 |
6 | describe "messages" do
7 | alias Chat.Chats.Message
8 |
9 | @valid_attrs %{body: "some body", name: "some name"}
10 | @update_attrs %{body: "some updated body", name: "some updated name"}
11 | @invalid_attrs %{body: nil, name: nil}
12 |
13 | def message_fixture(attrs \\ %{}) do
14 | {:ok, message} =
15 | attrs
16 | |> Enum.into(@valid_attrs)
17 | |> Chats.create_message()
18 |
19 | message
20 | end
21 |
22 | test "list_messages/0 returns all messages" do
23 | message = message_fixture()
24 | assert Chats.list_messages() == [message]
25 | end
26 |
27 | test "get_message!/1 returns the message with given id" do
28 | message = message_fixture()
29 | assert Chats.get_message!(message.id) == message
30 | end
31 |
32 | test "create_message/1 with valid data creates a message" do
33 | assert {:ok, %Message{} = message} = Chats.create_message(@valid_attrs)
34 | assert message.body == "some body"
35 | assert message.name == "some name"
36 | end
37 |
38 | test "create_message/1 with invalid data returns error changeset" do
39 | assert {:error, %Ecto.Changeset{}} = Chats.create_message(@invalid_attrs)
40 | end
41 |
42 | test "update_message/2 with valid data updates the message" do
43 | message = message_fixture()
44 | assert {:ok, message} = Chats.update_message(message, @update_attrs)
45 | assert %Message{} = message
46 | assert message.body == "some updated body"
47 | assert message.name == "some updated name"
48 | end
49 |
50 | test "update_message/2 with invalid data returns error changeset" do
51 | message = message_fixture()
52 | assert {:error, %Ecto.Changeset{}} = Chats.update_message(message, @invalid_attrs)
53 | assert message == Chats.get_message!(message.id)
54 | end
55 |
56 | test "delete_message/1 deletes the message" do
57 | message = message_fixture()
58 | assert {:ok, %Message{}} = Chats.delete_message(message)
59 | assert_raise Ecto.NoResultsError, fn -> Chats.get_message!(message.id) end
60 | end
61 |
62 | test "change_message/1 returns a message changeset" do
63 | message = message_fixture()
64 | assert %Ecto.Changeset{} = Chats.change_message(message)
65 | end
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/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 file 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 as 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 |
--------------------------------------------------------------------------------
/assets/css/app.css:
--------------------------------------------------------------------------------
1 | /* This file is for your main application css. */
2 |
3 | /*
4 | * Basic styling for elixircasts.io screencasts
5 | */
6 |
7 | body {
8 | font-family: 'Open Sans', sans-serif;
9 | background: #222E4D;
10 | font-size: 14px;
11 | line-height: 22px;
12 | overflow-x: hidden;
13 | }
14 |
15 | ::selection{
16 | background-color: #FFEC6E;
17 | color: #000;
18 | }
19 |
20 | ::-moz-selection {
21 | background: #46c2ca;
22 | color: #000;
23 | }
24 |
25 | .container {
26 | width: 75%;
27 | height: 100%;
28 | padding:20px;
29 | background-color: #fff;
30 | top: 100px;
31 | bottom: 0;
32 | left: 0;
33 | right: 0;
34 | margin: auto;
35 | }
36 |
37 | hr {
38 | border: 0;
39 | height: 0;
40 | border-top: 1px solid #CCC;
41 | }
42 |
43 | a {
44 | color: rgb(0, 0, 238);
45 | text-decoration: underline;
46 | }
47 |
48 | .alert:empty {
49 | display:none;
50 | }
51 |
52 | p.alert.alert-info {
53 | padding: 7px;
54 | background: #DFF0D8;
55 | }
56 |
57 | p.alert.alert-danger {
58 | padding: 7px;
59 | background: #F2DEDE;
60 | }
61 |
62 | .flash-notice {
63 | padding: 7px;
64 | background: #D9EDF7;
65 | }
66 |
67 | table {
68 | border-collapse: collapse;
69 | width: 100%;
70 | }
71 |
72 | table, th, td {
73 | text-align: left;
74 | padding: 10px;
75 | border: 1px solid black;
76 | }
77 |
78 | #chat-box {
79 | border: 1px #000 solid;
80 | padding: 0 0 0 5px;
81 | min-height: 157px;
82 | max-height: 225px;
83 | overflow: scroll;
84 | }
85 |
86 | #chat-form {
87 | width:250px;
88 | }
89 |
90 | #chat-form input[type="text"] {
91 | width: 250px;
92 | padding: 5px;
93 | border: 1px solid #ccc;
94 | margin-top: 5px;
95 | }
96 |
97 | #chat-form textarea {
98 | width: 250px;
99 | padding: 5px;
100 | border: 1px solid #ccc;
101 | margin-top: 5px;
102 |
103 | }
104 |
105 | .nav-header {
106 | position: relative;
107 | width: 100%;
108 | }
109 |
110 | .nav-h1 {
111 | float: left;
112 | clear:none;
113 | }
114 |
115 | .nav-header .nav-link {
116 | float: right;
117 | margin: -40px 10px 10px 10px;
118 | }
119 |
120 | .nav-header .nav-link a {
121 | margin-left: 5px;
122 | }
123 |
124 | .elixircasts-form {
125 | margin-bottom: 10px;
126 | }
127 |
128 | .elixircasts-form label {
129 | display: block;
130 | margin: 0px 0px 5px;
131 | }
132 |
133 | .elixircasts-form input[type="text"], .elixircasts-form input[type="email"], .elixircasts-form textarea, .elixircasts-form select{
134 | border: 1px solid #000;
135 | color: #000;
136 | font-size: 14px;
137 | height: 20px;
138 | line-height:15px;
139 | margin-bottom: 16px;
140 | margin-right: 6px;
141 | margin-top: 2px;
142 | outline: 0 none;
143 | padding: 5px 0px 5px 5px;
144 | width: 70%;
145 | }
146 |
147 | .elixircasts-form .help-block {
148 | background: #F2DEDE;
149 | }
150 |
151 | .elixircasts-form select {
152 | height: 35px;
153 | }
154 | .elixircasts-form textarea{
155 | height:100px;
156 | padding: 5px 0px 0px 5px;
157 | }
158 |
--------------------------------------------------------------------------------
/mix.lock:
--------------------------------------------------------------------------------
1 | %{"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
2 | "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
3 | "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
4 | "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
5 | "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"},
6 | "ecto": {:hex, :ecto, "2.2.9", "031d55df9bb430cb118e6f3026a87408d9ce9638737bda3871e5d727a3594aae", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
7 | "file_system": {:hex, :file_system, "0.2.4", "f0bdda195c0e46e987333e986452ec523aed21d784189144f647c43eaf307064", [:mix], [], "hexpm"},
8 | "gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
9 | "mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], [], "hexpm"},
10 | "phoenix": {:hex, :phoenix, "1.3.2", "2a00d751f51670ea6bc3f2ba4e6eb27ecb8a2c71e7978d9cd3e5de5ccf7378bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
11 | "phoenix_ecto": {:hex, :phoenix_ecto, "3.3.0", "702f6e164512853d29f9d20763493f2b3bcfcb44f118af2bc37bb95d0801b480", [:mix], [{:ecto, "~> 2.1", [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"},
12 | "phoenix_html": {:hex, :phoenix_html, "2.11.0", "ead10dd1e36d5b8b5cc55642ba337832ec62617efd5765cddaa1a36c8b3891ca", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
13 | "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.3", "1d178429fc8950b12457d09c6afec247bfe1fcb6f36209e18fbb0221bdfe4d41", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
14 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm"},
15 | "plug": {:hex, :plug, "1.5.0", "224b25b4039bedc1eac149fb52ed456770b9678bbf0349cdd810460e1e09195b", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
16 | "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
17 | "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
18 | "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
19 | "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}}
20 |
--------------------------------------------------------------------------------