diff options
Diffstat (limited to 'web/views')
-rw-r--r-- | web/views/audio_file_view.ex | 3 | ||||
-rw-r--r-- | web/views/error_helpers.ex | 40 | ||||
-rw-r--r-- | web/views/error_view.ex | 17 | ||||
-rw-r--r-- | web/views/layout_view.ex | 3 | ||||
-rw-r--r-- | web/views/page_view.ex | 3 |
5 files changed, 66 insertions, 0 deletions
diff --git a/web/views/audio_file_view.ex b/web/views/audio_file_view.ex new file mode 100644 index 0000000..b2b2c26 --- /dev/null +++ b/web/views/audio_file_view.ex @@ -0,0 +1,3 @@ +defmodule TheTranscriberBackend.AudioFileView do + use TheTranscriberBackend.Web, :view +end diff --git a/web/views/error_helpers.ex b/web/views/error_helpers.ex new file mode 100644 index 0000000..6f77aa4 --- /dev/null +++ b/web/views/error_helpers.ex @@ -0,0 +1,40 @@ +defmodule TheTranscriberBackend.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. + # Ecto will pass the :count keyword if the error message is + # meant to be pluralized. + # On your own code and templates, depending on whether you + # need the message to be pluralized or not, this could be + # written simply as: + # + # dngettext "errors", "1 file", "%{count} files", count + # dgettext "errors", "is invalid" + # + if count = opts[:count] do + Gettext.dngettext(TheTranscriberBackend.Gettext, "errors", msg, msg, count, opts) + else + Gettext.dgettext(TheTranscriberBackend.Gettext, "errors", msg, opts) + end + end +end diff --git a/web/views/error_view.ex b/web/views/error_view.ex new file mode 100644 index 0000000..e47ebee --- /dev/null +++ b/web/views/error_view.ex @@ -0,0 +1,17 @@ +defmodule TheTranscriberBackend.ErrorView do + use TheTranscriberBackend.Web, :view + + def render("404.html", _assigns) do + "Page not found" + end + + def render("500.html", _assigns) do + "Internal server 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 diff --git a/web/views/layout_view.ex b/web/views/layout_view.ex new file mode 100644 index 0000000..2d00bcb --- /dev/null +++ b/web/views/layout_view.ex @@ -0,0 +1,3 @@ +defmodule TheTranscriberBackend.LayoutView do + use TheTranscriberBackend.Web, :view +end diff --git a/web/views/page_view.ex b/web/views/page_view.ex new file mode 100644 index 0000000..30152fd --- /dev/null +++ b/web/views/page_view.ex @@ -0,0 +1,3 @@ +defmodule TheTranscriberBackend.PageView do + use TheTranscriberBackend.Web, :view +end |