Permalink
Browse files

Use Elixir 1.6's formatter

  • Loading branch information...
geolessel committed Jan 31, 2018
1 parent 2f0e685 commit c4c406b2a0aad7bcc8ad7dbccd444b79d4640962
Showing with 52 additions and 27 deletions.
  1. +2 −3 config/config.exs
  2. +4 −2 lib/react_phoenix.ex
  3. +5 −1 lib/react_phoenix/client_side.ex
  4. +17 −15 mix.exs
  5. +12 −3 test/react_phoenix/client_side_test.exs
  6. +12 −3 test/react_phoenix_test.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"
@@ -9,13 +9,15 @@ 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
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
@@ -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
32 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
@@ -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 = "<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
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 = "<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
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 = "<div data-react-class=\"test\" data-react-props=\"{}\" data-react-target-id=\"test-id\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{}\" data-react-target-id=\"test-id\"></div>"
assert html == expected
end
end
@@ -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 = "<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
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 = "<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{&quot;my&quot;:&quot;props&quot;}\"></div>"
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 = "<div data-react-class=\"test\" data-react-props=\"{}\" data-react-target-id=\"test-id\"></div>"
expected =
"<div data-react-class=\"test\" data-react-props=\"{}\" data-react-target-id=\"test-id\"></div>"
assert html == expected
end
end

0 comments on commit c4c406b

Please sign in to comment.