Pass erb from partials into sass (file)?

I think rails has a :custom option to pass erb into sass files. Anything like this in middleman?

What are you trying to do? Needing ERB inside Sass sounds like something’s not right…

If you add .erb to the extensions for the file you can process it as Ruby before you process it as Sass.

That will let you execute ERB, yes. But he wants to receive variables while inside Sass, which seems like a code smell. Why would Sass need access to data?

I was exploring ways of building a templating tool, that would generate appropriate html, sass, and js files for a website built on MM4 depending on a user’s options (which would need to be stored as data). I realized recently that .erb can be added to many different file types thanks to Middleman’s built in templating language.

What I’m trying to figure out now is the order in which files get resolved. For example, if my sass files are templated with .erb but also dependent on each other via sass’ @import, can I know if the templated erb gets resolved before the sass compiler runs?

I believe that the extension are resolved from right to left.

I was exploring ways of building a templating tool, a templating tool, that would generate appropriate html, sass, and js files for a website

Then, it still sounds like that Middleman is not the right tool for the job. If you’re generating websites, you would be generating different Middleman websites.

I’ve had to do something similar for a (non-middleman) project. I recommend giving Thor Generators a look.

This is possible, with the caveat that the stylesheet being processed by ERB can’t be imported by another SASS file. I use this in two places:

  1. Using variables from my data folder to fill URLs, in this case a bunch of fonts that are stored externally on another CDN
  2. For inline data-uri images where I want to use a helper to read and encode the image data.

I include these stylesheets consecutively in my layout, and rely on Netlify to concatenate them. I would love it if this were supported natively, eg:

_partial.scss.erb:
    .partial { property: <%= value %>; }

site.css.scss:
    import "partial";

I disagree that this is a code smell. I’ve been on a two-year Node/JavaScript bender after deciding that Middleman was too slow and didn’t have enough available image/css/js packages in the ecosystem, and I’ve come crawling back after making mess after mess in my JS projects, with each ending up as a random collection of ad-hoc build files.

Nested template processing is what makes Middleman so flexible, and the benefit of build process being stated declaratively in the source filename extensions should not be underestimated.