Skip to content

Commit e42158f

Browse files
committed
Remove json parsing
This solves a couple problems: 1. Poison was pretty out of date (so trying to use the lib caused version conflicts with the version we were already using in our app) 2. Our draftjs content wasn't stored as a string, it was stored as a map. Removing json parsing will let the user parse it if they need to (in whatever way they want), and let those who don't need to use it out of the box.
1 parent 67a922c commit e42158f

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

lib/draft.ex

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,17 @@ defmodule Draft do
33
Provides functions for parsing DraftJS content.
44
"""
55

6-
@doc """
7-
Parses the given DraftJS input and returns the blocks as a list of
8-
maps.
9-
10-
## Examples
11-
iex> draft = ~s({"entityMap":{},"blocks":[{"key":"1","text":"Hello","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]})
12-
iex> Draft.blocks draft
13-
[%{"key" => "1", "text" => "Hello", "type" => "unstyled",
14-
"depth" => 0, "inlineStyleRanges" => [], "entityRanges" => [],
15-
"data" => %{}}]
16-
"""
17-
def blocks(input) do
18-
Poison.Parser.parse!(input)["blocks"]
19-
end
20-
216
@doc """
227
Renders the given DraftJS input as html.
238
249
## Examples
25-
iex> draft = ~s({"entityMap":{},"blocks":[{"key":"1","text":"Hello","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]})
10+
iex> draft = {"entityMap":{},"blocks":[{"key":"1","text":"Hello","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]}
2611
iex> Draft.to_html draft
2712
"<p>Hello</p>"
2813
"""
2914
def to_html(input) do
3015
input
31-
|> blocks
16+
|> Map.get("blocks")
3217
|> Enum.map(&Draft.Block.to_html/1)
3318
|> Enum.join("")
3419
end

mix.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ defmodule Draft.Mixfile do
2929
defp deps do
3030
[
3131
{:credo, "~> 0.3", only: [:dev, :test]},
32-
{:ex_doc, "~> 0.14", only: :dev},
33-
{:poison, "~> 2.0"}
32+
{:ex_doc, "~> 0.14", only: :dev}
3433
]
3534
end
3635
end

mix.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
1+
%{
2+
"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
23
"credo": {:hex, :credo, "0.5.2", "92e8c9f86e0ffbf9f688595e9f4e936bc96a52e5606d2c19713e9e4d191d5c74", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
34
"earmark": {:hex, :earmark, "1.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [:mix], []},
45
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
5-
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []}}
6+
}

0 commit comments

Comments
 (0)