dwtpl

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: GPL-3.0 Imports: 9 Imported by: 4

README

Template Manager

Modul untuk keperluan templating aplikasi web, menggunakan module template standar html/template

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Dir    string `yaml:"dir"`
	Cached bool   `yaml:"cached"`
}

type DeviceType

type DeviceType string
const (
	DeviceMobile  DeviceType = "mobile"
	DeviceTablet  DeviceType = "tablet"
	DeviceDesktop DeviceType = "desktop"
)

type Layout

type Layout struct {
	Name   string `yaml:"name"`
	Device struct {
		Mobile  []string `yaml:"mobile"`
		Tablet  []string `yaml:"tablet"`
		Desktop []string `yaml:"desktop"`
	} `yaml:"device"`
}

type PageConfig

type PageConfig struct {
	Name        string   `yaml:"name"`
	Title       string   `yaml:"title"`
	Description string   `yaml:"description"`
	Tags        []string `yaml:"tags"`
	Device      struct {
		Mobile  []string `yaml:"mobile"`
		Tablet  []string `yaml:"tablet"`
		Desktop []string `yaml:"desktop"`
	} `yaml:"device"`
	Auth bool `yaml:"auth"`
	// contains filtered or unexported fields
}

type PageTemplate

type PageTemplate struct {
	Config *PageConfig
	Data   map[DeviceType]*template.Template
}

type TemplateManager

type TemplateManager struct {
	// contains filtered or unexported fields
}

func New

func New(config *Configuration, opt ...string) (*TemplateManager, error)

siapkan template manager sebelum memanggil ini, harus panggil dwtpl.New() terlebih dahulu

func (*TemplateManager) CachePages

func (mgr *TemplateManager) CachePages(dir string) error

CachePages caches the pages in the specified directory by parsing the page templates and storing them in the cache.

Parameters: - dir: The directory containing the pages to cache.

Returns: - error: An error if there was a problem parsing the page templates or if the pattern could not be obtained.

func (*TemplateManager) GetCachedPage

func (mgr *TemplateManager) GetCachedPage(pagename string) (*PageTemplate, bool)

GetCachedPage retrieves a cached page template based on the page name and device type.

Parameters: - pagename: The name of the page to retrieve. - device: The type of device for which the page template is needed. Returns: - *template.Template: The cached page template. - bool: A boolean indicating if the page template was found in the cache.

func (*TemplateManager) GetConfiguration

func (mgr *TemplateManager) GetConfiguration() *Configuration

GetConfiguration returns the configuration of the TemplateManager.

This function returns a pointer to the Configuration struct stored in the TemplateManager. It allows the caller to access and modify the configuration.

Returns: - *Configuration: A pointer to the Configuration struct.

func (*TemplateManager) GetLayoutFiles

func (mgr *TemplateManager) GetLayoutFiles(dir string) (map[DeviceType][]string, bool, error)

func (*TemplateManager) GetOptions

func (mgr *TemplateManager) GetOptions() []string

GetOptions returns the options stored in the TemplateManager.

No parameters. Returns a slice of strings representing the options.

func (*TemplateManager) GetPage

func (mgr *TemplateManager) GetPage(pagename string) (pagetemplate *PageTemplate, err error)

GetPage retrieves a page template for the specified page name and device type.

Parameters: - pagename: the name of the page to retrieve the template for. - device: the device type for which the page template is requested.

Returns: - *template.Template: the retrieved page template, or nil if not found. - bool: true if the page template exists, false otherwise. - error: an error if there was a problem retrieving the page template.

func (*TemplateManager) GetPageConfig

func (mgr *TemplateManager) GetPageConfig(dir string) (*PageConfig, error)

func (*TemplateManager) ParseTemplate

func (mgr *TemplateManager) ParseTemplate(pagename string, pagesdatadir string) (*PageTemplate, error)

ParsePageTemplate parses the page template for a given page name and data directory.

Parameters: - pagename: the name of the page (string) - pagesdatadir: the directory where the page data is located (string)

Returns: - tpldata: a map of device types to template.Template objects (map[DeviceType]*template.Template) - ispage: a boolean indicating whether the page directory exists (bool) - err: an error if there was an issue parsing the page template (error)

func (*TemplateManager) SetLogOutput

func (mgr *TemplateManager) SetLogOutput(w io.Writer)

SetLogOutput sets the output writer for the logger of the TemplateManager.

It takes a parameter `w` of type `io.Writer`, which represents the writer to which the logger output will be redirected. The function updates the logger's output writer with the provided writer.

func (*TemplateManager) SetOptions

func (mgr *TemplateManager) SetOptions(opt ...string)

SetOptions sets the options for the TemplateManager.

It takes a variadic parameter `opt` of type string, which represents the options to be set. The function updates the `options` field of the TemplateManager with the provided options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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