Skip to content

Commit

Permalink
The beginnings of a business letter class. See #453.
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Apr 24, 2017
1 parent c2ce65b commit bd8111d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
71 changes: 71 additions & 0 deletions classes/letter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
local plain = SILE.require("classes/plain")
local letter = plain { id = "letter" }

letter:declareFrame("content", {
left = "5%pw",
right = "95%pw",
top = "2in",
bottom = "90%ph"
})

letter.pageTemplate.firstContentFrame = letter.pageTemplate.frames["content"]

SILE.scratch.letter = {
sender = nil,
date = nil,
recipient = "",
salutation = ""
}

SILE.registerCommand("letter", function(options, content)
SILE.settings.set("current.parindent", SILE.nodefactory.zeroGlue)
SILE.settings.set("document.parindent", SILE.nodefactory.zeroGlue)
SILE.call("raggedright", {}, function()
SILE.call("letter:format:date")
SILE.call("bigskip")
if SILE.scratch.letter.sender then
SILE.call("letter:format:sender")
SILE.call("bigskip")
end
SILE.call("letter:format:recipient")
SILE.call("bigskip")
SILE.call("letter:format:salutation")
SILE.call("bigskip")
SILE.process(content)
end)
end)

SILE.registerCommand("sender", function(options, content)
SILE.scratch.letter.sender = content
end)
SILE.registerCommand("recipient", function(options, content)
SILE.scratch.letter.recipient = content
end)
SILE.registerCommand("salutation", function(options, content)
SILE.scratch.letter.salutation = content
end)
SILE.registerCommand("date", function(options, content)
SILE.scratch.letter.date = content
end)

SILE.registerCommand("letter:format:date", function()
if not SILE.scratch.letter.date then
SILE.scratch.letter.date = { os.date("%A, %d %B") }
end
SILE.process(SILE.scratch.letter.date)
SILE.call("par")
end)

SILE.registerCommand("letter:format:sender", function()
SILE.process(SILE.scratch.letter.sender)
end)

SILE.registerCommand("letter:format:recipient", function()
SILE.process(SILE.scratch.letter.recipient)
end)

SILE.registerCommand("letter:format:salutation", function()
SILE.process(SILE.scratch.letter.salutation)
end)

return letter
9 changes: 9 additions & 0 deletions tests/letter.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\begin[papersize=a5,class=letter]{document}
\recipient{John Doe,\cr
Some Street,\cr
Anytown}
\salutation{Dear John}
\begin{letter}
Hello.
\end{letter}
\end{document}

0 comments on commit bd8111d

Please sign in to comment.