pbj

package module
v0.0.0-...-9738b54 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 14 Imported by: 0

README

Pb&J Stack

The PB Stacks for PocketBase, and the J stands for just HTMX.

pbj-time

Simplicity > Dependencies

I wanted to make the simplest stack I could using the least number of dependencies, and writing the simplest code. This is a very hard balance to find as simplicity hides complexity.

Independently, I found both PocketBase and HTMX. Both solutions focus on what can be done simply and effectively. Once I looked at the documentation for PocketBase and saw that with Go I can render templates the path forward was clear.

Get Started

You should fork this repository for your next new project. Then run:

go mod tidy
go run main.go serve

And you're ready to go...

screen-capture - 2023-10-19T012556.063.webm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(fn func(*App)) func(*App)

Generic mount function for "routers"

func WithAdminOnlyAccess

func WithAdminOnlyAccess(admin bool) func(*Page)

WithAdminOnlyAccess configures the Page to only allow admin access

func WithInlineScript

func WithInlineScript(content string) func(*App)

WithInlineScript will include <script></script> tag

func WithMeta

func WithMeta(name, content string) func(*App)

WithMeta will include <meta name content> tag

func WithPublicAccess

func WithPublicAccess(public bool) func(*Page)

WithPublicAccess configures the Page to be public accessable

func WithScript

func WithScript(src string) func(*App)

WithScript will include <script src></script> tag

func WithStylesheet

func WithStylesheet(href string) func(*App)

WithStylesheet will include <link rel="stylesheet" href> tag

Types

type App

type App struct {
	*pocketbase.PocketBase
	// contains filtered or unexported fields
}

App data structure encapsolates PocketBase app

func NewApp

func NewApp(opts ...func(*App)) *App

NewApp creates a new app encapsolating PocketBase

func (*App) Event

func (a *App) Event(n string) string

Event formats event name for client and server side

func (*App) NewPage

func (app *App) NewPage(route string, opts ...func(*Page)) *Page

NewPage entry point for page API

func (*App) On

func (a *App) On(n string, fn func(Context) error)

On function to mount callbacks to App

func (*App) Start

func (app *App) Start() error

Start starts pocketbase app after registering migrations

type Context

type Context interface {
	Request() *http.Request
	Response() *echo.Response
	FormValue(string) string
	FormValues() (url.Values, error)
	PathParam(string) string
	QueryParam(string) string

	Admin() *models.Admin
	User() *models.Record
	Set(string, any)
	Props() map[string]any
	Refresh() error
	Push(url string) error
	Replace(url string) error
	Render(string) error
}

type GetProps

type GetProps func(Context) error

GetProps type for getting the props of a page when needed

type Page

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

Page data structure for passing configuration state to pages

func (*Page) Event

func (p *Page) Event(n string) string

Event formats event name for client and server side

func (*Page) On

func (p *Page) On(n string, fn func(Context) error)

On function to mount callbacks to PocketBase

func (*Page) Serve

func (p *Page) Serve(fn GetProps) *Page

Serve with Props retrieved before rendering

func (*Page) Static

func (p *Page) Static(tmpl string) *Page

Static serve page with only user and admin

Directories

Path Synopsis
cmd
demo command

Jump to

Keyboard shortcuts

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