CSS written in pure Go
github.com
github.com
table_ (tr_ (td_ (p_ "Hello, World!")))
More complex: table_ [rows_ "2"]
(tr_ (do td_ [class_ "top",colspan_ "2",style_ "color:red"]
(p_ "Hello, attributes!")
td_ "yay!"))
Source: https://hackage.haskell.org/package/lucidThat is essentially what Elm proposes and it works fine.
They even support a lot of properties that aren't in Gecko/WebKit/Blink, like the @page rules.
Even the historic browser vendors with lots of manpower struggle with implementing it and they don't even agree on the implementation details.
For example, let's say I use a third-party css library (materializecss, or similar) that provides a class `btn-warning` and `warning-text`, which sets say 10 fields (colors, elevation, etc) on the former and `text-transform` on the latter.
I just want to write one new class that inherits fields from both the existing classes.
I can't specify a new class `my-btn-warning` that inherits all the fields from `btn-warning` and `warning-text`.
I can't create a new class `my-btn-warning` that is composed of `btn-warning` and `warning-text`.
My only option (open to correction) is to copy-and-paste the existing `btn-warning` and `warning-text` fields into my new `my-btn-warning` class.
There's simply no reusability here.
If I want reusability, I need to go outside the spec i.e. have a build step. Not just any build step, but one that exactly matches the upstream library. Which is impossible if there are two upstream libraries, or if my existing build step is different.
This project looks nice but it combines all the disadvantages of writing CSS with all the disadvantages of a build step and adds the extra downside of not being compatible with anyone else's (including mine) build step.
To me, this is the worst of all worlds, with no redeeming advantage at all.
CSS cascades, embrace it rather than fighting it.
Have a .btn rule that styles all your buttons. Have a .warning one that makes it yellow. Then instead of `<button class="btn-warning">` use `<button class="btn warning">`.
Or just use Sass instead!
...
> Or just use Sass instead!
Maybe I was unclear: my gripe is that this functionality is such a necessary thing to have, that external non-spec third-party tools have to be used to get this functionality.
It is a shortcoming of CSS, because CSS is not providing this functionality that users want.
The fact that everyone is using a third party tool to get this functionality only reinforces my point: if everyone is doing it, then it's a shortcoming.
> Have a .btn rule that styles all your buttons. Have a .warning one that makes it yellow. Then instead of `<button class="btn-warning">` use `<button class="btn warning">`.
I do this, but it ends up being `class="<godawful number of named classes?"` and is prone to breakage when you need to update or modify a theme.
<button class="btn btn--warning">
Here double minus means that "warning" is a state of an element named "btn".I want to define a button that inherits from a library like tailwind (define button by using tailwind classes).
You can look at CSS Modules (not supported by browser) which has class inheritance.
(Not a parser, a renderer, a query engine, etc)
The nice thing about this is that you can get a tailwind Go lib to programmatically build into your binary. There are no extra files, one build step, and one binary output. After trying out Fly and Vercel, I went to running things with docker on a VM, and a single binary in a container makes things much simpler IMO.
This looks pretty cool and I look forward to seeing folks do interesting things with it.
Then for the actual build, everything is built and embedded in a single binary by conditionally using embed with build tags.
I think that live feedback development cycle is probably the most satisfying way to code something by oneself.
It did need quite a bit of messing around with tooling and my Makefiles are pretty big but at least I can reuse that in every new project.
And what about "embed with build tags."? I embed every build now.
Basically, templ will start a live reload server in "proxy mode". Other tools can then request a reload by notifying the proxy. I started with the makefile described in the docs. But I also have tailwind in watch mode, esbuild builds and more.
[0]: https://templ.guide/commands-and-tools/live-reload-with-othe...
So I would like to try something like this too. Integration with templ for local CSS components would be nice.
Also agree to the single binary, wrote here https://www.inkmi.com/blog/simplicity-of-golang-systemd-depl... (with systemd instead of a container)
https://dev.to/thormeier/dont-try-this-at-home-css-as-the-ba...
Anyways, good exercise for your experience. Have fun.
Why is why I absolutely love it.
It's the true hacker's spirit - about testing the frontiers of what's possible. Note what was said as well:
> This is really just a bit of fun and a way to write CSS in Go. I wanted to see if it was possible and it is with ease.
And I thought this was aspirational as well:
> CSS written in Pure Go. No JS builders, no preprocessors, no linters, no frameworks, no classes, no variables, no overrides, no plugins, no dependencies, no javascript, no templates, no bs, no nothing. Just Go.
Rust people are all about "let's rewrite it in Rust". I don't see why Gophers can't have their fun as well.
Indeed! When there's effort to make proofs or assertions about a program's behaviour before it is executed then good things happen!
Dev experience does look pretty good.
To be fair, i have been quite happy with templ's style support, which would not really be useable in a non-templ project.
The benefit of all this are
Keeps the css free of variables.
Keeps html free of classes like bg-gray-50 text-black dark:bg-slate-800 dark:text-white and eliminates the need to remember to add the dark variant.
I recently saw a button component on an html page 10 times with over 1800 characters in the class attribute of each!"
* efficiency (one less hash lookup, less bookkeeping for the browser)
* works on older browsers (or mine ;)
* you become a member of the exclusive club of devs that don't believe in turning CSS into a turing-complete language (old fashioned, I know)
In my head you went full bene gesserit and screamed "abomination" when you saw it.
Candidly I want to know where this thing was, you really need to name and shame.
To put it one way, you’ve phrased your compliment and thoughts in such a way that they only relate to you and don’t have any bearing on the reader.
https://news.ycombinator.com/item?id=40546415
I went after that harder.
Well, this would be possible in any language, I presume. Maybe it's easier in Go but is that the point?
> Just Go
So BS?
It seems like the point of this is to run during a compilation step with the added capability of rebuilding a CSS response on the fly, if you wanted.
Building a CSS during compile is no different than using something like Tailwind and is essentially free.
This shit is why basic webpages drain my battery and burn my lap.
The whole industry of React and similar giant frameworks is to offload functionality to the browser and make the server only a data source - you reduce the amount of data that has to go through tight pipes and speed up the responsiveness of the site for your users. Basic pages drain your battery for sure. There is a gradient of that and putting CSS in the front end is the wise minimal end of that gradient, while React is the opposite side of it, then add SQLite and you go even more client heavy. It depends on the tool you are building - some justify it, but many don’t.
<link rel="stylesheet" href="base.css" />
I often see such code and it seems that people simply don't know HTML and copy random garbage they found on the Internet. In the example above, the slash is simply ignored, but in this example the code will be parsed not as intended: <div/>
This is why you should read proper documentation or specification instead of blindly copying garbage code from Internet.MDN link: https://developer.mozilla.org/en-US/docs/Glossary/Void_eleme...
It is supported in HTML5.
https://html.spec.whatwg.org/multipage/syntax.html#start-tag...
> ... if the element is one of the void elements ... then there may be a single U+002F SOLIDUS character (/) (at the end of the element, before the closing bracket)
https://html.spec.whatwg.org/multipage/syntax.html#void-elem...
> Void elements: area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr
--
> This is why you should read proper documentation or specification instead of blindly copying garbage code from Internet.
Physician, heal thyself :)
<div/>
And it will be interpreted as <div>, not as a pair of <div></div>.HTML just ignores the slash character, it doesn't support XML-style self-closing tags. HTML is not XML.
Self-closing tags with the trailing slash are absolutely supported by HTML5, in some circumstances.
Quoting the spec [1]:
> Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/), which on foreign elements marks the start tag as self-closing. On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.