123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package pgenr
- const (
- TextThemeSuccess = "success"
- TextThemeDanger = "danger"
- )
- type (
- TextOption func(t *Text)
- ButtonOption func(btn *Button)
- Text struct {
- Content string
- Theme string
- Color string
- }
- Button struct {
- Url string
- Text string
- Color string
- }
- Entry struct {
- Title string
- Items map[string]*Text
- }
- Action struct {
- Instructions string
- Button *Button
- InviteCode string
- }
- Page struct {
- Title string
- Head string
- Intros []string
- Entries []*Entry
- Actions []Action
- Outros []string
- Copyright string
- }
- )
- func (e *Entry) AddItem(label string, txt *Text) *Entry {
- if e.Items == nil {
- e.Items = make(map[string]*Text)
- }
- e.Items[label] = txt
- return e
- }
- func (page *Page) SetHead(s string) *Page {
- page.Head = s
- return page
- }
- func (page *Page) SetCopyright(s string) *Page {
- page.Copyright = s
- return page
- }
- func (page *Page) AddIntro(s string) *Page {
- page.Intros = append(page.Intros, s)
- return page
- }
- func (page *Page) AddEntry(e *Entry) *Page {
- page.Entries = append(page.Entries, e)
- return page
- }
- func (page *Page) AddButtonAction(s string, btn *Button) *Page {
- page.Actions = append(page.Actions, Action{Instructions: s, Button: btn})
- return page
- }
- func (page *Page) AddInviteCodeAction(s string, code string) *Page {
- page.Actions = append(page.Actions, Action{Instructions: s, InviteCode: code})
- return page
- }
- func (page *Page) AddOutro(s string) *Page {
- page.Outros = append(page.Outros, s)
- return page
- }
- func NewPage(title string) *Page {
- return &Page{
- Title: title,
- Intros: make([]string, 0),
- Entries: make([]*Entry, 0),
- Actions: make([]Action, 0),
- Outros: make([]string, 0),
- }
- }
- func NewEntry(title string) *Entry {
- return &Entry{
- Title: title,
- Items: make(map[string]*Text),
- }
- }
- func WithTextTheme(s string) TextOption {
- return func(t *Text) {
- t.Theme = s
- }
- }
- func WithTextColor(color string) TextOption {
- return func(t *Text) {
- t.Color = color
- }
- }
- func NewButton(label, link string, opts ...ButtonOption) *Button {
- btn := &Button{Text: label, Url: link}
- for _, cb := range opts {
- cb(btn)
- }
- return btn
- }
- func NewText(s string, opts ...TextOption) *Text {
- txt := &Text{Content: s}
- for _, cb := range opts {
- cb(txt)
- }
- return txt
- }
|