component

package
v0.0.0-...-52fdeaf Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedExtensions = map[string]bool{
	".jpg":  true,
	".jpeg": true,
	".png":  true,
	".gif":  true,
	".svg":  true,
}

SupportedExtensions contains the image formats supported for processing

Functions

func APIConfigGetName

func APIConfigGetName() string

APIConfigGetName returns the HyperBricks type associated with the APIConfig.

func APIConfigGetName_test

func APIConfigGetName_test(t *testing.T)

func CssConfigGetName

func CssConfigGetName() string

CssConfigGetName returns the HyperBricks type associated with the CssConfig.

func HTMLConfigGetName

func HTMLConfigGetName() string

HTMLConfigGetName returns the HyperBricks type associated with the HTMLConfig.

func JavaScriptConfigGetName

func JavaScriptConfigGetName() string

JavaScriptConfigGetName returns the HyperBricks type associated with the JavaScriptConfig.

func LocalJSONConfigGetName

func LocalJSONConfigGetName() string

LocalJSONConfigGetName returns the HyperBricks type associated with the LocalJSONConfig.

func MenuConfigGetName() string

MenuConfigGetName returns the HyperBricks type associated with the MenuConfig.

func MultipleImagesConfigGetName

func MultipleImagesConfigGetName() string

MultipleImagesConfigGetName returns the HyperBricks type associated with the MultipleImagesConfig.

func PluginRenderGetName

func PluginRenderGetName() string

LinkConfigGetName returns the HyperBricks type associated with the PluginConfig.

func SingleImageConfigGetName

func SingleImageConfigGetName() string

SingleImageConfigGetName returns the HyperBricks type associated with the SingleImageConfig.

func SortHyperMediasBySection

func SortHyperMediasBySection(pagesBySection map[string][]composite.HyperMediaConfig, options SortOptions) (map[string][]composite.HyperMediaConfig, error)

SortHyperMediasBySection creates a sorted copy of pagesBySection based on the provided options. It returns the sorted copy and an error if the SortBy option is invalid.

func StyleConfigGetName

func StyleConfigGetName() string

StyleConfigGetName returns the HyperBricks type associated with the StyleConfig.

func TextConfigGetName

func TextConfigGetName() string

TextConfigGetName returns the HyperBricks type associated with the TextConfig.

Types

type APIConfig

type APIConfig struct {
	shared.Component `mapstructure:",squash"`
	Endpoint         string            `mapstructure:"endpoint" validate:"required" description:"The API endpoint" example:"{!{api-endpoint.hyperbricks}}"`
	Method           string            `` /* 152-byte string literal not displayed */
	Headers          map[string]string `mapstructure:"headers" description:"Optional HTTP headers for API requests" example:"{!{api-headers.hyperbricks}}"`
	Body             string            `` /* 198-byte string literal not displayed */
	Template         string            `` /* 136-byte string literal not displayed */
	IsTemplate       bool              `mapstructure:"istemplate"`
	User             string            `mapstructure:"user" description:"User for basic auth" example:"{!{api-user.hyperbricks}}"`
	Pass             string            `mapstructure:"pass" description:"User for basic auth" example:"{!{api-pass.hyperbricks}}"`
}

Basic config for ComponentRenderers

func (*APIConfig) Validate

func (api *APIConfig) Validate() []error

Validate ensures the API configuration is correct.

type APIRenderer

type APIRenderer struct {
	renderer.ComponentRenderer
}

APIRenderer handles rendering of data fetched from an API endpoint.

func (*APIRenderer) Render

func (ar *APIRenderer) Render(instance interface{}) (string, []error)

Render processes API data and outputs it according to the specified template.

func (*APIRenderer) Types

func (r *APIRenderer) Types() []string

type CssConfig

type CssConfig struct {
	shared.Component `mapstructure:",squash"`
	Inline           string `` /* 147-byte string literal not displayed */
	Link             string `mapstructure:"link" description:"Use link for a link tag" example:"{!{css-link.hyperbricks}}"`
	File             string `` /* 160-byte string literal not displayed */
}

CssConfig represents the configuration for the style renderer.

func (*CssConfig) Validate

func (css *CssConfig) Validate() []error

Validate ensures the CSS file exists and is readable.

type CssRenderer

type CssRenderer struct{}

CssRenderer handles rendering of CSS content from a file, inline multiline or link

func (*CssRenderer) Render

func (sr *CssRenderer) Render(instance interface{}) (string, []error)

Render reads the CSS file content and outputs it wrapped in <style> tags with extra attributes.

func (*CssRenderer) Types

func (r *CssRenderer) Types() []string

type HTMLConfig

type HTMLConfig struct {
	shared.Component `mapstructure:",squash"`
	Value            string `mapstructure:"value" validate:"required" description:"The raw HTML content" example:"{!{html-value.hyperbricks}}"`
	TrimSpace        bool   `mapstructure:"trimspace"  description:"The raw HTML content" example:"{!{html-value.hyperbricks}}"`
}

HTMLConfig represents configuration for raw HTML.

func (*HTMLConfig) Validate

func (hc *HTMLConfig) Validate() []error

Validate ensures that the HTML content is not empty.

type HTMLRenderer

type HTMLRenderer struct{}

HTMLRenderer handles rendering of raw HTML content.

func (*HTMLRenderer) Render

func (hr *HTMLRenderer) Render(instance interface{}) (string, []error)

Render processes raw HTML data and outputs it, applying wrapping if specified.

func (*HTMLRenderer) Types

func (r *HTMLRenderer) Types() []string

type HyperMediaConfig

type HyperMediaConfig struct {
	Title string `json:"title"`
	Route string `json:"route"`
	Index int    `json:"index"`
}

HyperMediaConfig represents configuration for a single page in the menu.

type ImageProcessor

type ImageProcessor struct{}

ImageProcessor handles rendering and processing of images

func (*ImageProcessor) ProcessMultipleImages

func (ir *ImageProcessor) ProcessMultipleImages(config MultipleImagesConfig) (string, error)

ProcessMultipleImages processes multiple images and adjusts their dimensions if width/height is specified

func (*ImageProcessor) ProcessSingleImage

func (ir *ImageProcessor) ProcessSingleImage(config SingleImageConfig) (string, error)

ProcessSingleImage processes a single image and generates the HTML

func (*ImageProcessor) Render

func (ir *ImageProcessor) Render(instance interface{}) (string, error)

Render processes the image rendering based on the instance configuration

type JavaScriptConfig

type JavaScriptConfig struct {
	shared.Component `mapstructure:",squash"`
	Inline           string `` /* 168-byte string literal not displayed */
	Link             string `mapstructure:"link" description:"Use link for a script tag with a src attribute" example:"{!{javascript-link.hyperbricks}}"`
	File             string `` /* 168-byte string literal not displayed */
}

JavaScriptConfig represents the configuration for the JavaScript renderer.

func (*JavaScriptConfig) Validate

func (js *JavaScriptConfig) Validate() []error

Validate ensures the JavaScript file exists and is readable.

type JavaScriptRenderer

type JavaScriptRenderer struct{}

JavaScriptRenderer handles rendering of JavaScript content from a file, inline multiline, or link.

func (*JavaScriptRenderer) Render

func (jsr *JavaScriptRenderer) Render(instance interface{}) (string, []error)

Render reads the JavaScript content and outputs it wrapped in <script> tags with appropriate attributes.

func (*JavaScriptRenderer) Types

func (r *JavaScriptRenderer) Types() []string

type LocalJSONConfig

type LocalJSONConfig struct {
	shared.Component `mapstructure:",squash"`
	FilePath         string `mapstructure:"file" validate:"required" description:"Path to the local JSON file" example:"{!{json-file.hyperbricks}}"`
	Template         string `` /* 128-byte string literal not displayed */
}

LocalJSONConfig represents configuration for fetching and rendering data from a local JSON file.

func (*LocalJSONConfig) Validate

func (config *LocalJSONConfig) Validate() []error

Validate ensures the local JSON configuration is correct.

type LocalJSONRenderer

type LocalJSONRenderer struct {
	TemplateProvider func(templateName string) (string, bool) // Function to retrieve templates
}

LocalJSONRenderer handles rendering of data from a local JSON file.

func (*LocalJSONRenderer) Render

func (renderer *LocalJSONRenderer) Render(instance interface{}) (string, []error)

Render processes local JSON data and outputs it according to the specified template.

func (*LocalJSONRenderer) Types

func (r *LocalJSONRenderer) Types() []string
type MenuConfig struct {
	shared.Component     `mapstructure:",squash"`
	Section              string `` /* 132-byte string literal not displayed */
	Order                string `` /* 148-byte string literal not displayed */
	Sort                 string `` /* 169-byte string literal not displayed */
	Active               string `` /* 129-byte string literal not displayed */
	Item                 string `mapstructure:"item" validate:"required" description:"Template for regular menu items." example:"{!{menu-item.hyperbricks}}"`
	Enclose              string `mapstructure:"enclose" description:"Template to wrap the menu items." example:"{!{menu-wrap.hyperbricks}}"`
	HyperMediasBySection map[string][]composite.HyperMediaConfig
}

MenuConfig represents configuration for the MENU component.

func (mc *MenuConfig) Validate() []error

Validate ensures the configuration is valid for rendering the MENU.

type MenuRenderer struct {
	TemplateProvider     func(templateName string) (string, bool) // Function to retrieve templates
	HyperMediasBySection map[string][]composite.HyperMediaConfig
	CurrentRoute         string // Added to track the current page's route
}

MenuRenderer handles rendering of MENU components.

func (mr *MenuRenderer) Render(instance interface{}) (string, []error)

Render generates the MENU output based on the configuration and context.

func (r *MenuRenderer) Types() []string

type MultipleImagesConfig

type MultipleImagesConfig struct {
	shared.Component `mapstructure:",squash"`
	Directory        string `` /* 143-byte string literal not displayed */
	Width            int    `` /* 147-byte string literal not displayed */
	Height           int    `` /* 150-byte string literal not displayed */
	IsStatic         bool   `mapstructure:"is_static" description:"Flag indicating if the images are static" example:"{!{images-is_static.hyperbricks}}"`
}

MultipleImagesConfig represents configuration for multiple images.

func (*MultipleImagesConfig) Validate

func (config *MultipleImagesConfig) Validate() []error

Validate ensures that the configuration is valid and complete

type MultipleImagesRenderer

type MultipleImagesRenderer struct {
	ImageProcessorInstance *ImageProcessor
}

MultipleImagesRenderer handles rendering for multiple images

func (*MultipleImagesRenderer) Render

func (mir *MultipleImagesRenderer) Render(instance interface{}) (string, []error)

Render processes the multiple images configuration and generates the output

func (*MultipleImagesRenderer) Types

func (r *MultipleImagesRenderer) Types() []string

type PluginConfig

type PluginConfig struct {
	shared.Component `mapstructure:",squash"`
	PluginName       string                 `mapstructure:"plugin"`
	Classes          []string               `mapstructure:"classes" description:"Optional CSS classes for the link" example:"{!{link-classes.hyperbricks}}"`
	Data             map[string]interface{} `mapstructure:"data"`
}

Basic config for ComponentRenderers

type PluginRenderer

type PluginRenderer struct {
	renderer.CompositeRenderer
}

Define a specific implementation of a RenderComponent

func (*PluginRenderer) LoadAndRender

func (r *PluginRenderer) LoadAndRender(instance interface{}) (string, []error)

Implement the Render method PluginRenderer

func (*PluginRenderer) Render

func (r *PluginRenderer) Render(instance interface{}) (string, []error)

func (*PluginRenderer) Types

func (r *PluginRenderer) Types() []string

type RenderImageConfig

type RenderImageConfig struct {
	Single   *SingleImageConfig    `mapstructure:"single"`
	Multiple *MultipleImagesConfig `mapstructure:"multiple"`
}

RenderImageConfig represents the configuration for rendering a single or multiple images

type SingleImageConfig

type SingleImageConfig struct {
	shared.Component `mapstructure:",squash"`
	Src              string `mapstructure:"src" validate:"required" description:"The source URL of the image" example:"{!{image-src.hyperbricks}}"`
	Width            int    `` /* 145-byte string literal not displayed */
	Height           int    `` /* 148-byte string literal not displayed */
	Alt              string `mapstructure:"alt" description:"Alternative text for the image" example:"{!{image-alt.hyperbricks}}"`
	Title            string `mapstructure:"title" description:"The title attribute of the image" example:"{!{image-title.hyperbricks}}"`
	Class            string `mapstructure:"class" description:"CSS class for styling the image" example:"{!{image-class.hyperbricks}}"`
	Quality          int    `mapstructure:"quality" description:"Image quality for optimization" example:"{!{image-quality.hyperbricks}}"`
	Loading          string `mapstructure:"loading" description:"Lazy loading strategy (e.g., 'lazy', 'eager')" example:"{!{image-loading.hyperbricks}}"`
	IsStatic         bool   `mapstructure:"is_static" description:"Flag indicating if the image is static" example:"{!{image-is_static.hyperbricks}}"`
}

SingleImageConfig represents configuration for a single image.

func (*SingleImageConfig) Validate

func (config *SingleImageConfig) Validate() []error

Validate ensures that the configuration is valid and complete

type SingleImageRenderer

type SingleImageRenderer struct {
	ImageProcessorInstance *ImageProcessor
}

SingleImageRenderer handles rendering for single images

func (*SingleImageRenderer) Render

func (sir *SingleImageRenderer) Render(instance interface{}) (string, []error)

Render processes the single image configuration and generates the output

func (*SingleImageRenderer) Types

func (r *SingleImageRenderer) Types() []string

type SortOptions

type SortOptions struct {
	SortBy    string // "title", "route", or "index"
	Ascending bool   // true for ascending order, false for descending
}

SortOptions defines the options for sorting pages.

type StyleConfig

type StyleConfig struct {
	shared.Component `mapstructure:",squash"`
	File             string `mapstructure:"file" validate:"required" description:"Path to the CSS file" example:"{!{styles-file.hyperbricks}}"`
}

StyleConfig represents the configuration for the style renderer.

func (*StyleConfig) Validate

func (style *StyleConfig) Validate() []error

Validate ensures the CSS file exists and is readable.

type StyleRenderer

type StyleRenderer struct{}

StyleRenderer handles rendering of CSS content from a file.

func (*StyleRenderer) Render

func (sr *StyleRenderer) Render(instance interface{}) (string, []error)

Render reads the CSS file content and outputs it wrapped in <style> tags with extra attributes.

func (*StyleRenderer) Types

func (r *StyleRenderer) Types() []string

type TextConfig

type TextConfig struct {
	shared.Component `mapstructure:",squash"`
	Value            string `mapstructure:"value" validate:"required" description:"The paragraph content" example:"{!{text-value.hyperbricks}}"`
}

TextConfig represents configuration for paragraph text.

func (*TextConfig) Validate

func (tc *TextConfig) Validate() []error

Validate ensures that the paragraph content is not empty.

type TextRenderer

type TextRenderer struct{}

TextRenderer handles rendering of paragraph text content.

func (*TextRenderer) Render

func (tr *TextRenderer) Render(instance interface{}) (string, []error)

Render processes paragraph text and outputs it, applying wrapping if specified.

func (*TextRenderer) Types

func (r *TextRenderer) Types() []string

Jump to

Keyboard shortcuts

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