Ecobolic
A small library that should ease the implementation of a !help feature in chat bot
This library aims to provide a simple way of declaring and accessing
documentations meant for users. This was build mainly to ease the implementation
of the well-known help command, that many chat-bots provide.
Usage
Declaring
The first step is to use the Ecbolic module in the module you want to
declare your documentations:
defmodule TestModule do
use EcbolicThen you can add document your functions like this:
@doc """
It's thanks to the 1.7 elixir update that we can add meta data to the @doc annotation
"""
Ecbolic.help("returns `:world`")
def hello, do: :world
At the start of your Application, or whenever you need it, you must load the documentation with with load_help/0
Testmodule.load_help()Accessing
To access the documentations you can call the function Ecbolic.fetch_help, which comes in a variaty of forms:
- Ecbolic.fetch_help() Returns the documentation for all functions
- Ecbolic.fetch_help(functions) Returns the documentaion for the given functions
- Ecbolic.fetch_help(fuction) Returns the documentation for the given function
Example
Ecbolic.fetch_help(:hello)
#=> "returns `:world`"Formating
The module Ecbolic.Pretty provides some basic formating:
Ecbolic.Pretty.format(:hello)
#=> "hello - returns `world`"
You can provide your own format as a second parameter to Ecbolic.Pretty.format/2.
The default format is ":f - :h"
Currently these are the tokens available for formating:
:f
Inserts the functions name
:h
Inserts the documentation
:a
If multiple entries are supplied, this token will align the strings, by filling them with spaces, until they all end at the same position.
##### Example:
```elixir
Ecbolic.Pretty.format([:hello, :long_function_name], ":f:a - :h")
#=> [
"hello - returns `world`",
"long_function_name - Long description"
]
```Note: if the function is not found, it’ll be skipped
Installation
If available in Hex, the package can be installed
by adding ecbolic to your list of dependencies in mix.exs:
def deps do
[
{:ecbolic, "~> 0.2.4"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ecbolic.