From a94203bec336b4ffede79472c4447ac560f22989 Mon Sep 17 00:00:00 2001 From: Michael Maier Date: Fri, 13 Dec 2019 16:28:06 +0100 Subject: [PATCH] added more documentation, bump to version 0.1.4 --- CHANGELOG.md | 8 ++++++++ lib/hocon.ex | 34 +++++++++++++++++++++++++++++++--- mix.exs | 4 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a7005..2c93a4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.1.4 + +* Enhancements + * added support for duration nad period unit format + * added more tests + * extended the documentation + * added support for includes + ## 0.1.3 * Enhancements diff --git a/lib/hocon.ex b/lib/hocon.ex index 31638ee..5a5f617 100644 --- a/lib/hocon.ex +++ b/lib/hocon.ex @@ -13,7 +13,7 @@ defmodule Hocon do ## Units format - The Parser returns a map, because in Elixir it is a common use case to use pattern matching on maps to + The parser returns a map, because in Elixir it is a common use case to use pattern matching on maps to extract specific values and keys. Therefore the `Hocon.decode/2` function returns a map. To support interpreting a value with some family of units, you can call some conversion functions like `as_bytes/1`. @@ -24,6 +24,35 @@ defmodule Hocon do iex> Hocon.as_bytes(limit) 524288 + It is possible to access the unit formats by a keypath, as well: + ## Example + + iex> conf = ~s(a { b { c { limit : "512KB" } } }) + iex> {:ok, map} = Hocon.decode(conf) + iex> Hocon.get_bytes(map, "a.b.c.limit") + 524288 + iex> Hocon.get_size(map, "a.b.c.limit") + 512000 + + ## Include + + HOCON supports including of other configuration files. The default implmentation uses the file systems, which + seems to be the most used use case. For other user cases you can implement the `Hocon.Resolver` behaviour and + call the `decode/2` function with `resolver: MyResolver` as an option. + + ## Example + + The file `include-1.conf` exists and has the following content: + + { x : 10, y : ${a.x} } + + In the case we use the Hocon.FileResolver (which is the default as well): + + iex> conf = ~s({ a : { include "./test/data/include-1" } }) + iex> Hocon.decode(conf, resolver: Hocon.FileResolver) + {:ok, %{"a" => %{"x" => 10, "y" => 10}}} + + To minize the dependencies of other packages, a seperate package will be provided to resolve url resource. """ alias Hocon.Parser @@ -67,12 +96,11 @@ defmodule Hocon do * `:convert_numerically_indexed` - if set to true then numerically-indexed objects are converted to arrays * `:strict_conversion` - if set to `true` then numerically-indexed objects are only converted to arrays if all keys are numbers - * `:resolver` - set to the module, which is responsible for loading the file/url resources. Default is `Hocon.FileResolver` + * `:resolver` - set to the module, which is responsible for loading the file/url resources. The default is `Hocon.FileResolver` ## Example iex> conf = ~s(animal { favorite : "dog" }, key : \"\"\"${animal.favorite} is my favorite animal\"\"\") - "animal { favorite : \\"dog\\" }, key : \\"\\"\\"${animal.favorite} is my favorite animal\\"\\"\\"" iex> Hocon.decode(conf) {:ok, %{"animal" => %{"favorite" => "dog"}, "key" => "dog is my favorite animal"}} diff --git a/mix.exs b/mix.exs index bb35015..90e33a4 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Hocon.MixProject do use Mix.Project - @version "0.1.3" + @version "0.1.4" def project do [ @@ -47,7 +47,7 @@ defmodule Hocon.MixProject do end defp docs() do - [main: "readme", + [main: "Hocon", name: "HOCON", extras: ["README.md"], source_ref: "v#{@version}",