-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.go
More file actions
112 lines (93 loc) · 2.11 KB
/
settings.go
File metadata and controls
112 lines (93 loc) · 2.11 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
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
package fairytale
import (
"fmt"
"github.com/gosimple/slug"
)
type IFrameSize [2]int
var (
SizeDesktop = IFrameSize{0, 0}
Size_iPhone_11_Pro = IFrameSize{375, 812}
)
var IFrameSizes = [...]IFrameSize{
SizeDesktop,
Size_iPhone_11_Pro,
}
func MustIFrameSizeFromString(s string) IFrameSize {
size, err := IFrameSizeFromString(s)
if err != nil {
panic(err)
}
return size
}
func IFrameSizeFromString(s string) (IFrameSize, error) {
for _, size := range IFrameSizes {
if size.String() == s {
return size, nil
}
}
return [2]int{}, fmt.Errorf("fairytale: cannot create iFrameSize from string '%s'", s)
}
func (i *IFrameSize) Swap() {
i[0], i[1] = i[1], i[0]
}
func (i IFrameSize) Equal(other IFrameSize) bool {
return i[0] == other[0] && i[1] == other[1]
}
func (i IFrameSize) String() string {
switch i {
case SizeDesktop:
return "Desktop"
case Size_iPhone_11_Pro:
return "iPhone 11 Pro"
default:
panic(fmt.Errorf("fairytale: unknown IFrameSize: %d, %d", i[0], i[1]))
}
}
func (i IFrameSize) Slug() string {
return slug.Make(i.String())
}
type Orientation int
const (
Portrait Orientation = iota
Landscape
)
var Orientations = [...]Orientation{
Portrait,
Landscape,
}
func MustOrientationFromString(s string) Orientation {
orientation, err := OrientationFromString(s)
if err != nil {
panic(err)
}
return orientation
}
func OrientationFromString(s string) (Orientation, error) {
for _, orientation := range Orientations {
if orientation.String() == s {
return orientation, nil
}
}
return -1, fmt.Errorf("fairytale: cannot create orientation from string '%s'", s)
}
func (r Orientation) String() string {
switch r {
case Portrait:
return "Portrait"
case Landscape:
return "Landscape"
default:
panic(fmt.Errorf("fairytale: unknown orientation: %d", r))
}
}
func (r Orientation) Slug() string {
return slug.Make(r.String())
}
func orientationFromSlug(s string) (Orientation, error) {
for _, orientation := range Orientations {
if orientation.Slug() == s {
return orientation, nil
}
}
return -1, fmt.Errorf("fairytale: cannot create orientation from slug '%s'", s)
}