diff --git a/lib/mazurka_plug.ex b/lib/mazurka_plug.ex index 41240cf..c6fb896 100644 --- a/lib/mazurka_plug.ex +++ b/lib/mazurka_plug.ex @@ -12,7 +12,6 @@ defmodule Mazurka.Plug do end end) - @doc false def action(conn, opts) when is_list(opts) do action(conn, :maps.from_list(opts)) end @@ -57,7 +56,7 @@ defmodule Mazurka.Plug do def serialize({"text", "html", _}, body) when is_tuple(body) do HTMLBuilder.encode_to_iodata!(body) end - def serialize({"text", _, _}, body) do + def serialize(_, body) do body end diff --git a/lib/mazurka_plug/helpers.ex b/lib/mazurka_plug/helpers.ex index 9693e2a..262b729 100644 --- a/lib/mazurka_plug/helpers.ex +++ b/lib/mazurka_plug/helpers.ex @@ -42,15 +42,25 @@ defmodule Mazurka.Plug.Helpers do {params, input, conn} end + def handle_body(_conn, %Plug.Conn{} = conn, content_type, serialize) do + handle_body(conn, conn.resp_body, content_type, serialize) + end + def handle_body(conn, body, {type, subtype, _} = content_type, serialize) do body = serialize.(content_type, body) %{conn | resp_body: body, state: :set} |> Conn.put_resp_content_type(type <> "/" <> subtype) end - def handle_transition(%{private: %{mazurka_transition: transition}, status: status} = conn) do - %{conn | status: status || 303} + def handle_transition(%{private: %{mazurka_transition: _} = private} = conn) do + {transition, private} = Map.pop(private, :mazurka_transition) + + %{conn | status: conn.status || 303} |> Conn.put_resp_header("location", to_string(transition)) + |> handle_transition() + end + def handle_transition(%{status: status} = conn) when status >= 300 and status < 400 do + %{conn | resp_body: ""} end def handle_transition(conn) do conn diff --git a/mix.exs b/mix.exs index f9adf17..0f71c1a 100644 --- a/mix.exs +++ b/mix.exs @@ -2,33 +2,31 @@ defmodule Mazurka.Plug.Mixfile do use Mix.Project def project do - [app: :mazurka_plug, - description: "Plug integration for Mazurka", - version: "0.1.6", - elixir: "~> 1.0", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - package: package(), - deps: deps()] + [ + app: :mazurka_plug, + description: "Plug integration for Mazurka", + version: "0.1.7", + elixir: "~> 1.0", + build_embedded: Mix.env() == :prod, + start_permanent: Mix.env() == :prod, + deps: deps() + ] end def application do - [applications: [:logger]] + [ + applications: [:logger] + ] end defp deps do - [{:fugue, ">= 0.1.0"}, - {:html_builder, "~> 0.1"}, - {:mazurka, ">= 1.0.0"}, - {:plug, ">= 0.0.0"}, - {:poison, ">= 2.2.0"}, - {:ex_doc, ">= 0.0.0", only: :dev}] - end - - defp package do - [files: ["lib", "mix.exs", "README*"], - maintainers: ["Cameron Bytheway"], - licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/exstruct/mazurka_plug"}] + [ + {:ex_doc, ">= 0.0.0", only: :dev}, + {:fugue, ">= 0.1.0"}, + {:html_builder, github: "simplecastapps/html_builder"}, + {:mazurka, github: "simplecastapps/mazurka"}, + {:plug, ">= 0.0.0"}, + {:poison, ">= 2.2.0"} + ] end end