2
votes

I'm writing my own static site generator in ruby and I'm in the process of adding Sass compiler to my code.

def compile_sass
  # system 'sass _sass/styles.scss styles.css'
  options = {
    syntax: :scss,
    style: :compressed
  }
  render = Sass::Engine.new(File.read('_sass/styles.scss'), options).render
  File.write('style.css', render)
end

But problem occurs when the styles.scss file has @import in it. Causing

(sass):1: File to import not found or unreadable: variables. (Sass::SyntaxError)

Both SCSS files are located in _sass folder, main script in root, and compile_sass is located in _generator. But when I uncomment the system call and comment the rest, everything works as expected.

styles.scss

@import 'variables';

html {
  background-color: red;
}

_variables.scss

body {
  background-color: blue;
}

I tried almost everything, checked how to import stuff, looked at the documentation, but I can't find anything that would helped me find and define the problem.

1
Why do you expect @import to prepend underscore to the imported file name? - Aleksei Matiushkin
@mudasobwa You don't need underscore to import the stylesheet.. - Mr. Alien
@mudasobwa their documentation says I should put it in there (but it doesn't work with or without the underscore). - rojcyk
maybe the working directory is changed at runtime ,try giving a absolute path to @import - max pleaner
@maxpleaner I tried all the possible variations with or without .scss, with or without underscore with no success - rojcyk

1 Answers

1
votes

Turns out I had to load all _sass/*.scss files into Sass::Engine like this:

Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
  load_paths << '_sass'
end