Skip to content

gavink97/tailwind-inline

Repository files navigation

Tailwind Inline

Mission

Tailwind Inline aims to create a cohesive development experience, whether you’re using templates to build a web application or an HTML email.

Why

Because most email clients block external and internal CSS, it’s essential to use inline style CSS when developing HTML email templates.

Getting Started

Installation

go get github.com/gavink97/tailwind-inline

Using Tailwind Inline with Templ

import(
    "os"
    "log"
    "context"

    "github.com/a-h/templ"
    twi "github.com/gavink97/tailwind-inline"
)

path := "./public/styles.css"
styles, err := os.ReadFile(path)
if err != nil {
    log.Fatal(err)
}

ctx := context.Background()
component := yourTemplComponent
s, err := templ.ToGoHTML(ctx, component)
if err != nil {
    log.Fatal(err)
}

c := twi.Convert(string(s), styles)

Using Tailwind Inline with html/template

import(
    "os"
    "io"
    "log"
    "bytes"
    "html/template"

    twi "github.com/gavink97/tailwind-inline"
)

path := "./public/styles.css"
styles, err := os.ReadFile(path)
if err != nil {
    log.Fatal(err)
}

var b bytes.Buffer
tpl := yourTemplate
t, err := template.New("Email").Parse(tpl)
if err != nil {
    log.Fatal()
}

data := struct {
          Title string
      }{
Title: "My email",
      }

buff := io.Writer(&b)
err = t.Execute(buff, data)

c := twi.Convert(b.String(), styles)

Contributing

I’m open to contributions

Star

If you’ve found this useful please give it a star ⭐️ as it helps other developers find my repos.

Star History Chart