create

package
v0.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2021 License: LGPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package create makes HTML and other web resources from a text file.

Example (BytesStats)
// Disable ANSI color output
color.Enable = false

fmt.Println(bytesStats("filename.txt", 0))
fmt.Println(bytesStats("filename.txt", 123))
fmt.Println(bytesStats("filename.txt", 1234567890))
Output:

saved to filename.txt (zero-byte file)
saved to filename.txt, 123B
saved to filename.txt, 1.23 GB (1234567890)

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrCleanPath = errors.New("cleanup temporary path match failed")
	ErrFileExist = errors.New("filename already exists")
	ErrFileNil   = errors.New("filename cannot be empty")
	ErrFont      = errors.New("unknown font name or family")
	ErrNilByte   = errors.New("cannot convert a nil byte value")
	ErrPorts     = errors.New("cannot run the http server using these ports")
)

Functions

func ColorScheme

func ColorScheme() [3]string

ColorScheme values for the content attribute of <meta name="color-scheme">.

Example
fmt.Print(ColorScheme()[0])
Output:

normal

func FontCSS added in v0.0.31

func FontCSS(name string, e encoding.Encoding, embed bool) ([]byte, error)

FontCSS creates the CSS required for customized fonts.

func Fonts added in v0.0.31

func Fonts() []string

Fonts are values for the CSS font-family attribute.

Example
fmt.Print(Fonts()[2])
Output:

vga

func Layouts

func Layouts() []string

Layouts are the names of the HTML templates.

func Normalize added in v0.0.31

func Normalize(e encoding.Encoding, r ...rune) []byte

Normalize runes into bytes by making adjustments to text control codes.

func Port added in v0.0.31

func Port(port uint) bool

Port checks if the TCP port is available on the local machine.

func Referrer

func Referrer() [8]string

Referrer values for the content attribute of <meta name="referrer">.

Example
fmt.Print(Referrer()[1])
Output:

origin

func Robots

func Robots() [9]string

Robots values for the content attribute of <meta name="robots">.

Example
fmt.Print(Robots()[2])
Output:

follow

Types

type Args

type Args struct {
	Source struct {
		Encoding   encoding.Encoding // Original encoding of the text source
		HiddenBody string            // Pre-text content override, accessible by a hidden flag
		Name       string            // Text source, usually a file or pack name
	}
	Save struct {
		AsFiles     bool   // Save assets as files
		Cache       bool   // Cache, when false will always unpack a new .gohtml template
		Compress    bool   // Compress and store all assets into an archive
		OW          bool   // OW overwrite any existing files when saving
		Destination string // Destination HTML destination either a directory or file
	}
	Title struct {
		Flag  bool
		Value string
	}
	FontFamily struct {
		Flag  bool
		Value string
	}
	Metadata  Meta
	SauceData struct {
		Use         bool
		Title       string
		Author      string
		Group       string
		Description string
		Width       uint
		Lines       uint
	}

	Port      uint   // Port for HTTP server
	FontEmbed bool   // embed the font as Base64 data
	Test      bool   // unit test mode
	Layout    string // Layout of the HTML
	Syntax    string // Syntax and color theming printing HTML
	// contains filtered or unexported fields
}

Args holds arguments and options sourced from user flags and the config file.

func (*Args) Create

func (args *Args) Create(b *[]byte) error

Create handles the target output command arguments.

func (*Args) Serve

func (args *Args) Serve(b *[]byte) error

Serve data over the internal HTTP server.

func (*Args) Stdout

func (args *Args) Stdout(b *[]byte) error

Stdout creates and prints the HTML template.

type Font added in v0.0.31

type Font uint

Font enum.

const (
	// Automatic uses AutoFont to suggest a font.
	Automatic Font = iota
	// Mona is a Japanese language font for ShiftJIS encoding.
	Mona
	// VGA is an all-purpose 8 pixel IBM/MS-DOS era VGA font.
	VGA
)

func AutoFont added in v0.0.31

func AutoFont(e encoding.Encoding) Font

AutoFont applies the automatic font-family setting to suggest a font based on the given encoding.

func Family added in v0.0.31

func Family(name string) Font

Family returns the named font.

func (Font) File added in v0.0.31

func (f Font) File() string

File is the packed filename of the font.

func (Font) String added in v0.0.31

func (f Font) String() string

type Layout added in v0.0.31

type Layout int

Layout are HTML template variations.

const (

	// Standard template with external CSS, JS, fonts.
	Standard Layout
	// Inline template with CSS and JS embedded.
	Inline
	// Compact template with external CSS, JS, fonts and no meta-tags.
	Compact
	// None template, just print the generated HTML.
	None
)

func (Layout) Pack added in v0.0.31

func (l Layout) Pack() string

Pack is the packed name of the HTML template.

func (Layout) String added in v0.0.31

func (l Layout) String() string

type Meta added in v0.0.31

type Meta struct {
	Author struct {
		Flag  bool
		Value string
	}
	ColorScheme struct {
		Flag  bool
		Value string
	}
	Description struct {
		Flag  bool
		Value string
	}
	Keywords struct {
		Flag  bool
		Value string
	}
	Referrer struct {
		Flag  bool
		Value string
	}
	Robots struct {
		Flag  bool
		Value string
	}
	ThemeColor struct {
		Flag  bool
		Value string
	}
	Generator   bool
	NoTranslate bool
	RetroTxt    bool
}

Meta data to embed into the HTML.

type PageData

type PageData struct {
	ExternalEmbed    bool
	FontEmbed        bool
	MetaGenerator    bool
	MetaNoTranslate  bool
	MetaRetroTxt     bool
	BuildVersion     string
	CacheRefresh     string
	Comment          string
	FontFamily       string
	MetaAuthor       string
	MetaColorScheme  string
	MetaDesc         string
	MetaKeywords     string
	MetaReferrer     string
	MetaRobots       string
	MetaThemeColor   string
	PageTitle        string
	PreText          string
	SauceTitle       string
	SauceAuthor      string
	SauceGroup       string
	SauceDescription string
	SauceWidth       uint
	SauceLines       uint
	CSSEmbed         template.CSS
	ScriptEmbed      template.JS
}

PageData temporarily holds template data used for the HTML layout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL