Skip to content

Commit 9429a8c

Browse files
committed
Ensure main document is always the first function argument
Makes it easier to use functions as methods.
1 parent 2941a35 commit 9429a8c

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/HsLua/Module/DocLayout.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ brackets = defun "brackets"
355355
-- | Like @'lblock'@ but aligned centered.
356356
cblock :: LuaError e => DocumentedFunction e
357357
cblock = defun "cblock"
358-
### liftPure2 Doc.cblock
359-
<#> parameter peekIntegral "integer" "width" "block width in chars"
358+
### liftPure2 (flip Doc.cblock)
360359
<#> docParam "doc"
360+
<#> parameter peekIntegral "integer" "width" "block width in chars"
361361
=#> docResult ("doc, aligned centered in a block with max" <>
362362
"`width` chars per line.")
363363
#? ("Creates a block with the given width and content, " <>
@@ -377,7 +377,7 @@ concat = defun "concat"
377377
### liftPure2 (\docs optSep -> mconcat $
378378
maybe docs (`intersperse` docs) optSep)
379379
<#> parameter (peekList peekDoc) "`{Doc,...}`" "docs" "list of Docs"
380-
<#> opt (parameter peekDoc "Doc" "sep" "separator")
380+
<#> opt (parameter peekDoc "Doc" "sep" "separator (default: none)")
381381
=#> docResult "concatenated doc"
382382
#? "Concatenates a list of `Doc`s."
383383

@@ -400,31 +400,31 @@ flush = defun "flush"
400400
-- | Creates a hanging indent.
401401
hang :: LuaError e => DocumentedFunction e
402402
hang = defun "hang"
403-
### liftPure3 Doc.hang
403+
### liftPure3 (\doc ind start -> Doc.hang ind start doc)
404+
<#> docParam "doc"
404405
<#> parameter peekIntegral "integer" "ind" "indentation width"
405406
<#> docParam "start"
406-
<#> docParam "doc"
407407
=#> docResult ("`doc` prefixed by `start` on the first line, " <>
408408
"subsequent lines indented by `ind` spaces.")
409409
#? "Creates a hanging indent."
410410

411411
-- | Encloses a @'Doc'@ inside a start and end @'Doc'@.
412412
inside :: LuaError e => DocumentedFunction e
413413
inside = defun "inside"
414-
### liftPure3 Doc.inside
414+
### liftPure3 (\contents start end -> Doc.inside start end contents)
415+
<#> docParam "contents"
415416
<#> docParam "start"
416417
<#> docParam "end"
417-
<#> docParam "contents"
418418
=#> docResult "enclosed contents"
419419
#? "Encloses a `Doc` inside a start and end `Doc`."
420420

421421
-- | Creates a block with the given width and content, aligned to
422422
-- the left.
423423
lblock :: LuaError e => DocumentedFunction e
424424
lblock = defun "lblock"
425-
### liftPure2 Doc.lblock
426-
<#> parameter peekIntegral "integer" "width" "block width in chars"
425+
### liftPure2 (flip Doc.lblock)
427426
<#> docParam "doc"
427+
<#> parameter peekIntegral "integer" "width" "block width in chars"
428428
=#> docResult "doc put into block with max `width` chars per line."
429429
#? ("Creates a block with the given width and content, " <>
430430
"aligned to the left.")
@@ -440,9 +440,9 @@ literal = defun "literal"
440440
-- | Indents a @'Doc'@ by the specified number of spaces.
441441
nest :: LuaError e => DocumentedFunction e
442442
nest = defun "nest"
443-
### liftPure2 Doc.nest
444-
<#> parameter peekIntegral "integer" "ind" "indentation size"
443+
### liftPure2 (flip Doc.nest)
445444
<#> docParam "doc"
445+
<#> parameter peekIntegral "integer" "ind" "indentation size"
446446
=#> docResult "`doc` indented by `ind` spaces"
447447
#? "Indents a `Doc` by the specified number of spaces."
448448

@@ -476,9 +476,9 @@ parens = defun "parens"
476476
-- the line).
477477
prefixed :: LuaError e => DocumentedFunction e
478478
prefixed = defun "prefixed"
479-
### liftPure2 Doc.prefixed
480-
<#> parameter peekString "string" "prefix" "prefix for each line"
479+
### liftPure2 (flip Doc.prefixed)
481480
<#> docParam "doc"
481+
<#> parameter peekString "string" "prefix" "prefix for each line"
482482
=#> docResult "prefixed `doc`"
483483
#? ("Uses the specified string as a prefix for every line of " <>
484484
"the inside document (except the first, if not at the " <>
@@ -495,9 +495,9 @@ quotes = defun "quotes"
495495
-- | Like @'rblock'@ but aligned to the right.
496496
rblock :: LuaError e => DocumentedFunction e
497497
rblock = defun "rblock"
498-
### liftPure2 Doc.rblock
499-
<#> parameter peekIntegral "integer" "width" "block width in chars"
498+
### liftPure2 (flip Doc.rblock)
500499
<#> docParam "doc"
500+
<#> parameter peekIntegral "integer" "width" "block width in chars"
501501
=#> docResult ("doc, right aligned in a block with max" <>
502502
"`width` chars per line.")
503503
#? ("Creates a block with the given width and content, " <>

test/test-doclayout.lua

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ return {
5050
test('inside', function ()
5151
local doc = doclayout.literal 'Hello,' + 'World!'
5252
assert.are_equal(
53-
doclayout.inside('Yo! ', ' Wassup?', doc),
53+
doclayout.inside(doc, 'Yo! ', ' Wassup?'),
5454
'Yo! ' .. doc .. ' Wassup?'
5555
)
5656
end),
@@ -120,11 +120,11 @@ return {
120120
assert.are_equal(doclayout.render(doc), '[1]')
121121
end),
122122
test('flush', function ()
123-
local doc = doclayout.flush(doclayout.nest(2, 'hi'))
123+
local doc = doclayout.flush(doclayout.nest('hi', 2))
124124
assert.are_equal(doclayout.render(doc), 'hi')
125125
end),
126126
test('hang', function ()
127-
local doc = doclayout.hang(4, ' - ', 'aa\nbb\ncc')
127+
local doc = doclayout.hang('aa\nbb\ncc', 4, ' - ')
128128
assert.are_equal(
129129
doclayout.render(doc),
130130
table.concat{
@@ -135,7 +135,7 @@ return {
135135
)
136136
end),
137137
test('nest', function ()
138-
local doc = doclayout.nest(2, 'aa\n\nbb\ncc')
138+
local doc = doclayout.nest('aa\n\nbb\ncc', 2)
139139
assert.are_equal(
140140
doclayout.render(doc),
141141
table.concat{
@@ -155,31 +155,31 @@ return {
155155
assert.are_equal(doclayout.render(doc), '(lisp)')
156156
end),
157157
test('prefixed', function ()
158-
local doc = doclayout.prefixed('# ', doclayout.literal 'aa' // 'bb')
158+
local doc = doclayout.prefixed(doclayout.literal 'aa' // 'bb', '# ' )
159159
assert.are_equal(doclayout.render(doc), '# aa\n#\n# bb')
160160
end),
161161
group 'table helpers' {
162162
test('cblock', function ()
163-
local doc = doclayout.cblock(2, '| ')
164-
.. doclayout.cblock(4, 'aa')
165-
.. doclayout.cblock(2, ' |')
163+
local doc = doclayout.cblock('| ', 2)
164+
.. doclayout.cblock('aa', 4)
165+
.. doclayout.cblock(' |', 2)
166166
assert.are_equal(doclayout.render(doc), '| aa |')
167167
end),
168168
test('lblock', function ()
169-
local doc = doclayout.lblock(2, '| ')
170-
.. doclayout.lblock(4, 'aa')
171-
.. doclayout.lblock(2, ' |')
169+
local doc = doclayout.lblock('| ', 2)
170+
.. doclayout.lblock('aa', 4)
171+
.. doclayout.lblock(' |', 2)
172172
assert.are_equal(doclayout.render(doc), '| aa |')
173173
end),
174174
test('rblock', function ()
175-
local doc = doclayout.rblock(2, '| ')
176-
.. doclayout.rblock(4, 'aa')
177-
.. doclayout.rblock(2, ' |')
175+
local doc = doclayout.rblock('| ', 2)
176+
.. doclayout.rblock('aa', 4)
177+
.. doclayout.rblock(' |', 2)
178178
assert.are_equal(doclayout.render(doc), '| aa |')
179179
end),
180180
test('vfill', function ()
181181
local doc = doclayout.vfill '| '
182-
.. doclayout.lblock(4, doclayout.literal 'aa' // 'bbb')
182+
.. doclayout.lblock(doclayout.literal 'aa' // 'bbb', 4)
183183
.. doclayout.vfill(' |')
184184
assert.are_equal(
185185
doclayout.render(doc),

0 commit comments

Comments
 (0)