@@ -17,7 +17,316 @@ Lua module wrapping the [doclayout] Haskell package.
1717[ Stackage Nightly badge ] : http://stackage.org/package/hslua-module-doclayout/badge/nightly
1818[ License badge ] : https://img.shields.io/badge/license-MIT-blue.svg
1919
20- # License
20+
21+ Example
22+ -------
23+
24+ ``` haskell
25+ loadProg :: Lua Status
26+ loadProg = do
27+ openlibs
28+ preloadModule " doclayout"
29+ dostring $ unlines
30+ [ " doc = require 'doclayout'"
31+ , " local example_doc = (doc.literal 'Line' + 'One')"
32+ , " // (doc.literal 'Line' + 'Two')"
33+ , " -- prints:"
34+ , " -- Line One"
35+ , " --"
36+ , " -- Line Two"
37+ , " print(doc.render(example_doc))"
38+ , " "
39+ , " -- prints:"
40+ , " -- Line"
41+ , " -- One"
42+ , " --"
43+ , " -- Line"
44+ , " -- Two"
45+ , " local columns = 5"
46+ , " print(doc.render(example_doc, columns))"
47+ ]
48+ ```
49+
50+
51+ Documentation
52+ -------------
53+
54+ ### Functions
55+
56+ #### render
57+
58+ ` render (doc[, colwidth]) `
59+
60+ Render the ` Doc ` using the given column width.
61+
62+ Parameters:
63+
64+ ` doc `
65+ : Doc to render
66+
67+ ` colwidth `
68+ : Maximum number of characters per line
69+
70+ #### concat
71+
72+ ` concat (docs[, sep]) `
73+
74+ Concatenate the given ` Doc ` s, interspersing ` sep ` if specified.
75+
76+ Parameters:
77+
78+ ` docs `
79+ : List of ` Doc ` s
80+
81+ ` sep `
82+ : Separator ` Doc `
83+
84+ ### Doc construction
85+
86+ All functions return a fresh ` Doc ` element.
87+
88+ #### after_break
89+
90+ ` after_break `
91+
92+ Creates a ` Doc ` which is conditionally included only if it
93+ comes at the beginning of a line.
94+
95+ #### before_non_blank
96+
97+ ` before_non_blank (doc) `
98+
99+ Conditionally includes the given ` Doc ` unless it is followed by
100+ a blank space.
101+
102+ #### blankline
103+
104+ ` blankline `
105+
106+ Inserts a blank line unless one exists already.
107+
108+ #### blanklines
109+
110+ ` blanklines (n) `
111+
112+ Insert blank lines unless they exist already.
113+
114+ Parameters:
115+
116+ ` n `
117+ : Number of blank lines to insert.
118+
119+ #### braces
120+
121+ ` braces (doc) `
122+
123+ Puts a ` Doc ` in curly braces.
124+
125+ #### brackets
126+
127+ ` brackets (doc) `
128+
129+ Puts a ` Doc ` in square brackets.
130+
131+ #### cblock
132+
133+ ` cblock (width, doc) `
134+
135+ Like ` lblock ` but aligned centered.
136+
137+ Parameters:
138+
139+ ` width `
140+ : Width of the created block, in characters
141+
142+ ` doc `
143+ : Contents of the block ([ Doc] )
144+
145+ #### chomp
146+
147+ ` chomp (doc) `
148+
149+ Chomps trailing blank space off of a ` Doc ` .
150+
151+ #### cr
152+
153+ A carriage return. Does nothing if we're at the beginning of a
154+ line; otherwise inserts a newline.
155+
156+ #### double_quotes
157+
158+ ` double_quotes (doc) `
159+
160+ Wraps a ` Doc ` in double quotes
161+
162+ #### empty
163+
164+ The empty document.
165+
166+ #### flush
167+
168+ ` flush (doc) `
169+
170+ Makes a ` Doc ` flush against the left margin.
171+
172+ #### hang
173+
174+ ` hang (indent, start, doc) `
175+
176+ Creates a hanging indent.
177+
178+ Parameters:
179+
180+ ` indent `
181+ : Indentation width in characters
182+
183+ ` start `
184+ : Start, printed unindented
185+
186+ ` doc `
187+ : Doc which is indented by ` indent ` spaces on every line.
188+
189+ #### inside
190+
191+ ` inside (start, end, contents) `
192+
193+ Encloses a ` Doc ` inside a start and end ` Doc ` .
194+
195+ Parameters:
196+
197+ ` start `
198+ : Doc before contents
199+
200+ ` end `
201+ : Doc after contents
202+
203+ ` contents `
204+ : Contents Doc
205+
206+ #### lblock
207+
208+ ` lblock (width, doc) `
209+
210+ Creates a block with the given width and content, aligned to the left.
211+
212+ Parameters:
213+
214+ ` width `
215+ : Width of the created block, in characters
216+
217+ ` doc `
218+ : Contents of the block ([ Doc] )
219+
220+
221+ #### literal
222+
223+ ` literal (string) `
224+
225+ Creates a ` Doc ` from a string.
226+
227+ #### nest
228+
229+ ` nest (indent) `
230+
231+ Indents a ` Doc ` by the specified number of spaces.
232+
233+ Parameters:
234+
235+ ` indent `
236+ : Indentation width.
237+
238+ #### nestle
239+
240+ ` nestle (doc) `
241+
242+ Removes leading blank lines from a ` Doc ` .
243+
244+ #### nowrap
245+
246+ ` nowrap (doc) `
247+
248+ Makes a ` Doc ` non-reflowable.
249+
250+ #### parens
251+
252+ ` parens (doc) `
253+
254+ Puts a ` Doc ` in parentheses.
255+
256+ #### prefixed
257+
258+ ` prefixed (prefix, doc) `
259+
260+ Uses the specified string as a prefix for every line of the
261+ inside document (except the first, if not at the beginning of the
262+ line).
263+
264+ Parameters:
265+
266+ ` prefix `
267+ : Prefix to prepend to each line
268+
269+ ` doc `
270+ : Inside Doc.
271+
272+ #### quotes
273+
274+ ` quotes (doc) `
275+
276+ Wraps a ` Doc ` in single quotes.
277+
278+ #### rblock
279+
280+ ` rblock (indent, doc) `
281+
282+ Like ` lblock ` but aligned to the right.
283+
284+ Parameters:
285+
286+ ` width `
287+ : Width of the created block, in characters
288+
289+ ` doc `
290+ : Contents of the block ([ Doc] )
291+
292+ #### space
293+
294+ A breaking (reflowable) space.
295+
296+ #### vfill
297+
298+ ` vfill `
299+
300+ Creates an expandable border that, when placed next to a box,
301+ expands to the height of the box.
302+
303+ Parameters:
304+
305+ ` text `
306+ : Border text
307+
308+ ### Operators
309+
310+ #### ` .. `
311+
312+ Concatenate two ` Doc ` elements.
313+
314+ #### ` + `
315+
316+ Concatenate two ` Doc ` s, inserting a reflowable space between them.
317+
318+ #### ` / `
319+
320+ If ` a ` and ` b ` are ` Doc ` elements, then ` a / b ` puts ` a ` above ` b ` .
321+
322+ #### ` // `
323+
324+ If ` a ` and ` b ` are ` Doc ` elements, then ` a // b ` puts ` a ` above
325+ ` b ` , inserting a blank line between them.
326+
327+
328+ License
329+ -------
21330
22331This package is made available under the MIT license. See [ ` LICENSE ` ] ( LICENSE )
23332for details.
0 commit comments