Skip to content

Commit 87fd397

Browse files
committed
Allow setting a doc below another via "devision"
1 parent 1d825f4 commit 87fd397

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/Foreign/Lua/Module/DocLayout.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
import Data.Text (Text)
5959
import Foreign.Lua (Lua, NumResults (..), Optional,
6060
Peekable, Pushable, StackIndex)
61-
import Text.DocLayout ((<+>), Doc)
61+
import Text.DocLayout (Doc, (<+>), ($$))
6262

6363
import qualified Data.Text as T
6464
import qualified Foreign.Lua as Lua
@@ -251,6 +251,7 @@ pushDoc = Lua.pushAnyWithMetatable pushDocMT
251251
pushDocMT = Lua.ensureUserdataMetatable docTypeName $ do
252252
Lua.addfunction "__add" __add
253253
Lua.addfunction "__concat" __concat
254+
Lua.addfunction "__div" __div
254255
Lua.addfunction "__eq" __eq
255256
Lua.addfunction "__tostring" __tostring
256257

@@ -265,6 +266,10 @@ __add a b = return (a <+> b)
265266
__concat :: Doc Text -> Doc Text -> Lua (Doc Text)
266267
__concat a b = return (a <> b)
267268

269+
-- | @a / b@ puts @a@ above @b@.
270+
__div :: Doc Text -> Doc Text -> Lua (Doc Text)
271+
__div a b = return (a $$ b)
272+
268273
-- | Test @'Doc'@ equality.
269274
__eq :: Doc Text -> Doc Text -> Lua Bool
270275
__eq a b = return (a == b)

test/test-doclayout.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ return {
5555
end),
5656

5757
test('adding concatenates with space', function ()
58-
local helloworld = doclayout.literal "Hello,"
58+
local helloworld = doclayout.literal 'Hello,'
5959
.. doclayout.space
60-
.. doclayout.literal "World"
60+
.. doclayout.literal 'World'
6161
assert.are_equal(doclayout.literal 'Hello,' + 'World', helloworld)
62-
end)
62+
end),
63+
64+
test('dividing sets the first above the second', function ()
65+
local first = doclayout.literal 'first'
66+
local second = doclayout.literal 'second'
67+
assert.are_equal(first / second, first .. doclayout.cr .. second)
68+
end),
6369
}
6470
}

0 commit comments

Comments
 (0)