create

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: LGPL-3.0 Imports: 41 Imported by: 0

Documentation

Overview

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

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
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/lib/create"
)

func main() {
	fmt.Print(create.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
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/lib/create"
)

func main() {
	fmt.Print(create.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
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/lib/create"
)

func main() {
	fmt.Print(create.Referrer()[1])
}
Output:

origin

func Robots

func Robots() [9]string

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

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/lib/create"
)

func main() {
	fmt.Print(create.Robots()[2])
}
Output:

follow

func Stats added in v0.0.38

func Stats(name string, nn int) string

Stats humanizes, colorizes and prints the filename and size.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/lib/create"
	"github.com/gookit/color"
)

func main() {
	// Disable ANSI color output
	color.Enable = false

	fmt.Println(create.Stats("filename.txt", 0))
	fmt.Println(create.Stats("filename.txt", 123))
	fmt.Println(create.Stats("filename.txt", 1234567890))
}
Output:

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

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
		BBSType    bbs.BBS           // Optional BBS or ANSI text format
	}
	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  assets.Meta
	SauceData SAUCE
	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
	// internals
	Layouts layout.Layout // layout flag interpretation
	Tmpl    string        // template filename
	Pack    string        // template package name
}

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

func (*Args) Comment added in v0.0.38

func (args *Args) Comment(lb filesystem.LB, r ...rune) string

Comment content for the meta retrotxt attribute.

func (*Args) Create

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

Create handles the target output command arguments.

func (*Args) Marshal added in v0.0.38

func (args *Args) Marshal(b *[]byte) (PageData, error)

Marshal transforms bytes into UTF-8, creates the page meta and template data.

func (*Args) SaveAssets added in v0.0.38

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

func (*Args) SaveHTML added in v0.0.38

func (args *Args) SaveHTML(b *[]byte, c chan error)

SaveHTML creates and save the HTML file.

func (*Args) Serve

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

Serve data over the internal HTTP server.

Example
package main

import (
	"log"

	"github.com/bengarrett/retrotxtgo/lib/create"
	"github.com/bengarrett/retrotxtgo/meta"
)

func main() {
	// Initialize the bare minimum configuration.
	b := []byte("hello world")
	args := create.Args{
		Layout: "standard",
		Port:   meta.WebPort,
	}
	// The test argument will immediately shutdown
	// the server after it successfully starts.
	args.Test = true
	// Run the HTTP server
	if err := args.Serve(&b); err != nil {
		log.Println(err)
	}
}
Output:

Server example was successful

func (*Args) Stdout

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

Stdout creates and prints the HTML template.

func (*Args) TemplateSave added in v0.0.38

func (args *Args) TemplateSave() error

TemplateSave saves an embedded template.

func (*Args) ZipAssets added in v0.0.38

func (args *Args) ZipAssets(destDir string, b *[]byte)

zipAssets compresses all assets into a single zip archive. An empty destination directory argument will save the zip file to the user working directory.

type Asset added in v0.0.38

type Asset int

Asset filenames.

const (
	HTML     Asset = iota // Index html.
	FontCss               // CSS containing fonts.
	StyleCss              // CSS containing styles and colors.
	Scripts               // JS scripts.
	FavIco                // Favorite icon.
	BbsCss                // Other BBS CSS.
	PcbCss                // PCBoard BBS CSS.
)

func (Asset) Write added in v0.0.38

func (a Asset) Write() string

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 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
	HTMLEmbed        template.HTML
	ScriptEmbed      template.JS
}

PageData temporarily holds template data used for the HTML layout.

type SAUCE added in v0.0.38

type SAUCE struct {
	Use         bool
	Title       string
	Author      string
	Group       string
	Description string
	Width       uint
	Lines       uint
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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