amnu3387

amnu3387

Hi,

As part of maybe starting a project for a CMS + static site generator I decided to create a library that allows similar CSS pre-processing as Sass/SCSS. It’s not yet finished but it already works for most part (it’s missing the ability to create ad-hoce functions) and similar in many aspects to Sass, with the exception that it allows using EEx code blocks and arbitrary Elixir terms as assigns (on top of normal string based “variables”).

It also has a basic watcher that pre-processes your CSSEx files automatically and it’s made in a way to accommodate the needs I imagined for the possible CMS+SSG (programatically pass variables & assigns while generating css, etc).

You can check it at GitHub repo
Along with some basic examples.

As it is still lacking what is described in the roadmap I haven’t put it on hex yet, nor done proper benchmarks with more than small toy sized sass/cssex files, but in those cases I did it was fairly faster.
If you give it a try or have suggestions, bug reports, or want to contribute open an issue on the repo!

If you would like to see it in Erlang help me solve the issue of the EEx blocks and how to pass assigns into them - having that solved would allow to write it almost as is in Erlang (I also have no idea if anyone writing erlang needs a css preprocessor to be honest…)

(forgot to put on the readme but it also supports of course the “&” nested notation of sass)

Showing Posts 1 to 10

derek-zhou

derek-zhou

Great idea. If you are introducing elixir grammar into CSS, I’d like to see something that is completely elixir; ie a full set of elixir macros and functions to write CSS in 100% elixir grammar, sort of like what ecto does for SQL.

The current landscape of various CSS techs is sad. The only thing that has momentum is tailwind, and it is incredibly slow to compile. Also the new version has the brilliant idea of changing whitespace-no-wrap to whitespace-nowrap for no apparent reason.

amnu3387

amnu3387 OP

Thanks :slight_smile:

What syntax/api are you thinking? And how would that work? IT would generate the files on compile?

I personally like how CSS works - just miss not having some basic constructs to generate repetitions with slight changes or not being able to do nested selectors (with sass’ &) that results in repeating a lot of declarations. I haven’t used tailwind that much, I can see it working but I think it adds a lot of class declarations to the html being generated (although some people swear by it and its maintainability), I’m just not sure it’s the best approach to CSS.

Sebb

Sebb

Great! I don’t want to put you to any bother, but could you please in the next step replace webpack and npm?

derek-zhou

derek-zhou

I haven’t think it through, but I think a elixir-ish DSL that compiles down to plain CSS is doable. I prefer it to be true elixir instead of some eex template so I can use the full power of elixir. If it can express 99% of the CSS constructs, the remaining 1% can be done in a escape hatch similar to an ecto fragment.

derek-zhou

derek-zhou

I actually wrote my own html DSL: html_writer

but for CSS if there are more people interested we could do something more advanced, think something like Ecto.

amnu3387

amnu3387 OP

Building CSS is really straightforward, parsing isn’t complex but it’s more complex than building it.

I’m just not sure about what would be the syntax and the benefits of having it written in Elixir (while in HTML I can clearly see why it can help).

Taking this example from Temple

    header do
      section class: "container" do
        nav role: "navigation" do
          ul do
            li do: a("Get Started", href: "https://hexdocs.pm/phoenix/overview.html")
          end
        end

        a href: "http://phoenixframework.org/", class: "phx-logo" do
          img src: Routes.static_path(@conn, "/images/phoenix.png"),
              alt: "Phoenix Framework Logo"
        end
      end
    end

CSS is already sort of structured and using the & for instance to style the header & section with a class “container”

@!bg_color white; // these need not be set in a file,  while usually you would
// write it in files, the parser itself can take these as values when started in the
// form of a map where each key is variable name, like %{bg_color: "white", text_color: ...}
@!text_color rgb(75,75,75);

header {
  background-colour: <$bg_color$>;
  color: <$text_color$>;
  width: 100%;
  section.container {
     width: 100%;
     display: flex;
     flex-flow: row no wrap;
     justify-content: space-between;
     //....
  }
}

Are you thinking of something like:

Stylesheet.new()
|> rule("header section.container", width: "100%",  other: "rules", ...)
|> media(type: :print, min: "565px", width: "95%")

?

Just trying to understand what it would look like.

amnu3387

amnu3387 OP

Someone’s working on an erlang to js implementation!

derek-zhou

derek-zhou

A different syntax only makes sense if it enables new and productive way to refactor the code. Sorry I don’t use CSS heavy enough to make any good suggestion.

olafura

olafura

Parsing CSS is really annoying because test suits assume that you want have the same experience as you do with browsers which is that you can throw a lot of crap at it and it still works :smiley:

But if you want to have a fairly standard compliant parser then I have one. It’s based of the CSS spec, it’s I believe only failing because I have to match test suits:
https://github.com/olafura/ex_css

It doesn’t not yet support the nesting tricks that postcss and sass use.

My intent was and is still to have something akin on styled components available for Elixir. It’s just sometimes hard to find time :smiley:

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews