Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/book/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cmd implements the book CLI.
package cmd

import (
Expand All @@ -23,10 +24,12 @@ var (
version = "internal"
)

// SetVersion sets the application version string used by the CLI.
func SetVersion(v string) {
version = v
}

// Main builds and runs the book CLI application.
func Main() {
var confirm bool
var interactive bool
Expand Down
6 changes: 3 additions & 3 deletions cmd/book/mark.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ func addMark(bs *book.BookShelves, URL string, tags string, shelfName string, co
}

mark := book.Mark{
Id: id,
Url: URL,
ID: id,
URL: URL,
Tags: strings.Split(tags, ","),
}

// Use provided title or fetch from URL
if title != "" {
mark.Name = title
} else {
fetchedTitle, err := web.LoadWebsite(mark.Url)
fetchedTitle, err := web.LoadWebsite(mark.URL)
if err != nil {
return err
}
Expand Down
46 changes: 34 additions & 12 deletions internal/book/templates.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
package book

// Templatable defines the view-model interface used to render TUI success screens.
type Templatable interface {
Primary() string
Secondary() string
List() []string
}

// Template interface methods
func (s *BookShelves) Primary() string { return "" }
func (s *BookShelves) Secondary() string { return "" }
func (s *BookShelves) List() []string { return s.ShelfNames() }
// Primary returns an empty string for BookShelves.
func (bs *BookShelves) Primary() string { return "" }

func (s *Shelf) Primary() string { return s.Name }
// Secondary returns an empty string for BookShelves.
func (bs *BookShelves) Secondary() string { return "" }

// List returns the names of all shelves.
func (bs *BookShelves) List() []string { return bs.ShelfNames() }

// Primary returns the shelf name.
func (s *Shelf) Primary() string { return s.Name }

// Secondary returns an empty string for Shelf.
func (s *Shelf) Secondary() string { return "" }
func (s *Shelf) List() []string { return s.CollectionsNames() }

func (s *Collection) Primary() string { return s.Shelf.Name }
func (s *Collection) Secondary() string { return s.Name }
func (s *Collection) List() []string { return s.MarksNames() }
// List returns the names of all collections in the shelf.
func (s *Shelf) List() []string { return s.CollectionsNames() }

// Primary returns the parent shelf name.
func (c *Collection) Primary() string { return c.Shelf.Name }

// Secondary returns the collection name.
func (c *Collection) Secondary() string { return c.Name }

// List returns the names of all marks in the collection.
func (c *Collection) List() []string { return c.MarksNames() }

// Primary returns the mark title.
func (m *Mark) Primary() string { return m.Name }

// Secondary returns the mark URL.
func (m *Mark) Secondary() string { return m.URL }

func (s *Mark) Primary() string { return s.Name }
func (s *Mark) Secondary() string { return s.Url }
func (s *Mark) List() []string { return s.Tags }
// List returns the mark's tags.
func (m *Mark) List() []string { return m.Tags }

// ViewTemplate used to templatize TUI success screens
type ViewTemplate struct {
Expand Down Expand Up @@ -61,6 +81,7 @@ func markTemplate(primary string) ViewTemplate {
}
}

// DefaultViewTemplates provides the built-in TUI success-screen templates.
var DefaultViewTemplates = map[string]ViewTemplate{
"shelf-list": {ListTitle: "You've knocked over all your shelves:"},
"shelf-add": {PrimaryTitle: "You added shelf:", SecondaryTitle: "Along chosen collection:"},
Expand All @@ -76,6 +97,7 @@ var DefaultViewTemplates = map[string]ViewTemplate{
"mark-delete": markTemplate("To delete mark:"),
}

// UserViewTemplates holds user-defined template overrides loaded at runtime.
var UserViewTemplates = map[string]ViewTemplate{}

// GetTemplate merges user overrides over the default for a given key.
Expand Down
Loading
Loading