-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_example_test.go
More file actions
82 lines (73 loc) · 1.87 KB
/
Copy pathencode_example_test.go
File metadata and controls
82 lines (73 loc) · 1.87 KB
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
// SPDX-License-Identifier: Apache-2.0
package epub_test
import (
"bytes"
"fmt"
"io"
"strings"
"github.com/publira/epub"
"github.com/publira/epub/profile/kadokawa"
"github.com/publira/epub/profile/kindle"
)
func ExampleEncode_preflightWithProfile() {
doc := &epub.Document{
Metadata: epub.Metadata{Title: "My Book"},
Direction: "rtl",
Layout: epub.LayoutPrePaginated,
Assets: map[string]*epub.Asset{
"item/image/p-001.jpg": {
ID: "p-001",
MimeType: "image/jpeg",
Size: 100,
Open: func() (io.ReadCloser, error) {
return io.NopCloser(strings.NewReader("fake")), nil
},
},
},
Pages: []*epub.Page{{Order: 0, AssetID: "p-001", Spread: "right"}},
}
var warnings []string
var out bytes.Buffer
err := epub.Encode(&out, doc,
epub.WithValidator(kadokawa.New()),
epub.WithEncodeWarningCollector(func(w string) { warnings = append(warnings, w) }),
)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(len(warnings), "warning(s)")
// Output:
// 0 warning(s)
}
func ExampleEncode_preflightWithMultipleProfiles() {
doc := &epub.Document{
Metadata: epub.Metadata{Title: "Multi-Profile Book"},
Direction: "rtl",
Layout: epub.LayoutPrePaginated,
Assets: map[string]*epub.Asset{
"item/image/p-001.jpg": {
ID: "p-001",
MimeType: "image/jpeg",
Size: 100,
Open: func() (io.ReadCloser, error) {
return io.NopCloser(strings.NewReader("fake")), nil
},
},
},
Pages: []*epub.Page{{Order: 0, AssetID: "p-001", Spread: "right"}},
}
var warnings []string
var out bytes.Buffer
err := epub.Encode(&out, doc,
epub.WithValidator(kadokawa.New(), kindle.New()),
epub.WithEncodeWarningCollector(func(w string) { warnings = append(warnings, w) }),
)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(len(warnings), "warning(s)")
// Output:
// 0 warning(s)
}