pongo2components

package module
v0.0.0-...-6636911 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 4 Imported by: 0

README

pongo2-components

Adds web components to the existing pongo2 template engine.
Now you can make components similar to how you would in popular JS frameworks.

How to install and initialize

Install via go get -u github.com/leandergangso/pongo2-components

Import and initialize the package as seen bellow.

package main

import (
    "github.com/flosch/pongo2"
    "github.com/leandergangso/pongo2-components"
)

func init() {
    err := pongo2components.Init() 
    if err != nil {
        panic(err)
    }
}

func main() {
    // ...
}

Note: you should init pongo2components before any calls to pongo2.

How to use (basic example)

A basic button component.

  1. Registering and setup button component.
// components/button.go
package components

import (
    "github.com/leandergangso/pongo2-components"
)

func init() {
    button := pongo2components.Component{
        Name:     "button",
        FilePath: "components/button.html",
        Props:    []pongo2components.Prop{"value", "type"}
    }
    pongo2components.Register(button)
}
  1. Create html component with available props.
<!-- components/button.html -->
<button class="{{type}}">{{value}}</button>
  1. Use button component.
<!-- views/login.html -->
{% component 'button' value="Login" type="primary" %}

See /example directory for more examples.

Documentation

Index

Constants

View Source
const (
	SlotBefore  = "slotBefore"
	SlotDefault = "slotDefault"
	SlotAfter   = "slotAfter"
)

Helper for commonly used slot names.

Variables

This section is empty.

Functions

func Init

func Init(dirPath string)

func Register

func Register(c Component)

Types

type Component

type Component struct {
	Name  string
	Props []Prop
	Slots []Slot
}

type Prop

type Prop struct {
	Name         string
	DefaultValue string
	Required     bool
}

type Slot

type Slot struct {
	Name string

	// Only one slot can have default as true.
	Default bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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