html

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AccessRightAll concerns all the users.
	AccessRightAll = "all"
	// AccessRightSignedIn concerns only the signed in users.
	AccessRightSignedIn = "signedin"
	// AccessRightNotSignedIn concerns only the non-signed in users.
	AccessRightNotSignedIn = "notsignedin"
	// AccessRightAttributes concerns only the users with some attributes.
	AccessRightAttributes = "attributes"
)
View Source
const (
	// SitemapUpdateFrequencyAlways always frequency
	SitemapUpdateFrequencyAlways = "always"
	// SitemapUpdateFrequencyHourly hourly frequency
	SitemapUpdateFrequencyHourly = "hourly"
	// SitemapUpdateFrequencyDaily daily frequency
	SitemapUpdateFrequencyDaily = "daily"
	// SitemapUpdateFrequencyWeekly weekly frequency
	SitemapUpdateFrequencyWeekly = "weekly"
	// SitemapUpdateFrequencyMonthly monthly frequency
	SitemapUpdateFrequencyMonthly = "monthly"
	// SitemapUpdateFrequencyYearly yearly frequency
	SitemapUpdateFrequencyYearly = "yearly"
	// SitemapUpdateFrequencyNever never frequency
	SitemapUpdateFrequencyNever = "never"
)

Variables

View Source
var (
	// LocaleKeyword key of the variable locale.
	LocaleKeyword = "Locale"
	// WebHostKeyword key of the variable webhost.
	WebHostKeyword = "WebHost"
	// StaticHostKeyword key of the variable statichost.
	StaticHostKeyword = "StaticHost"
	// APIHostKeyword key of the variable apihost.
	APIHostKeyword = "ApiHost"
)

Functions

func FormatOpenGraphLocale

func FormatOpenGraphLocale(locale string) string

FormatOpenGraphLocale : returns a locale in the open graph format.

func Initialize

func Initialize(file, webHost, staticHost, apiHost, applicationTimezone string, applicationLocales []string, fallbackLocales map[string]string, JWTCookieName, JWTSecret string, facebookConfiguration FacebookConfiguration, googleConfiguration GoogleConfiguration, socialNetworksConfiguration SocialNetworksConfiguration, betaVersion, isProduction bool)

Initialize : initialize the configuration of the routes.

Types

type AccessRight

type AccessRight string

AccessRight rights to access a page.

type Alternate

type Alternate struct {
	Href  string
	Type  string
	Title string
}

Alternate struct of an alternate resource.

type Async

type Async struct {
	Paths  map[string]string
	Method string
	Target string
}

Async : struct of a passthrough async call.

func (*Async) Prepare

func (async *Async) Prepare(webHost string, applicationLocales []string)

Prepare : sets up the localized urls.

type Configuration

type Configuration struct {
	Default *Page
	Routes  map[string]*Page
	Async   map[string]*Async
	// contains filtered or unexported fields
}

Configuration : struct of the configuration of the routes.

var Main *Configuration

Main : configuration of the routes: singleton.

func (*Configuration) AsyncURL

func (conf *Configuration) AsyncURL(key, locale string) string

AsyncURL : returns the URL of a async url.

func (*Configuration) IsPartial

func (conf *Configuration) IsPartial(key, locale string) bool

IsPartial : returns true if the page is a partial page.

func (*Configuration) Page

func (conf *Configuration) Page(c *gin.Context) *Page

Page : returns the standard page struct with the key and locale.

func (*Configuration) PageByKey

func (conf *Configuration) PageByKey(c *gin.Context, key string) *Page

PageByKey : returns the standard page struct with the key.

func (*Configuration) URL

func (conf *Configuration) URL(key, locale string) string

URL : returns the URL of a page with its locale and some vars.

type Error

type Error struct {
	Message  string
	Reason   string
	Recovery string
}

Error struct containing the properties of an error.

type FacebookConfiguration

type FacebookConfiguration struct {
	Enabled    bool
	AppID      string
	APIVersion string
}

FacebookConfiguration : configuration of the Facebook developer application.

type GoogleConfiguration

type GoogleConfiguration struct {
	Enabled  bool
	ClientID string
}

GoogleConfiguration : configuration of the Google developer application.

type HrefLang

type HrefLang struct {
	Href   string
	Locale string
}

HrefLang struct of a HfreLang tag.

type Icon

type Icon struct {
	Rel    string
	Href   string
	Type   string
	Color  string
	Width  int
	Height int
}

Icon struct of a icon (favicon).

type Info

type Info struct {
	Title   string
	Message string
}

Info struct containing the properties of an info.

type Meta

type Meta struct {
	Charset      string
	Title        string
	Description  string
	Keywords     []string
	CanonicalURL string `yaml:"-"` // Defined by the constructor
	Icons        []Icon
	ImageSource  string `yaml:"image_source"`
	Robots       string
	ViewPort     string
	HrefLang     []HrefLang `yaml:"-"` // Defined by the constructor
	Alternates   []Alternate
	Stylesheets  []Stylesheet
	OpenGraph    OpenGraph
	Twitter      Twitter
}

Meta struct of a HTML meta data.

func (*Meta) Copy

func (meta *Meta) Copy() (copied *Meta)

Copy copied a struct into an other.

func (*Meta) JoinedKeywords

func (meta *Meta) JoinedKeywords() string

JoinedKeywords returns a string containing the keywords separated by a comma.

func (*Meta) Merge

func (meta *Meta) Merge(toMerge Meta)

Merge merges two Meta structs.

type OpenGraph

type OpenGraph struct {
	Title            string
	Description      string
	Image            string
	URL              string
	SiteName         string `yaml:"site_name"`
	Type             string
	Locale           string
	AlternateLocales []string
}

OpenGraph : struct of OpenGraph Meta properties.

func (*OpenGraph) Equals

func (openGraph *OpenGraph) Equals(toCompare *OpenGraph) bool

Equals : returns true if the two structs are equal.

func (*OpenGraph) Merge

func (openGraph *OpenGraph) Merge(toMerge OpenGraph)

Merge : merges two OpenGraph structs.

type Page

type Page struct {
	Locale        string `yaml:"-"` // Defined by the constructor
	Timezone      string `yaml:"-"` // Defined by the constructor
	Paths         map[string]string
	Template      PageTemplate
	AccessRight   AccessRight `yaml:"access"`
	ScriptFiles   []Script    `yaml:"scripts"`
	Meta          Meta
	Title         string
	Sitemap       Sitemap
	Configuration PageConfiguration `yaml:"-"`       // Defined by the constructor
	Content       PageContent       `yaml:"-"`       // Defined by the each script
	Partial       bool              `yaml:"partial"` // true if this page is a partial page (loaded by an ajax call), false if it is a full page.
	Key           string            // The key defining the route in the 'routes' file.
	BetaVersion   bool
	Production    bool
	Vars          map[string]interface{} // Common variables to all the pages.
}

Page struct of a HTML page.

func NewPage

func NewPage() *Page

NewPage : returns a new struct *Page

func (*Page) AsyncURL

func (page *Page) AsyncURL(key string, vars ...map[string]string) string

AsyncURL : returns a localized url (used into the templates).

func (*Page) Copy

func (page *Page) Copy() (copied *Page)

Copy : copies a struct into an other.

func (*Page) Div

func (page *Page) Div(a, b int) int

Div : arithmetic function.

func (*Page) FormattedTime

func (page *Page) FormattedTime(s uint) string

FormattedTime : returns a formatted time (used into the templates).

func (*Page) HTMLEscape

func (page *Page) HTMLEscape(text string) string

HTMLEscape : returns a HTML escaped string (used into the templates).

func (*Page) HTMLEscapeWithNl

func (page *Page) HTMLEscapeWithNl(text string) template.HTML

HTMLEscapeWithNl : replaces the \n to a <br>.

func (*Page) HTMLSafe

func (page *Page) HTMLSafe(text string) template.HTML

HTMLSafe : returns a HTML unescaped string (used into the templates).

func (*Page) IncludeMainTemplate

func (page *Page) IncludeMainTemplate() template.HTML

IncludeMainTemplate : returns the content of the page, used to include the parsed Main template to the Decorator template.

func (*Page) InitializeData

func (page *Page) InitializeData(c *gin.Context)

InitializeData : initializes the data into the page struct before added some keywords.

func (*Page) LocaleVar

func (page *Page) LocaleVar(name, locale string) interface{}

LocaleVar : returns a variable from the list of the variables of the page.

func (*Page) Localize

func (page *Page) Localize(key string, args ...interface{}) string

Localize : returns a localized string (used into the templates).

func (*Page) LocalizeDate

func (page *Page) LocalizeDate(t time.Time) string

LocalizeDate : returns a localized date (used into the templates).

func (*Page) LocalizeDateTime

func (page *Page) LocalizeDateTime(t time.Time) string

LocalizeDateTime : returns a localized date and time (used into the templates).

func (*Page) LocalizeTime

func (page *Page) LocalizeTime(t time.Time) string

LocalizeTime : returns a localized time (used into the templates).

func (*Page) Merge

func (page *Page) Merge(toMerge Page)

Merge : merges two Page structs.

func (*Page) Minus

func (page *Page) Minus(a, b int) int

Minus : arithmetic function.

func (*Page) Mult

func (page *Page) Mult(a, b int) int

Mult : arithmetic function.

func (*Page) Nl2br

func (page *Page) Nl2br(text string) string

Nl2br : replaces the \n to a <br>.

func (*Page) Plus

func (page *Page) Plus(a, b int) int

Plus : arithmetic function.

func (*Page) PreparePaths

func (page *Page) PreparePaths(webHost string, applicationLocales []string, fallbackLocales map[string]string)

PreparePaths : sets up the global page struct.

func (*Page) PrepareWithLocale

func (page *Page) PrepareWithLocale(currentLocale, currentTimezone, webHost, staticHost, apiHost string, supportedLocales []string)

PrepareWithLocale : sets up a specific page struct before added some keywords.

func (*Page) Process

func (page *Page) Process()

Process : replaces the variables into the target properties before processing the templates.

func (*Page) RenderError

func (page *Page) RenderError(c *gin.Context)

RenderError : renders a HTML page with a HTTP code 500.

func (*Page) RenderNotFound

func (page *Page) RenderNotFound(c *gin.Context)

RenderNotFound : renders a HTML page with a HTTP code 404.

func (*Page) RenderOk

func (page *Page) RenderOk(c *gin.Context)

RenderOk : renders a HTML page with a HTTP code 200.

func (*Page) RenderUnauthorized

func (page *Page) RenderUnauthorized(c *gin.Context)

RenderUnauthorized : renders a HTML page with a HTTP code 401.

func (*Page) SetError

func (page *Page) SetError(err response.Error)

SetError : sets up the error of the page.

func (*Page) SetHrefLangParam

func (page *Page) SetHrefLangParam(locale string, params map[string]string)

SetHrefLangParam :

func (*Page) SetInfo

func (page *Page) SetInfo(info Info)

SetInfo : set up the error of the page.

func (*Page) SetLocaleVar

func (page *Page) SetLocaleVar(name, locale string, value interface{})

SetLocaleVar : sets up a variable to the list of the variables of the page with the locale.

func (*Page) SetLocalizedVar

func (page *Page) SetLocalizedVar(name, value string)

SetLocalizedVar : sets up a localized variable to the list of the variables of the page.

func (*Page) SetVar

func (page *Page) SetVar(name string, value interface{})

SetVar : sets up a variable to the list of the variables of the page.

func (*Page) StaticURL

func (page *Page) StaticURL(path string) string

StaticURL : returns the url of a static asset (used into the templates).

func (*Page) URL

func (page *Page) URL(key string, vars ...map[string]string) string

URL : returns a localized url (used into the templates).

func (*Page) UpdateMetaRobots

func (page *Page) UpdateMetaRobots()

UpdateMetaRobots : updates the meta 'robots' accordingl to the sitemap's properties.

func (*Page) Var

func (page *Page) Var(name string) interface{}

Var : returns a variable from the list of the variables of the page.

type PageConfiguration

type PageConfiguration struct {
	Facebook       FacebookConfiguration
	Google         GoogleConfiguration
	SocialNetworks SocialNetworksConfiguration
}

PageConfiguration : set of configurations.

type PageContent

type PageContent struct {
	CurrentUser User
	Title       string
	Error       Error
	Info        Info
	Vars        map[string]interface{}
	// contains filtered or unexported fields
}

PageContent struct of the content of a HTML page containing some variables.

func (*PageContent) HasError

func (content *PageContent) HasError() bool

HasError : returns true if an error is defined.

func (*PageContent) HasInfo

func (content *PageContent) HasInfo() bool

HasInfo : returns true if an info is defined.

func (*PageContent) HasTitle

func (content *PageContent) HasTitle() bool

HasTitle : returns true if a title is defined.

func (*PageContent) IsUserAuthenticated

func (content *PageContent) IsUserAuthenticated() bool

IsUserAuthenticated : returns true if the userID is defined.

type PageTemplate

type PageTemplate struct {
	Decorator string
	Main      string
}

PageTemplate struct containing the properties of templates.

func (*PageTemplate) Merge

func (templates *PageTemplate) Merge(toMerge PageTemplate)

Merge merges two PageTemplate structs.

type Script

type Script struct {
	Src         string
	Integrity   string
	CrossOrigin string
	Defer       bool
	Async       bool
}

Script struct of a script.

type Sitemap

type Sitemap struct {
	Included        bool
	Priority        float32
	UpdateFrequency SitemapUpdateFrequency `yaml:"update_frequency"`
}

Sitemap : struct of the sitemap properties.

func (Sitemap) IsDefined

func (sitemap Sitemap) IsDefined() bool

IsDefined : returns true if the struct is initialized.

type SitemapUpdateFrequency

type SitemapUpdateFrequency string

SitemapUpdateFrequency : update frequencies of a sitemap

func (SitemapUpdateFrequency) String

func (frequency SitemapUpdateFrequency) String() string

String : returns the string value of the frequency.

type SocialNetworksConfiguration

type SocialNetworksConfiguration struct {
	Facebook string
	Google   string
	Twitter  string
}

SocialNetworksConfiguration : configuration of the social network pages.

type Stylesheet

type Stylesheet struct {
	Href        string
	Media       string
	Integrity   string
	CrossOrigin string
}

Stylesheet struct of a stylesheet.

type Twitter

type Twitter struct {
	Card     string
	ImageAlt string `yaml:"image_alt"`
	Site     string // Twitter account i.e. '@cyril'
	Creator  string // Twitter account i.e. '@cyril'

}

Twitter struct of Twitter Meta properties.

func (*Twitter) Merge

func (twitter *Twitter) Merge(toMerge Twitter)

Merge merges two Twitter structs.

type User

type User struct {
	ID      string
	Name    string
	Image1x string
	Image2x string
	Unread  uint
}

User struct containing the properties of a user.

Jump to

Keyboard shortcuts

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