Skip to content
Permalink
Browse files

JSON serializer can be optionally configured in Aplication env

  • Loading branch information...
arathunku committed Jan 14, 2019
1 parent 854d355 commit fa22d7a5abed85c2bd2deaf8133c07be138e24fc
Showing with 14 additions and 1 deletion.
  1. +7 −0 README.md
  2. +7 −1 lib/chartkick.ex
@@ -235,6 +235,13 @@ Add the following to your project :deps list:
{:chartkick, "~>0.3.0"}
```

Optionally, you can set different JSON encoder, by default it's Poison.
It's used to encode options passed to Chartkick.
```
# config.exs
config :chartkick, json_serializer: Jason
```

By default when you render a chart it will return both the HTML-element and JS that initializes the chart.
This will only work if you load Chartkick in the `<head>` tag.
You can chose to render the JS & HTML separately using the `only: :html` or `only: :script` option.
@@ -1,5 +1,11 @@
defmodule Chartkick do
require EEx
Module.put_attribute(
__MODULE__,
:poison,
if(Code.ensure_loaded?(Poison), do: Poison, else: nil)
)
@json_serializer Application.get_env(:chartkick, :json_serializer) || @poison

gen_chart_fn = fn (chart_type) ->
def unquote(
@@ -83,7 +89,7 @@ defmodule Chartkick do
opts
|> Keyword.take(@options)
|> Enum.into(%{})
|> Poison.encode!()
|> @json_serializer.encode!()
end

defp options_json(opts) when is_bitstring(opts) do

0 comments on commit fa22d7a

Please sign in to comment.
You can’t perform that action at this time.