Skip to content

Commit edb93fd

Browse files
committed
Add experimental README with mdexp flow
1 parent 99dd82d commit edb93fd

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

README_gen.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# print-table
2+
3+
[![CI Status](https://github.com/mbarbin/print-table/workflows/ci/badge.svg)](https://github.com/mbarbin/print-table/actions/workflows/ci.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/mbarbin/print-table/badge.svg?branch=main)](https://coveralls.io/github/mbarbin/print-table?branch=main)
5+
[![OCaml-CI Build Status](https://img.shields.io/endpoint?url=https://ocaml.ci.dev/badge/mbarbin/print-table/main&logo=ocaml)](https://ocaml.ci.dev/github/mbarbin/print-table)
6+
7+
Print_table provides a minimal library for rendering text tables with Unicode
8+
box-drawing characters and optional ANSI colors:
9+
10+
```ocaml
11+
type row = string * int
12+
13+
let columns : row Print_table.Column.t list =
14+
Print_table.O.
15+
[ Column.make ~header:"Name" (fun (name, _) -> Cell.text name)
16+
; Column.make ~header:"Score" ~align:Right (fun (_, score) ->
17+
Cell.text (Int.to_string score))
18+
]
19+
;;
20+
21+
let rows : row list = [ "Alice", 10; "Bob", 3 ]
22+
let table : Print_table.t = Print_table.make ~columns ~rows
23+
24+
let%expect_test "to_string_text" =
25+
print_endline (Print_table.to_string_text table);
26+
[%expect
27+
{|
28+
┌───────┬───────┐
29+
│ Name │ Score │
30+
├───────┼───────┤
31+
│ Alice │ 10 │
32+
│ Bob │ 3 │
33+
└───────┴───────┘
34+
|}]
35+
;;
36+
```
37+
38+
Tables can be printed as Github-flavored Markdown:
39+
40+
```ocaml
41+
let%expect_test "to_string_markdown" =
42+
print_endline (Print_table.to_string_markdown table);
43+
[%expect
44+
{|
45+
| Name | Score |
46+
|:------|------:|
47+
| Alice | 10 |
48+
| Bob | 3 |
49+
|}]
50+
;;
51+
```
52+
53+
which is rendered natively by GitHub like this:
54+
55+
| Name | Score |
56+
|:------|------:|
57+
| Alice | 10 |
58+
| Bob | 3 |
59+
60+
## Code Documentation
61+
62+
The code documentation of the latest release is built with `odoc` and published to `GitHub` pages [here](https://mbarbin.github.io/print-table).
63+
64+
## Acknowledgments
65+
66+
This library has taken some inspiration from 2 existing and more feature-complete libraries, which we link to here for more advanced usages.
67+
68+
- [Printbox](https://github.com/c-cube/printbox)
69+
- [Ascii_table](https://github.com/janestreet/textutils)

dune

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,43 @@
88
(libraries print-table)
99
(files README.md)
1010
(preludes prelude.txt))
11+
12+
(rule
13+
(target README_gen.md)
14+
(alias runtest)
15+
(package print-table-dev)
16+
(mode promote)
17+
(action
18+
(with-stdout-to
19+
%{target}
20+
(run mdexp pp %{dep:gen_readme.ml}))))
21+
22+
(library
23+
(name readme)
24+
(flags
25+
:standard
26+
-w
27+
+a-4-40-41-42-44-45-48-66-70
28+
-warn-error
29+
+a
30+
-open
31+
Base
32+
-open
33+
Expect_test_helpers_base)
34+
(libraries
35+
base
36+
expect_test_helpers_core.expect_test_helpers_base
37+
print_table)
38+
(inline_tests)
39+
(instrumentation
40+
(backend bisect_ppx))
41+
(lint
42+
(pps ppx_js_style -allow-let-operators -check-doc-comments))
43+
(preprocess
44+
(pps
45+
-unused-code-warnings=force
46+
ppx_compare
47+
ppx_expect
48+
ppx_here
49+
ppx_sexp_conv
50+
ppx_sexp_value)))

gen_readme.ml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
(* @mdexp
2+
3+
# print-table
4+
5+
[![CI Status](https://github.com/mbarbin/print-table/workflows/ci/badge.svg)](https://github.com/mbarbin/print-table/actions/workflows/ci.yml)
6+
[![Coverage Status](https://coveralls.io/repos/github/mbarbin/print-table/badge.svg?branch=main)](https://coveralls.io/github/mbarbin/print-table?branch=main)
7+
[![OCaml-CI Build Status](https://img.shields.io/endpoint?url=https://ocaml.ci.dev/badge/mbarbin/print-table/main&logo=ocaml)](https://ocaml.ci.dev/github/mbarbin/print-table)
8+
9+
Print_table provides a minimal library for rendering text tables with Unicode
10+
box-drawing characters and optional ANSI colors:
11+
*)
12+
13+
(* @mdexp.code *)
14+
type row = string * int
15+
16+
let columns : row Print_table.Column.t list =
17+
Print_table.O.
18+
[ Column.make ~header:"Name" (fun (name, _) -> Cell.text name)
19+
; Column.make ~header:"Score" ~align:Right (fun (_, score) ->
20+
Cell.text (Int.to_string score))
21+
]
22+
;;
23+
24+
let rows : row list = [ "Alice", 10; "Bob", 3 ]
25+
let table : Print_table.t = Print_table.make ~columns ~rows
26+
27+
let%expect_test "to_string_text" =
28+
print_endline (Print_table.to_string_text table);
29+
[%expect
30+
{|
31+
┌───────┬───────┐
32+
NameScore
33+
├───────┼───────┤
34+
Alice10
35+
Bob3
36+
└───────┴───────┘
37+
|}]
38+
;;
39+
40+
(* @mdexp
41+
42+
Tables can be printed as Github-flavored Markdown: *)
43+
44+
(* @mdexp.code *)
45+
let%expect_test "to_string_markdown" =
46+
print_endline (Print_table.to_string_markdown table);
47+
[%expect
48+
{|
49+
| Name | Score |
50+
|:------|------:|
51+
| Alice | 10 |
52+
| Bob | 3 |
53+
|}]
54+
;;
55+
56+
(* @mdexp
57+
58+
which is rendered natively by GitHub like this:
59+
60+
@mdexp.end *)
61+
let%expect_test "snapshot" =
62+
print_endline (Print_table.to_string_markdown table);
63+
(* @mdexp.snapshot *)
64+
[%expect
65+
{|
66+
| Name | Score |
67+
|:------|------:|
68+
| Alice | 10 |
69+
| Bob | 3 |
70+
|}];
71+
()
72+
;;
73+
74+
(* @mdexp
75+
76+
## Code Documentation
77+
78+
The code documentation of the latest release is built with `odoc` and published to `GitHub` pages [here](https://mbarbin.github.io/print-table).
79+
80+
## Acknowledgments
81+
82+
This library has taken some inspiration from 2 existing and more feature-complete libraries, which we link to here for more advanced usages.
83+
84+
- [Printbox](https://github.com/c-cube/printbox)
85+
- [Ascii_table](https://github.com/janestreet/textutils)
86+
*)

0 commit comments

Comments
 (0)