refactor: reorganize pkl files for better separation of concerns

This commit is contained in:
Prad Nukala 2024-10-03 01:01:49 -04:00
parent 931ac2308d
commit f75ff0d3be
27 changed files with 415 additions and 180 deletions

View File

@ -37,7 +37,7 @@ jobs:
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2-bucket: pkljar r2-bucket: pkljar
source-dir: pkl source-dir: deploy/config
destination-dir: . destination-dir: .
upload_nebula_cdn: upload_nebula_cdn:

View File

@ -55,7 +55,7 @@ release:
github: github:
owner: onsonr owner: onsonr
name: sonr name: sonr
name_template: '{{.Now.Format "2006.01.02"}}' name_template: "Release {{.Version}}"
draft: false draft: false
replace_existing_draft: true replace_existing_draft: true
replace_existing_artifacts: true replace_existing_artifacts: true
@ -63,7 +63,6 @@ release:
- glob: ./CHANGELOG* - glob: ./CHANGELOG*
- glob: ./README* - glob: ./README*
- glob: ./LICENSE* - glob: ./LICENSE*
- glob: ./pkl/*
brews: brews:
- name: sonr - name: sonr

View File

@ -307,7 +307,6 @@ motr:
templ: templ:
@echo "(templ) Generating templ files" @echo "(templ) Generating templ files"
go install github.com/a-h/templ/cmd/templ@latest
templ generate templ generate
nebula: nebula:
@ -316,10 +315,10 @@ nebula:
pkl: pkl:
@echo "(pkl) Building PKL" @echo "(pkl) Building PKL"
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/DWN.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./deploy/config/DWN.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/ORM.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./deploy/config/ORM.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/Txns.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./deploy/config/Txns.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./pkl/UIUX.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./deploy/config/UIUX.pkl
start-caddy: start-caddy:
@echo "(start-caddy) Starting caddy" @echo "(start-caddy) Starting caddy"

View File

@ -8,7 +8,18 @@ import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
// │ General State │ // │ General State │
// ╰───────────────────────────────────────────────────────────╯ // ╰───────────────────────────────────────────────────────────╯
typealias FormState = "initial" | "error" | "success" | "warning" typealias InputType = "text" | "password" | "email" | "credential" | "file"
class Button {
text: String
href: String
}
abstract class Form {
title: String
description: String
inputs: List<Input>
}
class Image { class Image {
src: String src: String
@ -16,6 +27,16 @@ class Image {
height: String height: String
} }
class Input {
label: String
type: InputType
placeholder: String
value: String?
error: String?
help: String?
required: Boolean?
}
class Link { class Link {
text: String text: String
href: String href: String
@ -26,25 +47,17 @@ class SocialLink {
icon: String icon: String
} }
class Button {
text: String
href: String
}
class Input {
label: String
type: String
placeholder: String
value: String?
error: String?
help: String?
required: Boolean
}
// ╭───────────────────────────────────────────────────────────╮ // ╭───────────────────────────────────────────────────────────╮
// │ Data Models │ // │ Data Models │
// ╰───────────────────────────────────────────────────────────╯ // ╰───────────────────────────────────────────────────────────╯
class Feature {
title: String
description: String
icon: String
image: Image
}
class Highlight { class Highlight {
title: String title: String
description: String description: String
@ -72,9 +85,9 @@ class Hero {
} }
class Highlights { class Highlights {
title: String heading: String
description: String subheading: String
image: Image highlights: Listing<Highlight>
} }
class Features { class Features {
@ -115,29 +128,13 @@ class Footer {
class Home { class Home {
hero: Hero hero: Hero
highlights: Listing<Highlight>
features: Listing<Features>
bento: Bento
lowlights: Listing<Lowlights>
callToAction: CallToAction
footer: Footer
} }
// ╭───────────────────────────────────────────────────────────╮
// │ Registration View Model │
// ╰───────────────────────────────────────────────────────────╯
class RegistrationForm {
title: String
description: String
state: FormState
inputs: List<Input>
}
// ╭───────────────────────────────────────────────────────────╮
// │ Login View Model │
// ╰───────────────────────────────────────────────────────────╯
// ╭───────────────────────────────────────────────────────────╮
// │ FINAL INPUTS │
// ╰───────────────────────────────────────────────────────────╯
// Pages
home : Home home : Home

View File

@ -6,6 +6,7 @@
"bun@latest", "bun@latest",
"ipfs@latest", "ipfs@latest",
"skate@latest", "skate@latest",
"templ@latest",
"cloudflared@latest", "cloudflared@latest",
"process-compose@latest" "process-compose@latest"
], ],

View File

@ -1,6 +1,9 @@
package home package home
import "github.com/onsonr/sonr/pkg/nebula/models" import (
"github.com/onsonr/sonr/pkg/nebula/components/ui"
"github.com/onsonr/sonr/pkg/nebula/models"
)
templ SectionHero(hero *models.Hero) { templ SectionHero(hero *models.Hero) {
<!-- Hero --> <!-- Hero -->
@ -24,12 +27,8 @@ templ SectionHero(hero *models.Hero) {
{ hero.Subtitle } { hero.Subtitle }
</p> </p>
<div class="max-w-xs mx-auto sm:max-w-none sm:inline-flex sm:justify-center space-y-4 sm:space-y-0 sm:space-x-4"> <div class="max-w-xs mx-auto sm:max-w-none sm:inline-flex sm:justify-center space-y-4 sm:space-y-0 sm:space-x-4">
<div> @ui.PrimaryButton(hero.PrimaryButton.Href, hero.PrimaryButton.Text)
<div class="btn cursor-pointer text-zinc-100 bg-zinc-900 hover:bg-zinc-800 w-full shadow" hx-swap="afterend" hx-get={ hero.PrimaryButton.Href }>{ hero.PrimaryButton.Text }</div> @ui.SecondaryButton(hero.SecondaryButton.Href, hero.SecondaryButton.Text)
</div>
<div>
<div class="btn cursor-pointer text-zinc-600 bg-white hover:text-zinc-900 w-full shadow" hx-swap="afterend" hx-get={ hero.SecondaryButton.Href }>{ hero.SecondaryButton.Text }</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,22 +1,10 @@
package register package register
import ( import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/blocks" "github.com/onsonr/sonr/pkg/nebula/components/blocks"
"github.com/onsonr/sonr/pkg/nebula/models/formstate" "github.com/onsonr/sonr/pkg/nebula/models/formstate"
) )
templ View(c echo.Context) {
@blocks.Layout("Sonr.ID", true) {
@blocks.Card("register-view", blocks.SizeMedium) {
@blocks.Spacer()
@blocks.Breadcrumbs()
@basicInfoForm(formstate.Initial)
@blocks.Spacer()
}
}
}
templ basicInfoForm(state formstate.FormState) { templ basicInfoForm(state formstate.FormState) {
switch (state) { switch (state) {
default: default:

View File

@ -0,0 +1,13 @@
package ui
templ PrimaryButton(href string, text string) {
<div>
<div class="btn cursor-pointer text-zinc-100 bg-zinc-900 hover:bg-zinc-800 w-full shadow" hx-swap="afterend" hx-get={ href }>{ text }</div>
</div>
}
templ SecondaryButton(href string, text string) {
<div>
<div class="btn cursor-pointer text-zinc-600 bg-white hover:text-zinc-900 w-full shadow" hx-swap="afterend" hx-get={ href }>{ text }</div>
</div>
}

View File

@ -0,0 +1,12 @@
// Code generated from Pkl module `models`. DO NOT EDIT.
package models
type Feature struct {
Title string `pkl:"title"`
Description string `pkl:"description"`
Icon string `pkl:"icon"`
Image *Image `pkl:"image"`
}

View File

@ -0,0 +1,10 @@
// Code generated from Pkl module `models`. DO NOT EDIT.
package models
type Form interface {
GetTitle() string
GetDescription() string
GetInputs() []*Input
}

View File

@ -2,9 +2,9 @@
package models package models
type Highlights struct { type Highlights struct {
Title string `pkl:"title"` Heading string `pkl:"heading"`
Description string `pkl:"description"` Subheading string `pkl:"subheading"`
Image *Image `pkl:"image"` Highlights []*Highlight `pkl:"highlights"`
} }

View File

@ -3,4 +3,16 @@ package models
type Home struct { type Home struct {
Hero *Hero `pkl:"hero"` Hero *Hero `pkl:"hero"`
Highlights []*Highlight `pkl:"highlights"`
Features []*Features `pkl:"features"`
Bento *Bento `pkl:"bento"`
Lowlights []*Lowlights `pkl:"lowlights"`
CallToAction *CallToAction `pkl:"callToAction"`
Footer *Footer `pkl:"footer"`
} }

View File

@ -1,10 +1,12 @@
// Code generated from Pkl module `models`. DO NOT EDIT. // Code generated from Pkl module `models`. DO NOT EDIT.
package models package models
import "github.com/onsonr/sonr/pkg/nebula/models/inputtype"
type Input struct { type Input struct {
Label string `pkl:"label"` Label string `pkl:"label"`
Type string `pkl:"type"` Type inputtype.InputType `pkl:"type"`
Placeholder string `pkl:"placeholder"` Placeholder string `pkl:"placeholder"`
@ -14,5 +16,5 @@ type Input struct {
Help *string `pkl:"help"` Help *string `pkl:"help"`
Required bool `pkl:"required"` Required *bool `pkl:"required"`
} }

View File

@ -0,0 +1,28 @@
// Code generated from Pkl module `models`. DO NOT EDIT.
package models
type RegisterFormData interface {
Form
}
var _ RegisterFormData = (*RegisterFormDataImpl)(nil)
type RegisterFormDataImpl struct {
Title string `pkl:"title"`
Description string `pkl:"description"`
Inputs []*Input `pkl:"inputs"`
}
func (rcv *RegisterFormDataImpl) GetTitle() string {
return rcv.Title
}
func (rcv *RegisterFormDataImpl) GetDescription() string {
return rcv.Description
}
func (rcv *RegisterFormDataImpl) GetInputs() []*Input {
return rcv.Inputs
}

View File

@ -1,40 +0,0 @@
// Code generated from Pkl module `models`. DO NOT EDIT.
package formstate
import (
"encoding"
"fmt"
)
type FormState string
const (
Initial FormState = "initial"
Error FormState = "error"
Success FormState = "success"
Warning FormState = "warning"
)
// String returns the string representation of FormState
func (rcv FormState) String() string {
return string(rcv)
}
var _ encoding.BinaryUnmarshaler = new(FormState)
// UnmarshalBinary implements encoding.BinaryUnmarshaler for FormState.
func (rcv *FormState) UnmarshalBinary(data []byte) error {
switch str := string(data); str {
case "initial":
*rcv = Initial
case "error":
*rcv = Error
case "success":
*rcv = Success
case "warning":
*rcv = Warning
default:
return fmt.Errorf(`illegal: "%s" is not a valid FormState`, str)
}
return nil
}

View File

@ -10,15 +10,15 @@ func init() {
pkl.RegisterMapping("models#Button", Button{}) pkl.RegisterMapping("models#Button", Button{})
pkl.RegisterMapping("models#Image", Image{}) pkl.RegisterMapping("models#Image", Image{})
pkl.RegisterMapping("models#Stat", Stat{}) pkl.RegisterMapping("models#Stat", Stat{})
pkl.RegisterMapping("models#Link", Link{})
pkl.RegisterMapping("models#SocialLink", SocialLink{})
pkl.RegisterMapping("models#Input", Input{})
pkl.RegisterMapping("models#Highlight", Highlight{}) pkl.RegisterMapping("models#Highlight", Highlight{})
pkl.RegisterMapping("models#Highlights", Highlights{})
pkl.RegisterMapping("models#Features", Features{}) pkl.RegisterMapping("models#Features", Features{})
pkl.RegisterMapping("models#Bento", Bento{}) pkl.RegisterMapping("models#Bento", Bento{})
pkl.RegisterMapping("models#Lowlights", Lowlights{}) pkl.RegisterMapping("models#Lowlights", Lowlights{})
pkl.RegisterMapping("models#CallToAction", CallToAction{}) pkl.RegisterMapping("models#CallToAction", CallToAction{})
pkl.RegisterMapping("models#Footer", Footer{}) pkl.RegisterMapping("models#Footer", Footer{})
pkl.RegisterMapping("models#RegistrationForm", RegistrationForm{}) pkl.RegisterMapping("models#SocialLink", SocialLink{})
pkl.RegisterMapping("models#Link", Link{})
pkl.RegisterMapping("models#Input", Input{})
pkl.RegisterMapping("models#Feature", Feature{})
pkl.RegisterMapping("models#Highlights", Highlights{})
} }

View File

@ -0,0 +1,43 @@
// Code generated from Pkl module `models`. DO NOT EDIT.
package inputtype
import (
"encoding"
"fmt"
)
type InputType string
const (
Text InputType = "text"
Password InputType = "password"
Email InputType = "email"
Credential InputType = "credential"
File InputType = "file"
)
// String returns the string representation of InputType
func (rcv InputType) String() string {
return string(rcv)
}
var _ encoding.BinaryUnmarshaler = new(InputType)
// UnmarshalBinary implements encoding.BinaryUnmarshaler for InputType.
func (rcv *InputType) UnmarshalBinary(data []byte) error {
switch str := string(data); str {
case "text":
*rcv = Text
case "password":
*rcv = Password
case "email":
*rcv = Email
case "credential":
*rcv = Credential
case "file":
*rcv = File
default:
return fmt.Errorf(`illegal: "%s" is not a valid InputType`, str)
}
return nil
}

View File

@ -1,6 +1,8 @@
amends "https://pkl.sh/uiux.pkl"; amends "https://pkl.sh/UIUX.pkl";
home = new Home { home = new Home {
// Hero
hero = new Hero { hero = new Hero {
titleFirst = "Simplified"; titleFirst = "Simplified";
titleEmphasis = "self-custody"; titleEmphasis = "self-custody";
@ -34,4 +36,198 @@ home = new Home {
} }
}; };
}; };
// Highlights
highlights {
new Highlight {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/highlight-1.svg";
width = "500";
height = "500";
};
};
new Highlight {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/highlight-2.svg";
width = "500";
height = "500";
};
};
};
// Features
features {
new Features {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/feature-1.svg";
width = "500";
height = "500";
};
};
new Features {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/feature-2.svg";
width = "500";
height = "500";
};
};
new Features {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/feature-3.svg";
width = "500";
height = "500";
};
};
};
// Bento
bento = new Bento {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
primaryButton = new Button {
text = "Get Started";
href = "/register";
};
secondaryButton = new Button {
text = "Learn More";
href = "/about";
};
};
// Lowlights
lowlights {
new Lowlights {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/lowlight-1.svg";
width = "500";
height = "500";
};
};
new Lowlights {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
image = new Image {
src = "https://cdn.sonr.id/img/lowlight-2.svg";
width = "500";
height = "500";
};
};
};
// Call to Action
callToAction = new CallToAction {
title = "Simplified";
description = "Sonr is a modern re-imagination of online user identity, empowering users to take ownership of their digital footprint and unlocking a new era of self-sovereignty.";
primaryButton = new Button {
text = "Get Started";
href = "/register";
};
secondaryButton = new Button {
text = "Learn More";
href = "/about";
};
};
// Footer
footer = new Footer {
logo = new Image {
src = "https://cdn.sonr.id/img/logo.svg";
width = "500";
height = "500";
};
mediumLink = new SocialLink {
link = new Link {
text = "Medium";
href = "https://medium.com/sonr-io";
};
icon = "https://cdn.sonr.id/img/medium.svg";
};
twitterLink = new SocialLink {
link = new Link {
text = "Twitter";
href = "https://twitter.com/sonr";
};
icon = "https://cdn.sonr.id/img/twitter.svg";
};
discordLink = new SocialLink {
link = new Link {
text = "Discord";
href = "https://discord.com/invite/sonr";
};
icon = "https://cdn.sonr.id/img/discord.svg";
};
githubLink = new SocialLink {
link = new Link {
text = "GitHub";
href = "https://github.com/sonr-io";
};
icon = "https://cdn.sonr.id/img/github.svg";
};
companyLinks {
new Link {
text = "About";
href = "https://sonr.io/about";
};
new Link {
text = "Careers";
href = "https://sonr.io/careers";
};
new Link {
text = "Partners";
href = "https://sonr.io/partners";
};
new Link {
text = "Investors";
href = "https://sonr.io/investors";
};
new Link {
text = "Newsroom";
href = "https://sonr.io/newsroom";
};
new Link {
text = "Blog";
href = "https://sonr.io/blog";
};
};
resourcesLinks {
new Link {
text = "Docs";
href = "https://docs.sonr.io";
};
new Link {
text = "Whitepaper";
href = "https://sonr.io/whitepaper";
};
new Link {
text = "FAQ";
href = "https://sonr.io/faq";
};
new Link {
text = "Terms of Service";
href = "https://sonr.io/terms";
};
new Link {
text = "Privacy Policy";
href = "https://sonr.io/privacy";
};
};
}
}; };

View File

@ -1,11 +0,0 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/grant"
)
func Authorize(c echo.Context) error {
return echoResponse(c, grant.View(c))
}

View File

@ -1,16 +0,0 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/home"
"github.com/onsonr/sonr/pkg/nebula/models"
)
func Home(c echo.Context) error {
mdls, err := models.GetModels()
if err != nil {
return err
}
return echoResponse(c, home.View(mdls.Home))
}

View File

@ -1,11 +0,0 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/login"
)
func Login(c echo.Context) error {
return echoResponse(c, login.Modal(c))
}

36
pkg/nebula/pages/pages.go Normal file
View File

@ -0,0 +1,36 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/grant"
"github.com/onsonr/sonr/pkg/nebula/components/home"
"github.com/onsonr/sonr/pkg/nebula/components/login"
"github.com/onsonr/sonr/pkg/nebula/components/profile"
"github.com/onsonr/sonr/pkg/nebula/components/register"
"github.com/onsonr/sonr/pkg/nebula/models"
)
func Authorize(c echo.Context) error {
return echoResponse(c, grant.View(c))
}
func Home(c echo.Context) error {
mdls, err := models.GetModels()
if err != nil {
return err
}
return echoResponse(c, home.View(mdls.Home))
}
func Login(c echo.Context) error {
return echoResponse(c, login.Modal(c))
}
func Profile(c echo.Context) error {
return echoResponse(c, profile.View(c))
}
func Register(c echo.Context) error {
return echoResponse(c, register.Modal(c))
}

View File

@ -1,11 +0,0 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/profile"
)
func Profile(c echo.Context) error {
return echoResponse(c, profile.View(c))
}

View File

@ -1,11 +0,0 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/register"
)
func Register(c echo.Context) error {
return echoResponse(c, register.Modal(c))
}