Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/mazurka_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions lib/mazurka_plug/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 20 additions & 22 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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