Skip to content

Commit

Permalink
Use Elixir 1.6's formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
geolessel committed Jan 31, 2018
1 parent 2f0e685 commit c4c406b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
5 changes: 2 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 4 additions & 2 deletions lib/react_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion lib/react_phoenix/client_side.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]}])
Expand Down Expand Up @@ -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 changes: 17 additions & 15 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
15 changes: 12 additions & 3 deletions test/react_phoenix/client_side_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions test/react_phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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.