model

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 4 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABTest added in v2.7.0

type ABTest struct {
	GTMKey string `json:"abtest_gtm_key"` // key for GTM to differentiate test pages.
}

ABTest contains all information needed for ABTesting - this is separated for expansion in future.

type BackTo

type BackTo struct {
	AnchorFragment string       `json:"anchor_fragment"`
	Text           Localisation `json:"text"`
}
BackTo maps the back to component.

AnchorFragment refers to the anchor fragment on the page to link to, leave empty to display the default '#'. Text refers to the display text that can be either a 'Localisation.Text' or a 'Localisation.LocaleKey'.

type Collapsible

type Collapsible struct {
	Title            Localisation      `json:"title"`
	CollapsibleItems []CollapsibleItem `json:"collapsible_item"`
	Language         string            `json:"language"`
}

Collapsible maps the collapsible UI component. The title text can be either a 'Title' or a 'LocaliseKey', the question mark will always render at the end. The 'LocaliseKey' has to correspond to the localisation key found in the toml files within assets/locales, otherwise the page will error. LocalisePluralInt refers to the plural int used in the toml file. Language should be passed in from the Page model.

type CollapsibleItem

type CollapsibleItem struct {
	Subheading string       `json:"subheading"`
	Content    []string     `json:"content"`
	SafeHTML   Localisation `json:"safe_html"`
}

CollapsibleItem is an individual representation of the data required in a collapsible item

type CompactSearch

type CompactSearch struct {
	ElementId  string       `json:"element_id"`
	InputName  string       `json:"input_name"`
	Language   string       `json:"language"`
	Label      Localisation `json:"label"`
	SearchTerm string       `json:"search_term"`
}
CompactSearch provides an input for a search term.

ElementId is the id in the document. InputName is the name submitted in a form. Language should be passed in from the Page model. Label states the purpose of the search term. SearchTerm is the user input submitted in a form.

type ContentSection

type ContentSection struct {
	Current bool         `json:"current"`
	Title   Localisation `json:"title"`
}
ContentSection maps the content details.

The visible text can be either a 'Localisation.Text' or a 'Localisation.LocaleKey'. The 'LocaleKey' has to correspond to the localisation key found in the toml files within assets/locales, otherwise the page will error. Plural refers to the plural int used in the toml file.

type CookiesPolicy

type CookiesPolicy struct {
	Essential bool `json:"essential"`
	Usage     bool `json:"usage"`
}

CookiesPolicy contains data for the users cookie policy

type DataAttribute added in v2.4.0

type DataAttribute struct {
	Key   template.HTMLAttr `json:"key"`
	Value Localisation      `json:"value"`
}

DataAttribute represents the data struct required to display a data attribute

type DateFieldset added in v2.9.0

type DateFieldset struct {
	ErrorID                  string         `json:"error_id"`                   // HTML id attribute used within a field validation error
	Input                    InputDate      `json:"input"`                      // HTML date input attributes
	Language                 string         `json:"language"`                   // Passed in from the Page model
	ValidationErrDescription []Localisation `json:"validation_err_description"` // String array that describes the validation error
}

DateFieldset defines the HTML for a date input

func (DateFieldset) FuncHasDateValidationErr added in v2.9.0

func (d DateFieldset) FuncHasDateValidationErr() bool

FuncHasDateValidationErr helper function that returns true if any of the date input fields have a validation error

type EmergencyBanner

type EmergencyBanner struct {
	Type        string `json:"type"`
	Title       string `json:"title"`
	Description string `json:"description"`
	URI         string `json:"uri"`
	LinkText    string `json:"link_text"`
}

EmergencyBanner data

type Error

type Error struct {
	Title       string      `json:"title"`       // The error title and populates the <title> element
	Description string      `json:"description"` // Free text to describe the error
	ErrorItems  []ErrorItem `json:"error_items"` // Array of error item
	Language    string      `json:"language"`    // User defined language
	ErrorCode   int         `json:"error_code"`  // Http error code e.g. 401, 404, 500
}

Error contains data to display a client page error

type ErrorItem

type ErrorItem struct {
	Description Localisation `json:"description"` // Can be either a 'Localisation.Text' or a 'Localisation.LocaleKey'
	Language    string       `json:"language"`    // User defined language
	ID          string       `json:"id"`          // HTML id attribute used within a field validation error
	URL         string       `json:"url"`         // The href to the error
}

ErrorItem represents an error item.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type FeatureFlags

type FeatureFlags struct {
	EnableCensusBanner     bool   `json:"enable_census_banner"`
	EnableCensusTile       bool   `json:"enable_census_tile"`
	EnableGetDataCard      bool   `json:"enable_get_data_card"`
	HideCookieBanner       bool   `json:"hide_cookie_banner"`
	ONSDesignSystemVersion string `json:"ons_design_system_version"`
	SixteensVersion        string `json:"legacy_sixteens_version"`
	EnableFeedbackAPI      bool   `json:"enable_feedback_api"`
	FeedbackAPIURL         string `json:"feedback_api_url"` // technically not a feature flag, but used exclusivly with one
	IsPublishing           bool   `json:"is_publishing"`
}

FeatureFlags contains toggles for certain features on the website

type Feedback added in v2.4.0

type Feedback struct {
	Description TextareaField `json:"description"`
	NameInput   TextField     `json:"name_input"`
	EmailInput  TextField     `json:"email_input"`
}

type Input

type Input struct {
	Autocomplete   string          `json:"autocomplete"`    // Renders the autocomplete browser functionality for the input
	DataAttributes []DataAttribute `json:"data_attributes"` // Renders a key/value pair of data attributes automatically prepended with 'data-'
	Description    Localisation    `json:"description"`     // Human readable additional content to support the label
	ID             string          `json:"id"`              // Unique element ID
	IsChecked      bool            `json:"is_checked"`      // Boolean representing whether the element is checked
	IsDisabled     bool            `json:"is_disabled"`     // Boolean representing whether the element is disabled
	IsRequired     bool            `json:"is_required"`     // Boolean representing whether the element is required
	Label          Localisation    `json:"label"`           // Human readable label
	Language       string          `json:"language"`        // Passed from the Page model
	Name           string          `json:"name"`            // Name attribute used for model binding
	Type           InputType       `json:"type"`            // Input type - default 'text'
	Value          string          `json:"value"`           // Value sent to the server
}

Input represents the common attributes and elements for html input. Some properties are not rendered if they are invalid attributes for the type.

func (Input) FuncGetInputType added in v2.1.0

func (i Input) FuncGetInputType() (inputType string)

FuncGetInputType returns the input type as a string

type InputDate

type InputDate struct {
	Language              string       `json:"language"`
	Id                    string       `json:"id"`
	InputNameDay          string       `json:"input_name_day"`
	InputNameMonth        string       `json:"input_name_month"`
	InputNameYear         string       `json:"input_name_year"`
	InputValueDay         string       `json:"input_value_day"`
	InputValueMonth       string       `json:"input_value_month"`
	InputValueYear        string       `json:"input_value_year"`
	HasDayValidationErr   bool         `json:"has_day_validation_err"`
	HasMonthValidationErr bool         `json:"has_month_validation_err"`
	HasYearValidationErr  bool         `json:"has_year_validation_err"`
	Title                 Localisation `json:"title"`
	Description           Localisation `json:"description"`
}

InputDate provides an input for a date. Language should be passed in from the Page model. Id is the id in the document. InputNameDay is the name submitted for the day in a form. InputNameMonth is the name submitted for the month in a form. InputNameYear is the name submitted for the year in a form. InputValueDay is the user input submitted for the day in a form. InputValueMonth is the user input submitted for the month in a form. InputValueYear is the user input submitted for the year in a form. HasDayValidationErr displays a validation error for the day input field. HasMonthValidationErr displays a validation error for the month input field. HasYearValidationErr displays a validation error for the year input field. Title states the purpose of the date. Description offers a further explanation for the purpose of the date.

type InputType added in v2.1.0

type InputType int
const (
	Text InputType = iota
	Email
	Tel
	Url
)

type Localisation

type Localisation struct {
	Text      string `json:"text"`
	LocaleKey string `json:"locale_key"`
	Plural    int    `json:"plural"`
}

Localisation offers text or a localised substitute. Text is displayed as-is. LocaleKey is a key into the toml files found in assets/locales. Plural chooses the singular or plural form of the phrase selected by LocaleKey.

func (Localisation) FuncLocalise

func (localisation Localisation) FuncLocalise(language string) string

Localise by preference when a LocaleKey is provided, defaulting to Text otherwise.

type Metadata

type Metadata struct {
	Title       string   `json:"title"`
	Description string   `json:"description"`
	ServiceName string   `json:"serviceName"`
	Keywords    []string `json:"keywords"`
}

Metadata ...

type NavigationItem struct {
	Uri      string           `json:"uri"`
	Label    string           `json:"label"`
	SubItems []NavigationItem `json:"sub_items"`
}

NavigationItem contains all information needed to render the navigation bar and submenus

type Page

type Page struct {
	Count                            int              `json:"count"`
	Type                             string           `json:"type"`
	DatasetId                        string           `json:"dataset_id"`
	DatasetTitle                     string           `json:"dataset_title"`
	URI                              string           `json:"uri"`
	Taxonomy                         []TaxonomyNode   `json:"taxonomy"`
	Breadcrumb                       []TaxonomyNode   `json:"breadcrumb"`
	IsInFilterBreadcrumb             bool             `json:"is_in_filter_breadcrumb"`
	ServiceMessage                   string           `json:"service_message"`
	Metadata                         Metadata         `json:"metadata"`
	SearchDisabled                   bool             `json:"search_disabled"`
	SiteDomain                       string           `json:"-"`
	PatternLibraryAssetsPath         string           `json:"-"`
	Language                         string           `json:"language"`
	IncludeAssetsIntegrityAttributes bool             `json:"-"`
	ReleaseDate                      string           `json:"release_date"`
	BetaBannerEnabled                bool             `json:"beta_banner_enabled"`
	CookiesPreferencesSet            bool             `json:"cookies_preferences_set"`
	CookiesPolicy                    CookiesPolicy    `json:"cookies_policy"`
	HasJSONLD                        bool             `json:"has_jsonld"`
	FeatureFlags                     FeatureFlags     `json:"feature_flags"`
	Error                            Error            `json:"error"`
	EmergencyBanner                  EmergencyBanner  `json:"emergency_banner"`
	Collapsible                      Collapsible      `json:"collapsible"`
	Pagination                       Pagination       `json:"pagination"`
	TableOfContents                  TableOfContents  `json:"table_of_contents"`
	BackTo                           BackTo           `json:"back_to"`
	SearchNoIndexEnabled             bool             `json:"search_no_index_enabled"`
	NavigationContent                []NavigationItem `json:"navigation_content"`
	PreGTMJavaScript                 []template.JS    `json:"pre_gtm_javascript"`
	RemoveGalleryBackground          bool             `json:"remove_gallery_background"`
	Feedback                         Feedback         `json:"feedback"`
	Enable500ErrorPageStyling        bool             `json:"enable_500_error_page_styling"` // flag for hiding standard page "furniture" (header, nav, etc.)
	ABTest
}

Page contains data re-used for each page type a Data struct for data specific to the page type

func NewPage

func NewPage(path, domain string) Page

NewPage instantiates the base Page type with configurable fields

func (Page) FuncFeedback added in v2.4.0

func (p Page) FuncFeedback() Feedback

FuncFeedback is a helper function that binds appropriate properties to the model on instantiation

type PageToDisplay

type PageToDisplay struct {
	PageNumber int    `json:"page_number"`
	URL        string `json:"url"`
}

PageToDisplay represents a page to display in pagination with their corresponding URL

type Pagination

type Pagination struct {
	CurrentPage       int             `json:"current_page"`
	PagesToDisplay    []PageToDisplay `json:"pages_to_display"`
	FirstAndLastPages []PageToDisplay `json:"first_and_last_pages"`
	TotalPages        int             `json:"total_pages"`
	Limit             int             `json:"limit"`
	LimitOptions      []int           `json:"limit_options,omitempty"`
}

Pagination represents all information regarding pagination of search results

func (Pagination) FuncPhraseCurrentPage

func (pagination Pagination) FuncPhraseCurrentPage(progress, language string) string

Produces a string of the form "Current page (Page 5 of 10)"

func (Pagination) FuncPhraseGoToFirstPage

func (pagination Pagination) FuncPhraseGoToFirstPage(language string) string

Produces a string of the form "Go to the first page (Page 1)"

func (Pagination) FuncPhraseGoToLastPage

func (pagination Pagination) FuncPhraseGoToLastPage(language string) string

Produces a string of the form "Go to the last page (Page 10)"

func (Pagination) FuncPhraseGoToNextPage

func (pagination Pagination) FuncPhraseGoToNextPage(language string) string

Produces a string of the form "Go to the next page (Page 6)"

func (Pagination) FuncPhraseGoToPreviousPage

func (pagination Pagination) FuncPhraseGoToPreviousPage(language string) string

Produces a string of the form "Go to the previous page (Page 4)"

func (Pagination) FuncPhrasePageNOfTotal

func (pagination Pagination) FuncPhrasePageNOfTotal(n int, language string) string

Produces a string of the form "Page 1 of 10"

func (Pagination) FuncPhrasePaginationProgress

func (pagination Pagination) FuncPhrasePaginationProgress(progress, language string) string

Produces a string of the form "Pagination (Page 1 of 10)"

func (Pagination) FuncPickNextURL

func (pagination Pagination) FuncPickNextURL() string

func (Pagination) FuncPickPreviousURL

func (pagination Pagination) FuncPickPreviousURL() string

func (Pagination) FuncShowLinkToFirst

func (pagination Pagination) FuncShowLinkToFirst() bool

func (Pagination) FuncShowLinkToLast

func (pagination Pagination) FuncShowLinkToLast() bool

type Radio

type Radio struct {
	Input      Input `json:"input"`       // HTML input attributes
	OtherInput Input `json:"other_input"` // Conditionally displays an additional text input
}

Radio defines the fields for a radio input

type RadioFieldset

type RadioFieldset struct {
	Language      string        `json:"language"`       // Passed in from the Page model
	Legend        Localisation  `json:"legend"`         // Content within legend html element
	Radios        []Radio       `json:"radios"`         // Radios within the fieldset
	ValidationErr ValidationErr `json:"validation_err"` // Fields for validation model against the fieldset
}

RadioFieldset defines the HTML fieldset for radio inputs

type ShareLink struct {
	Type               SocialType
	Url                string
	RequiresJavaScript bool
}

Represents an instance of a link URL for a specific shared resource

type SocialType

type SocialType int

Enumerates known social types that allow sharing a resource via a link URL

const (
	SocialUnknown SocialType = iota
	SocialEmail
	SocialFacebook
	SocialLinkedin
	SocialTwitter
)
func (s SocialType) CreateLink(title, target string) ShareLink

Creates a ShareLink from the supplied resource title and target URL

func (SocialType) String

func (s SocialType) String() string

Stringer interface

type Table

type Table struct {
	Variants     []string      `json:"variants"`      // Possible variants: "compact", "responsive", "scrollable", "sortable", and "row-hover"
	TableClasses string        `json:"table_classes"` // Additional classes appended to the HTML class attribute
	Id           string        `json:"id"`            // HTML id attribute
	Caption      string        `json:"caption"`       // Content of the HTML caption
	HideCaption  bool          `json:"hide_caption"`  // When true, visually hides the caption
	AriaLabel    string        `json:"aria_label"`    // The ARIA label to be added if ”scrollable” variant set, to inform screen reader users that the table can be scrolled. Defaults to “Scrollable table“.
	TableHeaders []TableHeader `json:"table_headers"` // An array of column headers, required
	TableRows    []TableRow    `json:"trs"`           // An array or data rows, required
	SortBy       string        `json:"sort_by"`       // Required the "sortable" variant, sets the data-aria-sort attribute for the table. Used as a prefix for the aria-label to announce to screen readers when the table is sorted by a column. For example, “Sort by Date, ascending”
	AriaAsc      string        `json:"aria_asc"`      // Required by "sortable" variant, sets the data-aria-asc attribute for the table. Used to update aria-sort attribute to announce to screen readers how a table is sorted by a column, for example, “Sort by Date, ascending“
	AriaDesc     string        `json:"aria_desc"`     // Required by "sortable" variant, sets the data-aria-desc attribute for the table. Used to update aria-sort attribute to announce to screen readers how a table is sorted by a column, for example, “Sort by Date, descending“
	TableFooters []TableFooter `json:"table_footers"` // An array of cells for the footer of each column
}

Table displays data in a variety of tabular styles that can be combined in Variants

func (Table) FuncContainsVariant

func (table Table) FuncContainsVariant(variant string) bool

Tests for the presence of a known variant in the options supplied by the user

type TableData

type TableData struct {
	TdClasses string     `json:"td_classes"` // Additional classes appended to the HTML class attribute
	Id        string     `json:"id"`         // HTML id attribute
	Name      string     `json:"name"`       // HTML name attribute
	Data      string     `json:"data"`       // Required by the responsive variant, sets the data-th attribute for this cell to its matching column header
	DataSort  string     `json:"data_sort"`  // Required by the sortable variant, sets the numerical order of a table cell in a column
	Value     string     `json:"value"`      // Cell content
	Numeric   bool       `json:"numeric"`    // When true, right aligns content for easier comparison of numeric data
	Form      *TableForm `json:"form"`       // Settings for a form within the cell
}

TableData defines an individual data cell

type TableFooter

type TableFooter struct {
	Value string `json:"value"` // Cell content in the footer, required
}

Defines a column footer

type TableForm

type TableForm struct {
	Method           string                 `json:"method"`             // HTML method attribute, defaults to "POST"
	Action           string                 `json:"action"`             // HTML action attribute, required
	Button           TableFormButton        `json:"button"`             // Button shown to the user, required
	HiddenFormFields []TableFormHiddenField `json:"hidden_form_fields"` // Hidden form inputs
}

TableForm can be placed in data cells to present a TableFormButton

type TableFormButton

type TableFormButton struct {
	Text    string `json:"text"`    // Label text, required
	Id      string `json:"id"`      // HTML id attribute
	Name    string `json:"name"`    // HTML name attribute
	Value   string `json:"value"`   // HTML value attribute
	Url     string `json:"url"`     // Link destination
	Classes string `json:"classes"` // Additional classes appended to the HTML class attribute
}

Defines the form button visible in a data cell

type TableFormHiddenField

type TableFormHiddenField struct {
	Name  string `json:"name"` // HTML input name attribute
	Value string `json:"vale"` // HTML input value attribute
}

Defines hidden form input fields

type TableHeader

type TableHeader struct {
	ThClasses string `json:"th_classes"` // Additional classes appended to the HTML class attribute
	AriaSort  string `json:"aria_sort"`  // Set to “ascending” or “descending” to set the default order of a table column when the page loads when setting variants to “sortable”. Defaults to “none”
	Value     string `json:"value"`      // Header content
	Numeric   bool   `json:"numeric"`    // When true, right aligns content for easier comparison of numeric data
}

TableHeader defines column headers

type TableOfContents

type TableOfContents struct {
	Id           string                    `json:"id"`
	AriaLabel    Localisation              `json:"aria_label"`
	Title        Localisation              `json:"title"`
	Sections     map[string]ContentSection `json:"sections"`
	DisplayOrder []string                  `json:"display_order"`
}

TableOfContents contains the contents of the page

type TableRow

type TableRow struct {
	TableData []TableData `json:"table_data"` // An array of data cells populating the row, required
	Id        string      `json:"id"`         // HTML id attribute
	Name      string      `json:"name"`       // HTML name attribute
	Highlight bool        `json:"highlight"`  // When true, highlights the row
}

TableRow holds rows of data

type TaxonomyNode

type TaxonomyNode struct {
	Title    string         `json:"title"`
	URI      string         `json:"uri"`
	Type     string         `json:"type,omitempty"`
	Children []TaxonomyNode `json:"children,omitempty"`
}

TaxonomyNode ...

type TextField

type TextField struct {
	Input         Input         `json:"input"`          // HTML input attributes
	ValidationErr ValidationErr `json:"validation_err"` // fields for validation model against the field
}

TextField defines the fields for a text input element

type TextareaField

type TextareaField struct {
	Input         Input         `json:"input"`          // HTML input attributes
	ValidationErr ValidationErr `json:"validation_err"` // fields for validation model against the field
}

TextareaField defines the fields for a textarea element

type ValidationErr

type ValidationErr struct {
	ErrorItem        ErrorItem `json:"error_item"`         // Fields for an error item
	HasValidationErr bool      `json:"has_validation_err"` // Bool check to display additional html required for a field error
}

ValidationErr defines the fields for a field validation error

Jump to

Keyboard shortcuts

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