generate

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FOLDER_PERMS = 0755
	FILE_PERMS   = 0644
)

Variables

View Source
var (
	PageNameRegex = regexp.MustCompile(`^[a-z][a-z]+$`)
)

Functions

func FlushFiles

func FlushFiles(modDir string, files []File) error

FlushFiles will write files out to a temp directory and move those files to into the go package

func GoFormat

func GoFormat(path string) (string, error)

GoFormat will execute the go fmt command on the module path

func IsTTY

func IsTTY() bool

IsTTY will check if we have a terminal, should work on Linux or Mac

func ScanSitemap

func ScanSitemap(sitePkg GoPackage) (pages []string, err error)

ScanSitemap will scan the site page package and list pages

func TimeoutScanln

func TimeoutScanln() (string, error)

TimeoutScanln will wait for at most 10 seconds for a line of input from the user

func TryReadModFile

func TryReadModFile() (module string, baseDir string)

TryReadModFile will attempt to load the root module path from a go.mod file it will return empty string otherwise

func ValidatePageLocation

func ValidatePageLocation(pageDir string, scaffold fs.FS) error

ValidatePagePackage will check that a page can be installed at a given location.

If the target directory is not empty, this will scan for conflicts against the scaffold

func ValidatePageName

func ValidatePageName(name string) error

ValidatePageName will check if a page name is permitted to be the name of a site page

func ValidateScaffoldLocation

func ValidateScaffoldLocation(siteDir string, scaffold fs.FS) error

ValidateScaffoldPackage will check that a relative go package path is available for a site scaffold to to be installed and return the go import path and directory for the new scaffold site.

Note that '.' will attempt to install the site in the root directory of the current go module

If the target directory is not empty, this will scan for conflicts against the scaffold

Types

type Entry

type Entry struct {
	Type       string // "SubView" "DefaultSubView" "Spacer"
	Assignment string
	Extends    string
	Block      string
	Template   string
	Handler    string
	Comment    string
}

Entry for the routes.go file

type File

type File struct {
	Dir       string
	Name      string
	Contents  []byte
	Overwrite bool
}

File description and contents that will later be flushed to disk

func PageScaffold

func PageScaffold(sitePkg GoPackage, name string, scaffold fs.FS, starter fs.FS, withResources bool) (files []File, err error)

PageScaffold will assemble files for adding a new page to the site scaffold

func PagesScaffold

func PagesScaffold(sitePkg GoPackage, pages []string, scaffold fs.FS) (file File, err error)

PagesFile creates a new pages.go file by scanning the target scaffold site for directories inside the ./page sub-package

func RoutesScaffold

func RoutesScaffold(
	sitePkg GoPackage,
	pageName string,
	entries []Entry,
	routes []Route,
	templates []HTMLTemplate,
	handlers []Handler,
	scaffold fs.FS,
	hasResources bool,
) (files []File, err error)

RoutesScaffold will generate all files for the good routes command

func SiteScaffold

func SiteScaffold(pkg GoPackage, scaffold fs.FS) (files []File, err error)

SiteScaffold will return a list of files that need to be created

func StarterScaffold

func StarterScaffold(dir string, scaffold, starter fs.FS) (files []File, err error)

StarterScaffold will output a copy of the raw starter template files

func (File) Path

func (f File) Path() string

Path will return the dir+name for this file

type GoModule

type GoModule struct {
	Path string `json:"Path"`
	Dir  string `json:"Dir"`
}

GoModule represents a golang project level module

func GoListModule

func GoListModule(path string) (mod GoModule, err error)

GoListModule will get the Go module information for the import path provied

type GoPackage

type GoPackage struct {
	Dir        string   `json:"Dir"`
	ImportPath string   `json:"ImportPath"`
	Module     GoModule `json:"Module"`
}

GoPackage represents a package within a go module

func GoListPackage

func GoListPackage(path string) (pkg GoPackage, err error)

GoListPackage will get the Go module information for the go path provied

func ParseSitePackage

func ParseSitePackage(mod GoModule, name string) (sitePkg GoPackage, err error)

ParseSitePackage will normalize a relative path from a valid Go module and return a golang package import path and directory path relative to the module dir

func SiteFromPagePackage

func SiteFromPagePackage(pkg GoPackage) (sitePkg GoPackage, err error)

SiteFromPagePackage will construct a site go package given one that refers to a page in that site

func (*GoPackage) Name

func (pkg *GoPackage) Name() string

Name will return the name of the package based on the import path

func (*GoPackage) RelPath

func (pkg *GoPackage) RelPath() (string, error)

RelPath gets the relative import path for the package relative to the module, if will return "." if they are the same

type HTMLTemplate

type HTMLTemplate struct {
	Filepath string
	Path     string
	Blocks   []TemplateBlock
	Block    string
	Merge    string
	Fragment bool
	Partial  bool
	Page     bool
	Name     string
}

HTMLTemplate is data for a page template document

type HandleBlock

type HandleBlock struct {
	FieldName string
	Name      string
}

HandleBlock is the details of sub-views which should be delegated to in the handler

type Handler

type Handler struct {
	Ref        string
	Block      string
	Method     string
	Doc        string
	Identifier string
	Blocks     []HandleBlock
}

Handler is data for a handler function which should be created

type Route

type Route struct {
	Method       string
	Path         string
	Includes     []string
	Reference    string
	PageOnly     bool
	FragmentOnly bool
}

Route is a path mapped to a view definition

type TemplateBlock

type TemplateBlock struct {
	FieldName string
	Name      string
	Views     []TemplateSubView
}

type TemplateSubView

type TemplateSubView struct {
	Ref          string
	Path         string
	POSTOnly     bool
	Default      bool
	FragmentOnly bool
	PageOnly     bool
}

Jump to

Keyboard shortcuts

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