Skip to content

patrickkdev/templ-sass-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

templ-sass-processor

I built this while working on a web app where I was using Nested CSS inside <style> tags. It worked fine at first, but I later realized it only works in modern browsers and completely breaks on older ones.

I didn’t want to rewrite all the css by hand so instead, I discovered I could flatten the CSS by running it through something like the Sass CLI. The problem is that the CSS lives inside .templ files, so you can’t just pipe the whole file through Sass.

I ended up putting together this small utility that:

  • Recursively discovers .templ files.
  • Extracts <style> blocks and processes them with the sass CLI.
  • Replaces the processed parts while preserving surrounding markup unchanged.

Why use it

  • Flatten nested CSS inside your Templ components while preserving surrounding markup unchanged.

Requirements

  • sass CLI must be installed and available on PATH.

Install

go install github.com/patrickkdev/templ-sass-processor@latest

CLI examples

Basic: scan the current directory and replace <style> blocks with processed output in-place:

templ-sass-processor .

Example — before & after

Input (component.templ)

...
<div class="card">
  <h3 class="title">Title</h3>
</div>

<style>
.card {
  padding: 1rem;
  background: white;
  .title {
    font-weight: 700;
    &:hover { color: #555; }
  }
}
</style>
...

Output (inline replacement)

...
<div class="card">
  <h3 class="title">Title</h3>
</div>

<style>
.card { padding: 1rem; background: white; }
.card .title { font-weight: 700; }
.card .title:hover { color: #555; }
</style>
...

PRs and issues welcome.

About

A Go tool that recursively finds .templ files in your project, and processes CSS code inside <style> blocks using Sass CLI. It replaces the processed parts while keeping the rest of the code unchanged.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages