diff --git a/config/config.exs b/config/config.exs index 35f4d87..4ff155b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -8,7 +8,6 @@ use Mix.Config config :porcelain, driver: Porcelain.Driver.Basic -config :react_phoenix, - compiled_path: Path.join(["priv", "static", "js", "components"]) +config :react_phoenix, compiled_path: Path.join(["priv", "static", "js", "components"]) -import_config "#{Mix.env}.exs" +import_config "#{Mix.env()}.exs" diff --git a/lib/react_phoenix.ex b/lib/react_phoenix.ex index 95ccee7..e0de532 100644 --- a/lib/react_phoenix.ex +++ b/lib/react_phoenix.ex @@ -9,7 +9,8 @@ defmodule ReactPhoenix do As of v0.4.0, please use `ElixirCabinet.ClientSide.react_component/2` instead. Provided for backward compatability for versions < 0.4.0. """ - def react_component(name, props \\ %{}), do: ReactPhoenix.ClientSide.react_component(name, props) + def react_component(name, props \\ %{}), + do: ReactPhoenix.ClientSide.react_component(name, props) @doc """ (Depricated) provides functions for client-side rendering of React.js components @@ -17,5 +18,6 @@ defmodule ReactPhoenix do As of v0.4.0, please use `ElixirCabinet.ClientSide.react_component/3` instead. Provided for backward compatability for versions < 0.4.0. """ - def react_component(name, props, opts), do: ReactPhoenix.ClientSide.react_component(name, props, opts) + def react_component(name, props, opts), + do: ReactPhoenix.ClientSide.react_component(name, props, opts) end diff --git a/lib/react_phoenix/client_side.ex b/lib/react_phoenix/client_side.ex index 38c8e71..6dec017 100644 --- a/lib/react_phoenix/client_side.ex +++ b/lib/react_phoenix/client_side.ex @@ -46,6 +46,7 @@ defmodule ReactPhoenix.ClientSide do def react_component(name, props) when is_list(props) do react_component(name, Enum.into(props, %{})) end + def react_component(name, props) when is_map(props) do props = Poison.encode!(props) content_tag(:div, "", [{:data, [react_class: name, react_props: props]}]) @@ -76,6 +77,9 @@ defmodule ReactPhoenix.ClientSide do """ def react_component(name, props, opts) when is_map(props) do props = Poison.encode!(props) - content_tag(:div, "", [{:data, [react_class: name, react_props: props, react_target_id: opts[:target_id]]}]) + + content_tag(:div, "", [ + {:data, [react_class: name, react_props: props, react_target_id: opts[:target_id]]} + ]) end end diff --git a/mix.exs b/mix.exs index fdb9f6a..df1d294 100644 --- a/mix.exs +++ b/mix.exs @@ -5,19 +5,21 @@ defmodule ReactPhoenix.Mixfile do @source_url "https://github.com/geolessel/react-phoenix" def project do - [app: :react_phoenix, - version: @version, - elixir: "~> 1.2", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - package: package(), - description: description(), - deps: deps(), - docs: docs()] + [ + app: :react_phoenix, + version: @version, + elixir: "~> 1.2", + build_embedded: Mix.env() == :prod, + start_permanent: Mix.env() == :prod, + package: package(), + description: description(), + deps: deps(), + docs: docs() + ] end def application do - [applications: [:logger, :phoenix_html, :poison],] + [applications: [:logger, :phoenix_html, :poison]] end def description do @@ -37,11 +39,11 @@ defmodule ReactPhoenix.Mixfile do defp package do [ - name: :react_phoenix, - files: ["lib", "priv", "mix.exs", "package.json", "README*", "LICENSE*"], - maintainers: ["Geoffrey Lessel"], - licenses: ["MIT"], - links: %{"GitHub" => @source_url} + name: :react_phoenix, + files: ["lib", "priv", "mix.exs", "package.json", "README*", "LICENSE*"], + maintainers: ["Geoffrey Lessel"], + licenses: ["MIT"], + links: %{"GitHub" => @source_url} ] end diff --git a/test/react_phoenix/client_side_test.exs b/test/react_phoenix/client_side_test.exs index d895149..9c56a11 100644 --- a/test/react_phoenix/client_side_test.exs +++ b/test/react_phoenix/client_side_test.exs @@ -19,19 +19,28 @@ defmodule ReactPhoenix.ClientSideTest do test "react_component returns a renderable div with data-react-props containing props list" do html = Phoenix.HTML.safe_to_string(react_component("test", my: "props")) - expected = "
" + + expected = + "" + assert html == expected end test "react_component returns a renderable div with data-react-props containing props map" do html = Phoenix.HTML.safe_to_string(react_component("test", %{my: "props"})) - expected = "" + + expected = + "" + assert html == expected end test "react_component accepts a target div option" do html = Phoenix.HTML.safe_to_string(react_component("test", %{}, target_id: "test-id")) - expected = "" + + expected = + "" + assert html == expected end end diff --git a/test/react_phoenix_test.exs b/test/react_phoenix_test.exs index f71fff4..b635c37 100644 --- a/test/react_phoenix_test.exs +++ b/test/react_phoenix_test.exs @@ -19,19 +19,28 @@ defmodule ReactPhoenixTest do test "react_component returns a renderable div with data-react-props containing props list" do html = Phoenix.HTML.safe_to_string(react_component("test", my: "props")) - expected = "" + + expected = + "" + assert html == expected end test "react_component returns a renderable div with data-react-props containing props map" do html = Phoenix.HTML.safe_to_string(react_component("test", %{my: "props"})) - expected = "" + + expected = + "" + assert html == expected end test "react_component accepts a target div option" do html = Phoenix.HTML.safe_to_string(react_component("test", %{}, target_id: "test-id")) - expected = "" + + expected = + "" + assert html == expected end end