Permalink
Browse files

Upgrading Phoenix 1.0.4 -> 1.1.0

  • Loading branch information...
urfolomeus committed Jan 10, 2016
1 parent 0dfd82a commit 00016ae4b0d7328984a1556c4585dd1a36c3edfd
View
13 mix.exs
@@ -18,7 +18,7 @@ defmodule SeatSaver.Mixfile do
# Type `mix help compile.app` for more information.
def application do
[mod: {SeatSaver, []},
applications: [:phoenix, :phoenix_html, :cowboy, :logger,
applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex]]
end
@@ -30,12 +30,13 @@ defmodule SeatSaver.Mixfile do
#
# Type `mix help deps` for examples and options.
defp deps do
[{:phoenix, "~> 1.0.3"},
{:phoenix_ecto, "~> 1.1"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.1"},
[{:phoenix, "~> 1.1"},
{:phoenix_ecto, "~> 2.0"},
{:postgrex, "~> 0.10"},
{:phoenix_html, "~> 2.3"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:cowboy, "~> 1.0"}]
{:cowboy, "~> 1.0"},
{:gettext, "~> 0.9"}]
end
# Aliases are shortcut or tasks specific to the current project.
View
@@ -1,14 +1,16 @@
%{"cowboy": {:hex, :cowboy, "1.0.3"},
"cowlib": {:hex, :cowlib, "1.0.1"},
"decimal": {:hex, :decimal, "1.1.0"},
"ecto": {:hex, :ecto, "1.0.4"},
%{"connection": {:hex, :connection, "1.0.2"},
"cowboy": {:hex, :cowboy, "1.0.4"},
"cowlib": {:hex, :cowlib, "1.0.2"},
"decimal": {:hex, :decimal, "1.1.1"},
"ecto": {:hex, :ecto, "1.1.1"},
"fs": {:hex, :fs, "0.9.2"},
"phoenix": {:hex, :phoenix, "1.0.3"},
"phoenix_ecto": {:hex, :phoenix_ecto, "1.2.0"},
"phoenix_html": {:hex, :phoenix_html, "2.2.0"},
"gettext": {:hex, :gettext, "0.9.0"},
"phoenix": {:hex, :phoenix, "1.1.2"},
"phoenix_ecto": {:hex, :phoenix_ecto, "2.0.0"},
"phoenix_html": {:hex, :phoenix_html, "2.3.1"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.1"},
"plug": {:hex, :plug, "1.0.2"},
"plug": {:hex, :plug, "1.0.3"},
"poison": {:hex, :poison, "1.5.0"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"postgrex": {:hex, :postgrex, "0.9.1"},
"ranch": {:hex, :ranch, "1.1.0"}}
"postgrex": {:hex, :postgrex, "0.10.0"},
"ranch": {:hex, :ranch, "1.2.0"}}
@@ -0,0 +1,95 @@
## `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.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] ""
View
@@ -0,0 +1,92 @@
## 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.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] ""
@@ -21,7 +21,7 @@ defmodule SeatSaver.ChannelCase do
use Phoenix.ChannelTest
alias SeatSaver.Repo
import Ecto.Model
import Ecto
import Ecto.Query, only: [from: 2]
@@ -21,7 +21,7 @@ defmodule SeatSaver.ConnCase do
use Phoenix.ConnTest
alias SeatSaver.Repo
import Ecto.Model
import Ecto
import Ecto.Query, only: [from: 2]
import SeatSaver.Router.Helpers
@@ -17,7 +17,7 @@ defmodule SeatSaver.ModelCase do
using do
quote do
alias SeatSaver.Repo
import Ecto.Model
import Ecto
import Ecto.Query, only: [from: 2]
import SeatSaver.ModelCase
end
View
@@ -0,0 +1,24 @@
defmodule SeatSaver.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 SeatSaver.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: :seat_saver
end
@@ -14,7 +14,7 @@
<body>
<div class="container" role="main">
<%= @inner %>
<%= render @view_module, @view_template, assigns %>
</div> <!-- /container -->
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
View
@@ -0,0 +1,19 @@
defmodule SeatSaver.ChangesetView do
use SeatSaver.Web, :view
@doc """
Traverses and translates changeset errors.
See `Ecto.Changeset.traverse_errors/2` and
`SeatSaver.ErrorHelpers.translate_error/1` for more details.
"""
def translate_errors(changeset) do
Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
end
def render("error.json", %{changeset: changeset}) do
# When encoded, the changeset returns its errors
# as a JSON object. So we just pass it forward.
%{errors: translate_errors(changeset)}
end
end
View
@@ -0,0 +1,34 @@
defmodule SeatSaver.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(SeatSaver.Gettext, "errors", msg, msg, opts[:count], opts)
end
def translate_error(msg) do
Gettext.dgettext(SeatSaver.Gettext, "errors", msg)
end
end
View
@@ -18,8 +18,9 @@ defmodule SeatSaver.Web do
def model do
quote do
use Ecto.Model
use Ecto.Schema
import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]
end
@@ -30,7 +31,7 @@ defmodule SeatSaver.Web do
use Phoenix.Controller
alias SeatSaver.Repo
import Ecto.Model
import Ecto
import Ecto.Query, only: [from: 1, from: 2]
import SeatSaver.Router.Helpers
@@ -48,6 +49,8 @@ defmodule SeatSaver.Web do
use Phoenix.HTML
import SeatSaver.Router.Helpers
import SeatSaver.ErrorHelpers
import SeatSaver.Gettext
end
end
@@ -62,7 +65,7 @@ defmodule SeatSaver.Web do
use Phoenix.Channel
alias SeatSaver.Repo
import Ecto.Model
import Ecto
import Ecto.Query, only: [from: 1, from: 2]
end
end

0 comments on commit 00016ae

Please sign in to comment.