Skip to content

Commit

Permalink
Init repo
Browse files Browse the repository at this point in the history
ggpasqualino committed Feb 8, 2016
0 parents commit f2fd40d
Showing 41 changed files with 1,286 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# App artifacts
/_build
/db
/deps
/*.ez

# Generate on crash by the VM
erl_crash.dump

# Static artifacts
/node_modules

# Since we are building assets from web/static,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/

# The config/prod.secret.exs file by default contains sensitive
# data and you should not commit it into version control.
#
# Alternatively, you may comment the line below and commit the
# secrets file as long as you replace its contents by environment
# variables.
/config/prod.secret.exs
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Meetup

To start your Phoenix app:

* Install dependencies with `mix deps.get`
* Create and migrate your database with `mix ecto.create && mix ecto.migrate`
* Install Node.js dependencies with `npm install`
* Start Phoenix endpoint with `mix phoenix.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).

## Learn more

* Official website: http://www.phoenixframework.org/
* Guides: http://phoenixframework.org/docs/overview
* Docs: http://hexdocs.pm/phoenix
* Mailing list: http://groups.google.com/group/phoenix-talk
* Source: https://github.com/phoenixframework/phoenix
70 changes: 70 additions & 0 deletions brunch-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"

// To use a separate vendor.js bundle, specify two files path
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files
// joinTo: {
// "js/app.js": /^(web\/static\/js)/,
// "js/vendor.js": /^(web\/static\/vendor)|(deps)/
// }
//
// To change the order of concatenation of files, explicitly mention here
// https://github.com/brunch/brunch/tree/master/docs#concatenation
// order: {
// before: [
// "web/static/vendor/js/jquery-2.1.1.js",
// "web/static/vendor/js/bootstrap.min.js"
// ]
// }
},
stylesheets: {
joinTo: "css/app.css"
},
templates: {
joinTo: "js/app.js"
}
},

conventions: {
// This option sets where we should place non-css and non-js assets in.
// By default, we set this to "/web/static/assets". Files in this directory
// will be copied to `paths.public`, which is "priv/static" by default.
assets: /^(web\/static\/assets)/
},

// Phoenix paths configuration
paths: {
// Dependencies and current project directories to watch
watched: [
"web/static",
"test/static"
],

// Where to compile files to
public: "priv/static"
},

// Configure your plugins
plugins: {
babel: {
// Do not use ES6 compiler in vendor code
ignore: [/web\/static\/vendor/]
}
},

modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"]
}
},

npm: {
enabled: true,
// Whitelist the npm deps to be pulled in as front-end assets.
// All other deps in package.json will be excluded from the bundle.
whitelist: ["phoenix", "phoenix_html"]
}
};
29 changes: 29 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config

# Configures the endpoint
config :meetup, Meetup.Endpoint,
url: [host: "localhost"],
root: Path.dirname(__DIR__),
secret_key_base: "XVM6/VcNY8bAwfnl2RUR5TRhZ77AAI6nsanOsuifNY63eC6nEKoCqty9eEJ0skA4",
render_errors: [accepts: ~w(html json)],
pubsub: [name: Meetup.PubSub,
adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"

# Configure phoenix generators
config :phoenix, :generators,
migration: true,
binary_id: false
42 changes: 42 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use Mix.Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :meetup, Meetup.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin"]]

# Watch static and templates for browser reloading.
config :meetup, Meetup.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
]
]

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

# Set a higher stacktrace during development.
# Do not configure such in production as keeping
# and calculating stacktraces is usually expensive.
config :phoenix, :stacktrace_depth, 20

# Configure your database
config :meetup, Meetup.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "meetup_dev",
hostname: "localhost",
pool_size: 10
65 changes: 65 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use Mix.Config

# For production, we configure the host to read the PORT
# from the system environment. Therefore, you will need
# to set PORT=80 before running your server.
#
# You should also configure the url host to something
# meaningful, we use this information when generating URLs.
#
# Finally, we also include the path to a manifest
# containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
config :meetup, Meetup.Endpoint,
http: [port: {:system, "PORT"}],
url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/manifest.json"

# Do not print debug messages in production
config :logger, level: :info

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
# config :meetup, Meetup.Endpoint,
# ...
# url: [host: "example.com", port: 443],
# https: [port: 443,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
#
# Where those two env variables return an absolute path to
# the key and cert in disk or a relative path inside priv,
# for example "priv/ssl/server.key".
#
# We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https:
#
# config :meetup, Meetup.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
# config :phoenix, :serve_endpoints, true
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
# config :meetup, Meetup.Endpoint, server: true
#
# You will also need to set the application root to `.` in order
# for the new static assets to be served after a hot upgrade:
#
# config :meetup, Meetup.Endpoint, root: "."

# Finally import the config/prod.secret.exs
# which should be versioned separately.
import_config "prod.secret.exs"
19 changes: 19 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use Mix.Config

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :meetup, Meetup.Endpoint,
http: [port: 4001],
server: false

# Print only warnings and errors during test
config :logger, level: :warn

# Configure your database
config :meetup, Meetup.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "meetup_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
30 changes: 30 additions & 0 deletions lib/meetup.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule Meetup do
use Application

# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false

children = [
# Start the endpoint when the application starts
supervisor(Meetup.Endpoint, []),
# Start the Ecto repository
supervisor(Meetup.Repo, []),
# Here you could define other workers and supervisors as children
# worker(Meetup.Worker, [arg1, arg2, arg3]),
]

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Meetup.Supervisor]
Supervisor.start_link(children, opts)
end

# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
Meetup.Endpoint.config_change(changed, removed)
:ok
end
end
39 changes: 39 additions & 0 deletions lib/meetup/endpoint.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule Meetup.Endpoint do
use Phoenix.Endpoint, otp_app: :meetup

socket "/socket", Meetup.UserSocket

# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/", from: :meetup, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
end

plug Plug.RequestId
plug Plug.Logger

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison

plug Plug.MethodOverride
plug Plug.Head

plug Plug.Session,
store: :cookie,
key: "_meetup_key",
signing_salt: "9eSUTiuI"

plug Meetup.Router
end
3 changes: 3 additions & 0 deletions lib/meetup/repo.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Meetup.Repo do
use Ecto.Repo, otp_app: :meetup
end
52 changes: 52 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
defmodule Meetup.Mixfile do
use Mix.Project

def project do
[app: :meetup,
version: "0.0.1",
elixir: "~> 1.0",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases,
deps: deps]
end

# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[mod: {Meetup, []},
applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex]]
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
defp elixirc_paths(_), do: ["lib", "web"]

# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[{:phoenix, "~> 1.1.4"},
{:postgrex, ">= 0.0.0"},
{:phoenix_ecto, "~> 2.0"},
{:phoenix_html, "~> 2.4"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.9"},
{:cowboy, "~> 1.0"}]
end

# Aliases are shortcut or tasks specific to the current project.
# For example, to create, migrate and run the seeds file at once:
#
# $ mix ecto.setup
#
# See the documentation for `Mix` for more info on aliases.
defp aliases do
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"]]
end
end
17 changes: 17 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%{"connection": {:hex, :connection, "1.0.2"},
"cowboy": {:hex, :cowboy, "1.0.4"},
"cowlib": {:hex, :cowlib, "1.0.2"},
"db_connection": {:hex, :db_connection, "0.2.3"},
"decimal": {:hex, :decimal, "1.1.1"},
"ecto": {:hex, :ecto, "1.1.3"},
"fs": {:hex, :fs, "0.9.2"},
"gettext": {:hex, :gettext, "0.9.0"},
"phoenix": {:hex, :phoenix, "1.1.4"},
"phoenix_ecto": {:hex, :phoenix_ecto, "2.0.1"},
"phoenix_html": {:hex, :phoenix_html, "2.5.0"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.3"},
"plug": {:hex, :plug, "1.1.0"},
"poison": {:hex, :poison, "1.5.2"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"postgrex": {:hex, :postgrex, "0.11.0"},
"ranch": {:hex, :ranch, "1.2.1"}}
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"repository": {
},
"dependencies": {
"babel-brunch": "~6.0.0",
"brunch": "~2.1.3",
"clean-css-brunch": "~1.8.0",
"css-brunch": "~1.7.0",
"javascript-brunch": "~1.8.0",
"uglify-js-brunch": "~1.7.0",
"phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html"
}
}
99 changes: 99 additions & 0 deletions priv/gettext/en/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
## `msgid`s in this file come from POT (.pot) files. Do not add, change, or
## remove `msgid`s manually here as they're tied to the ones in the
## corresponding POT file (with the same domain). Use `mix gettext.extract
## --merge` or `mix gettext.merge` to merge POT files into PO files.
msgid ""
msgstr ""
"Language: en\n"

## From Ecto.Changeset.cast/4
msgid "can't be blank"
msgstr ""

## From Ecto.Changeset.unique_constraint/3
msgid "has already been taken"
msgstr ""

## From Ecto.Changeset.put_change/3
msgid "is invalid"
msgstr ""

## From Ecto.Changeset.validate_format/3
msgid "has invalid format"
msgstr ""

## From Ecto.Changeset.validate_subset/3
msgid "has an invalid entry"
msgstr ""

## From Ecto.Changeset.validate_exclusion/3
msgid "is reserved"
msgstr ""

## From Ecto.Changeset.validate_confirmation/3
msgid "does not match confirmation"
msgstr ""

## From Ecto.Changeset.no_assoc_constraint/3
msgid "is still associated to this entry"
msgstr ""

msgid "are still associated to this entry"
msgstr ""

## From Ecto.Changeset.validate_length/3
msgid "should be %{count} character(s)"
msgid_plural "should be %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have %{count} item(s)"
msgid_plural "should have %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should be at least %{count} character(s)"
msgid_plural "should be at least %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have at least %{count} item(s)"
msgid_plural "should have at least %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should be at most %{count} character(s)"
msgid_plural "should be at most %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have at most %{count} item(s)"
msgid_plural "should have at most %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

## From Ecto.Changeset.validate_number/3
msgid "must be less than %{count}"
msgid_plural "must be less than %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be greater than %{count}"
msgid_plural "must be greater than %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be less than or equal to %{count}"
msgid_plural "must be less than or equal to %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be greater than or equal to %{count}"
msgid_plural "must be greater than or equal to %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be equal to %{count}"
msgid_plural "must be equal to %{count}"
msgstr[0] ""
msgstr[1] ""
97 changes: 97 additions & 0 deletions priv/gettext/errors.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## This file is a PO Template file. `msgid`s here are often extracted from
## source code; add new translations manually only if they're dynamic
## translations that can't be statically extracted. Run `mix
## gettext.extract` to bring this file up to date. Leave `msgstr`s empty as
## changing them here as no effect; edit them in PO (`.po`) files instead.

## From Ecto.Changeset.cast/4
msgid "can't be blank"
msgstr ""

## From Ecto.Changeset.unique_constraint/3
msgid "has already been taken"
msgstr ""

## From Ecto.Changeset.put_change/3
msgid "is invalid"
msgstr ""

## From Ecto.Changeset.validate_format/3
msgid "has invalid format"
msgstr ""

## From Ecto.Changeset.validate_subset/3
msgid "has an invalid entry"
msgstr ""

## From Ecto.Changeset.validate_exclusion/3
msgid "is reserved"
msgstr ""

## From Ecto.Changeset.validate_confirmation/3
msgid "does not match confirmation"
msgstr ""

## From Ecto.Changeset.no_assoc_constraint/3
msgid "is still associated to this entry"
msgstr ""

msgid "are still associated to this entry"
msgstr ""

## From Ecto.Changeset.validate_length/3
msgid "should be %{count} character(s)"
msgid_plural "should be %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have %{count} item(s)"
msgid_plural "should have %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should be at least %{count} character(s)"
msgid_plural "should be at least %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have at least %{count} item(s)"
msgid_plural "should have at least %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should be at most %{count} character(s)"
msgid_plural "should be at most %{count} character(s)"
msgstr[0] ""
msgstr[1] ""

msgid "should have at most %{count} item(s)"
msgid_plural "should have at most %{count} item(s)"
msgstr[0] ""
msgstr[1] ""

## From Ecto.Changeset.validate_number/3
msgid "must be less than %{count}"
msgid_plural "must be less than %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be greater than %{count}"
msgid_plural "must be greater than %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be less than or equal to %{count}"
msgid_plural "must be less than or equal to %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be greater than or equal to %{count}"
msgid_plural "must be greater than or equal to %{count}"
msgstr[0] ""
msgstr[1] ""

msgid "must be equal to %{count}"
msgid_plural "must be equal to %{count}"
msgstr[0] ""
msgstr[1] ""
11 changes: 11 additions & 0 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Script for populating the database. You can run it as:
#
# mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
# Meetup.Repo.insert!(%Meetup.SomeModel{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
8 changes: 8 additions & 0 deletions test/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Meetup.PageControllerTest do
use Meetup.ConnCase

test "GET /", %{conn: conn} do
conn = get conn, "/"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end
41 changes: 41 additions & 0 deletions test/support/channel_case.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
defmodule Meetup.ChannelCase do
@moduledoc """
This module defines the test case to be used by
channel tests.
Such tests rely on `Phoenix.ChannelTest` and also
imports other functionality to make it easier
to build and query models.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""

use ExUnit.CaseTemplate

using do
quote do
# Import conveniences for testing with channels
use Phoenix.ChannelTest

alias Meetup.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]


# The default endpoint for testing
@endpoint Meetup.Endpoint
end
end

setup tags do
unless tags[:async] do
Ecto.Adapters.SQL.restart_test_transaction(Meetup.Repo, [])
end

:ok
end
end
42 changes: 42 additions & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule Meetup.ConnCase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a connection.
Such tests rely on `Phoenix.ConnTest` and also
imports other functionality to make it easier
to build and query models.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""

use ExUnit.CaseTemplate

using do
quote do
# Import conveniences for testing with connections
use Phoenix.ConnTest

alias Meetup.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]

import Meetup.Router.Helpers

# The default endpoint for testing
@endpoint Meetup.Endpoint
end
end

setup tags do
unless tags[:async] do
Ecto.Adapters.SQL.restart_test_transaction(Meetup.Repo, [])
end

{:ok, conn: Phoenix.ConnTest.conn()}
end
end
61 changes: 61 additions & 0 deletions test/support/model_case.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
defmodule Meetup.ModelCase do
@moduledoc """
This module defines the test case to be used by
model tests.
You may define functions here to be used as helpers in
your model tests. See `errors_on/2`'s definition as reference.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""

use ExUnit.CaseTemplate

using do
quote do
alias Meetup.Repo

import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]
import Meetup.ModelCase
end
end

setup tags do
unless tags[:async] do
Ecto.Adapters.SQL.restart_test_transaction(Meetup.Repo, [])
end

:ok
end

@doc """
Helper for returning list of errors in model when passed certain data.
## Examples
Given a User model that lists `:name` as a required field and validates
`:password` to be safe, it would return:
iex> errors_on(%User{}, %{password: "password"})
[password: "is unsafe", name: "is blank"]
You could then write your assertion like:
assert {:password, "is unsafe"} in errors_on(%User{}, %{password: "password"})
You can also create the changeset manually and retrieve the errors
field directly:
iex> changeset = User.changeset(%User{}, password: "password")
iex> {:password, "is unsafe"} in changeset.errors
true
"""
def errors_on(model, data) do
model.__struct__.changeset(model, data).errors
end
end
6 changes: 6 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ExUnit.start

Mix.Task.run "ecto.create", ~w(-r Meetup.Repo --quiet)
Mix.Task.run "ecto.migrate", ~w(-r Meetup.Repo --quiet)
Ecto.Adapters.SQL.begin_test_transaction(Meetup.Repo)

21 changes: 21 additions & 0 deletions test/views/error_view_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Meetup.ErrorViewTest do
use Meetup.ConnCase, async: true

# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View

test "renders 404.html" do
assert render_to_string(Meetup.ErrorView, "404.html", []) ==
"Page not found"
end

test "render 500.html" do
assert render_to_string(Meetup.ErrorView, "500.html", []) ==
"Server internal error"
end

test "render any other" do
assert render_to_string(Meetup.ErrorView, "505.html", []) ==
"Server internal error"
end
end
3 changes: 3 additions & 0 deletions test/views/layout_view_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Meetup.LayoutViewTest do
use Meetup.ConnCase, async: true
end
3 changes: 3 additions & 0 deletions test/views/page_view_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Meetup.PageViewTest do
use Meetup.ConnCase, async: true
end
37 changes: 37 additions & 0 deletions web/channels/user_socket.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Meetup.UserSocket do
use Phoenix.Socket

## Channels
# channel "rooms:*", Meetup.RoomChannel

## Transports
transport :websocket, Phoenix.Transports.WebSocket
# transport :longpoll, Phoenix.Transports.LongPoll

# Socket params are passed from the client and can
# be used to verify and authenticate a user. After
# verification, you can put default assigns into
# the socket that will be set for all channels, ie
#
# {:ok, assign(socket, :user_id, verified_user_id)}
#
# To deny connection, return `:error`.
#
# See `Phoenix.Token` documentation for examples in
# performing token verification on connect.
def connect(_params, socket) do
{:ok, socket}
end

# Socket id's are topics that allow you to identify all sockets for a given user:
#
# def id(socket), do: "users_socket:#{socket.assigns.user_id}"
#
# Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user:
#
# Meetup.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{})
#
# Returning `nil` makes this socket anonymous.
def id(_socket), do: nil
end
7 changes: 7 additions & 0 deletions web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Meetup.PageController do
use Meetup.Web, :controller

def index(conn, _params) do
render conn, "index.html"
end
end
24 changes: 24 additions & 0 deletions web/gettext.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Meetup.Gettext do
@moduledoc """
A module providing Internationalization with a gettext-based API.
By using [Gettext](http://hexdocs.pm/gettext),
your module gains a set of macros for translations, for example:
import Meetup.Gettext
# Simple translation
gettext "Here is the string to translate"
# Plural translation
ngettext "Here is the string to translate",
"Here are the strings to translate",
3
# Domain-based translation
dgettext "errors", "Here is the error message to translate"
See the [Gettext Docs](http://hexdocs.pm/gettext) for detailed usage.
"""
use Gettext, otp_app: :meetup
end
26 changes: 26 additions & 0 deletions web/router.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule Meetup.Router do
use Meetup.Web, :router

pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end

pipeline :api do
plug :accepts, ["json"]
end

scope "/", Meetup do
pipe_through :browser # Use the default browser stack

get "/", PageController, :index
end

# Other scopes may use custom stacks.
# scope "/api", Meetup do
# pipe_through :api
# end
end
Binary file added web/static/assets/favicon.ico
Binary file not shown.
Binary file added web/static/assets/images/phoenix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions web/static/assets/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /
78 changes: 78 additions & 0 deletions web/static/css/app.css

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions web/static/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Brunch automatically concatenates all files in your
// watched paths. Those paths can be configured at
// config.paths.watched in "brunch-config.js".
//
// However, those files will only be executed if
// explicitly imported. The only exception are files
// in vendor, which are never wrapped in imports and
// therefore are always executed.

// Import dependencies
//
// If you no longer want to use a dependency, remember
// to also remove its path from "config.paths.watched".
import "phoenix_html"

// Import local files
//
// Local files can be imported directly using relative
// paths "./socket" or full ones "web/static/js/socket".

// import socket from "./socket"
62 changes: 62 additions & 0 deletions web/static/js/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// NOTE: The contents of this file will only be executed if
// you uncomment its entry in "web/static/js/app.js".

// To use Phoenix channels, the first step is to import Socket
// and connect at the socket path in "lib/my_app/endpoint.ex":
import {Socket} from "phoenix"

let socket = new Socket("/socket", {params: {token: window.userToken}})

// When you connect, you'll often need to authenticate the client.
// For example, imagine you have an authentication plug, `MyAuth`,
// which authenticates the session and assigns a `:current_user`.
// If the current user exists you can assign the user's token in
// the connection for use in the layout.
//
// In your "web/router.ex":
//
// pipeline :browser do
// ...
// plug MyAuth
// plug :put_user_token
// end
//
// defp put_user_token(conn, _) do
// if current_user = conn.assigns[:current_user] do
// token = Phoenix.Token.sign(conn, "user socket", current_user.id)
// assign(conn, :user_token, token)
// else
// conn
// end
// end
//
// Now you need to pass this token to JavaScript. You can do so
// inside a script tag in "web/templates/layout/app.html.eex":
//
// <script>window.userToken = "<%= assigns[:user_token] %>";</script>
//
// You will need to verify the user token in the "connect/2" function
// in "web/channels/user_socket.ex":
//
// def connect(%{"token" => token}, socket) do
// # max_age: 1209600 is equivalent to two weeks in seconds
// case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
// {:ok, user_id} ->
// {:ok, assign(socket, :user, user_id)}
// {:error, reason} ->
// :error
// end
// end
//
// Finally, pass the token on connect as below. Or remove it
// from connect if you don't care about authentication.

socket.connect()

// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("topic:subtopic", {})
channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })

export default socket
35 changes: 35 additions & 0 deletions web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Hello Meetup!</title>
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
</head>

<body>
<div class="container">
<header class="header">
<nav role="navigation">
<ul class="nav nav-pills pull-right">
<li><a href="http://www.phoenixframework.org/docs">Get Started</a></li>
</ul>
</nav>
<span class="logo"></span>
</header>

<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>

<main role="main">
<%= render @view_module, @view_template, assigns %>
</main>

</div> <!-- /container -->
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions web/templates/page/index.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="jumbotron">
<h2><%= gettext "Welcome to %{name}", name: "Phoenix!" %></h2>
<p class="lead">A productive web framework that<br />does not compromise speed and maintainability.</p>
</div>

<div class="row marketing">
<div class="col-lg-6">
<h4>Resources</h4>
<ul>
<li>
<a href="http://phoenixframework.org/docs/overview">Guides</a>
</li>
<li>
<a href="http://hexdocs.pm/phoenix">Docs</a>
</li>
<li>
<a href="https://github.com/phoenixframework/phoenix">Source</a>
</li>
</ul>
</div>

<div class="col-lg-6">
<h4>Help</h4>
<ul>
<li>
<a href="http://groups.google.com/group/phoenix-talk">Mailing list</a>
</li>
<li>
<a href="http://webchat.freenode.net/?channels=elixir-lang">#elixir-lang on freenode IRC</a>
</li>
<li>
<a href="https://twitter.com/elixirphoenix">@elixirphoenix</a>
</li>
</ul>
</div>
</div>
35 changes: 35 additions & 0 deletions web/views/error_helpers.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Meetup.ErrorHelpers do
@moduledoc """
Conveniences for translating and building error messages.
"""

use Phoenix.HTML

@doc """
Generates tag for inlined form input errors.
"""
def error_tag(form, field) do
if error = form.errors[field] do
content_tag :span, translate_error(error), class: "help-block"
end
end

@doc """
Translates an error message using gettext.
"""
def translate_error({msg, opts}) do
# Because error messages were defined within Ecto, we must
# call the Gettext module passing our Gettext backend. We
# also use the "errors" domain as translations are placed
# in the errors.po file. On your own code and templates,
# this could be written simply as:
#
# dngettext "errors", "1 file", "%{count} files", count
#
Gettext.dngettext(Meetup.Gettext, "errors", msg, msg, opts[:count], opts)
end

def translate_error(msg) do
Gettext.dgettext(Meetup.Gettext, "errors", msg)
end
end
17 changes: 17 additions & 0 deletions web/views/error_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Meetup.ErrorView do
use Meetup.Web, :view

def render("404.html", _assigns) do
"Page not found"
end

def render("500.html", _assigns) do
"Server internal error"
end

# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
render "500.html", assigns
end
end
3 changes: 3 additions & 0 deletions web/views/layout_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Meetup.LayoutView do
use Meetup.Web, :view
end
3 changes: 3 additions & 0 deletions web/views/page_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Meetup.PageView do
use Meetup.Web, :view
end
81 changes: 81 additions & 0 deletions web/web.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
defmodule Meetup.Web do
@moduledoc """
A module that keeps using definitions for controllers,
views and so on.
This can be used in your application as:
use Meetup.Web, :controller
use Meetup.Web, :view
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below.
"""

def model do
quote do
use Ecto.Schema

import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]
end
end

def controller do
quote do
use Phoenix.Controller

alias Meetup.Repo
import Ecto
import Ecto.Query, only: [from: 1, from: 2]

import Meetup.Router.Helpers
import Meetup.Gettext
end
end

def view do
quote do
use Phoenix.View, root: "web/templates"

# Import convenience functions from controllers
import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]

# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML

import Meetup.Router.Helpers
import Meetup.ErrorHelpers
import Meetup.Gettext
end
end

def router do
quote do
use Phoenix.Router
end
end

def channel do
quote do
use Phoenix.Channel

alias Meetup.Repo
import Ecto
import Ecto.Query, only: [from: 1, from: 2]
import Meetup.Gettext
end
end

@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end

0 comments on commit f2fd40d

Please sign in to comment.