• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/H07-Aug-2018-439357

test/H07-Aug-2018-280234

.gitignoreH A D07-Aug-201834 54

.travis.ymlH A D07-Aug-201878 87

README.mdH A D07-Aug-20185 KiB166134

mix.exsH A D07-Aug-2018663 3832

mix.lockH A D07-Aug-2018935 65

README.md

1## Apex - Awesome Print for Elixir ##
2Awesome Print is an Elixir library that pretty prints Elixir data structures in full color
3exposing their internal structure with proper indentation. It's a port of part of the functionality
4of Ruby's awesome [awesome_print gem](https://github.com/michaeldv/awesome_print).
5
6### Installation ###
7In order to install it via hex, add the reference to this package into the `deps` area of your `mix.exs`.
8
9```elixir
10  defp deps do
11    [
12      {:apex, "~>1.2.1"}
13    ]
14  end
15```
16
17### Examples ###
18
19```elixir
20data = [false, 42, ~w(forty two), [time: "now"], %{foo: :bar}]
21
22Apex.ap data
23
24# Will output the following:
25#[
26#   [0] false
27#   [1] 42
28#   [2] [
29#     [0] "forty"
30#     [1] "two"
31#   ]
32#   [3] [
33#     [0] time: "now"
34#   ]
35#   [4] %{
36#      foo: bar
37#   }
38#]
39#
40#[false, 42, ~w(forty two), [time: "now"], %{foo: :bar}]
41```
42
43If the numbering is not for you, you can turn it off via `Apex.ap(data, numbers: false)`.
44
45### Supported types
46
47* BitString
48* Integer
49* Float
50* Atom
51* List
52* Range
53* PID
54* Port
55* Function
56* MapSet
57* Map
58* Tuple
59* Reference
60* Elixir Records
61* Elixir Structs
62
63`Apex` uses a protocol internally to format a given value. If there's something not yet in the box, you can extend the protocol `Apex.Format`.
64
65### Color customizations
66You can customize the `Apex` colors on a per project or global basis. For project
67specific color configuration, you can specify the color table in your `config/config.ex`
68
69```elixir
70use Mix.Config
71
72config :apex, :colors, %{
73  binary: :red
74}
75```
76
77This can alternatively also be done at runtime by using the `Application.put_env/3` function.
78
79Please note, that you only have to specify the colors you actively want to change here. For
80the rest `Apex` will fallback to the defaults.
81
82If you want to apply the same settings across multiple elixir projects, you can drop a `.apexrc`
83file into your home directory in order do the same thing. The configuration is an `Elixir` Map.
84
85```elixir
86%{
87  colors: %{
88    binary: :yellow,
89    true:   [:green, :bright]
90  }
91}
92```
93
94__IMPORTANT:__ the global configuration will get compiled into your `Apex` version when
95you compile your app. You need to recompile `Apex` via `mix deps.compile apex` when
96you want to apply changes to the `.apexrc` file.
97
98__PRECEDENCE:__ When both project specific and global configuration
99are present, project specific configuration will take precedence.
100
101For a full list of all available customizations, please take a look at the result of `Apex.Format.Color.default_colors/0)`.
102
103### Awesome def aka adef
104Inspired by [@sasajuric](https://github.com/sasa1977)'s [awesome blog post series about macros](http://www.theerlangelist.com/search/label/metaprogramming), Apex also contains an Apex flavored version of his `deftracable` macro. By using `adef` instead of `def`
105
106```elixir
107import Apex.AwesomeDef
108adef test(data, options \\ []) do
109  data
110end
111```
112
113all function invocations print trace outputs in the following format to the group leader (console):
114
115```bash
116iex(1)> Apex.test "foo"
117>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
118Function Elixir.Apex.test was called
119defined in /Users/bjoernrochel/Coding/Laboratory/apex/lib/apex.ex:12
120----------------------------------------------------------------------------------------------------
121Parameters:
122----------------------------------------------------------------------------------------------------
123[
124  [0] "foo"
125  [1] []
126]
127
128----------------------------------------------------------------------------------------------------
129Result:
130----------------------------------------------------------------------------------------------------
131"foo"
132```
133
134### Note on Patches/Pull Requests ###
135* Fork the project on Github.
136* Make your feature addition or bug fix.
137* Add tests for it, making sure $ mix test is all green.
138* Do not rebase other commits than your own
139* Do not change the version in the mix file
140* Commit
141* Send me a pull request
142
143### License ###
144(The MIT License)
145
146Copyright (c) 2014-2018 Björn Rochel
147
148Permission is hereby granted, free of charge, to any person obtaining
149a copy of this software and associated documentation files (the
150'Software'), to deal in the Software without restriction, including
151without limitation the rights to use, copy, modify, merge, publish,
152distribute, sublicense, and/or sell copies of the Software, and to
153permit persons to whom the Software is furnished to do so, subject to
154the following conditions:
155
156The above copyright notice and this permission notice shall be
157included in all copies or substantial portions of the Software.
158
159THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
160EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
162IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
163CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
164TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
165SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
166