-
Notifications
You must be signed in to change notification settings - Fork 0
/
docgen_test.go
115 lines (83 loc) · 2.28 KB
/
docgen_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package docgen
import (
"log"
"os"
"testing"
)
// TestMain is the root testing method
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
// TestGen tests document generation
func TestGen(t *testing.T) {
err := OutputExamplePdf("test.pdf")
if err != nil {
t.Error(err)
}
}
// OutputExamplePdf is a test method to generate an extremely simple pdf to test initial generation
func OutputExamplePdf(destination string) error {
template := `{#% test marker %#}
I am a test document
hear me roar
I can have included templated content like '{{.include}}'
**and formatted content through markdown**
blah
blah
blah ~ ; test indent with a really reeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeeaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaallllllllllllllllll lllllllllllllllllllll lllllyyyyyyyyyyyyyyyyyyy yyyyyyyyy long line
blah
---
blah
blah
blah
\thead ln shalf ac
| a | b |
| --- | --- |
| test table | with cells |
| and more | cells |
\thead ll sfull ar
| a | b |
| --- | --- |
| test table | with cells |
| and more | cells |
blah
blah
blah
blah
blah
blah ~ !test indent with a really reeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeeaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaallllllllllllllllll lllllllllllllllllllll lllllyyyyyyyyyyyyyyyyyyy yyyyyyyyy long line
\page
blah!
blah
blah ~ test! indent with a really reeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeeaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaallllllllllllllllll lllllllllllllllllllll lllllyyyyyyyyyyyyyyyyyyy yyyyyyyyy long line
blah!`
doc := NewDocument("test", template, nil)
doc.SetDocumentHeader(`# I am a document header, great for titles, and document identifiers
---`)
doc.SetPageHeader(`_header template_ all fancy and shit`)
doc.SetPageFooter(`---
***footer template***, not quite the same, just a little different :::Page {{._page}}:::`)
inputMap := map[string]interface{}{
"include": "Im template included content",
}
doc.AddExtensionFunctions(map[string]interface{}{
"logger": func() string {
log.Print("test")
return ""
},
})
doc.RegisterSubTemplate("test-sub", `blah blah test subtemplate`)
err := doc.Execute(inputMap)
if err != nil {
return err
}
err = doc.RenderToFile(destination)
if err != nil {
return err
}
_, err = doc.RenderToString()
if err != nil {
return err
}
return nil
}