NameError - uninitialized constant Sass::Engine: - ruby

I am getting NameError - uninitialized constant Sass::Engine: when I run my sinatra app with sass gem.
installed ruby version 2.3.1 with rbenv and also installed sinatra, sass gem.
require 'sinatra'
require 'slim'
require 'sass' # required sass
require 'sinatra/reloader' if development?
get '/styles.css' do
scss :styles #does not generate styles.css, styles.scss file is in /views folder
end
get '/' do
slim :home
end
get '/about' do
#title = "All About This Website"
slim :about
end
get '/contact' do
slim :contact #, :layout => :special
end
not_found do
slim :not_found
end
get '/fake_error' do
status 500
"There's nothing wrong, really :P"
end
Full error:
NameError - uninitialized constant Sass::Engine:
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt/sass.rb:13:in
prepare'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt/template.rb:92:in
initialize'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:862:in
new'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:862:in
block in compile_template'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:104:in
block in fetch'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:103:in
fetch'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.5/lib/tilt.rb:103:in
fetch'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:841:in
compile_template'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:822:in
render'
/home/tasqyn/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:687:in
scss' main.rb:7:in `block in '
What I am doing wrong?
and here is styles.scss:
$red: #903;
$black: #444;
$white: #fff;
$main-font: Helvetica, Arial, sans-serif;
body {
font-family: $main-font;
}
h1 {
color: $red;
font: 32px/1 $main-font;
}
header h1 {
font-size: 40px;
line-height: 80px;
background: transparent url(/images/logo.png) 0 0 no-repeat;
padding-left: 84px;
}
#mixin tabs ($background: blue, $color: yellow) {
ul {
list-style: none;
margin: 0;
padding: 0;
background: $background;
overflow: hidden;
}
li {
float: left;
}
a {
text-decoration: none;
display: block;
padding: 8px;
background: $background;
color: $color;
&:hover {
background: darken($background, 20%);
}
}
}
nav {
##include tabs($background: $black, $color: $white);
font-weight: bold;
}
p {
font: 13px/1.4 $main-font;
}

Perform below steps :
Add any of this gem into your gem file gem 'bootstrap-sass' or gem 'sass-rails'
Then install bundle using bundle OR bundle install command

Make sure you have in your gemfile:
gem 'sass'
gem 'sass-rails'
If not, add it. Don't forget to run bundle install.

If you are using the asset-pipeline with sinatra, then this might help. For those using rails this could help.
In my scenario, (running rails 3.2.22.2) on one machine my app worked.
On another machine I cloned the repo and ran into the uninitialized constant Sass::Engine error.
Moving gem sass-rails did not work for me
I moved gem 'sass-rails' out of the group :assets do block.
This did not work for me.
Solution for me:
rake assets:clean removes all compiled assets.
Next time you run rake rails s, your assets will be recompiled.
If not, you can run rake assets:precompile to compile all your assets.
Or if you are deploying via capistrano, the deploy.rb will run "deploy:assets:precompile" and compile assets for your production/staging machine.
The error seems to occur because sass is not being compiled in the asset pipeline correctly. (Would love to know why this occurs if anyone has the answer)

Related

SASS variables are not working in .scss file

I'm having trouble with sass variables. The browser is telling me i am using invalid property values and i can see the code editor is not picking up the variables i am using because it's not colorizing them.
I have uninstalled and reinstalled sass and gulp-sass but that didn't fix the problem and i'm out of ideas. I'm sure it's something really simple.
Key Facts
I am on windows 10
I installed sass using npm install sass
i installed gulp-sass using npm install gulp-sass
I am successfully compiling the .scss file into the .css file
i am currently trying to create the variables in an .scss file
This is my .scss file
$flx: flex;
$clm: column;
$mpage: 1 0 auto;
$space-between: sb;
$pg1: 100vh;
body {
display: flx;
min-height: 100vh;
flex-direction: clm;
}
main {
flex: mpage;
}
.item-wrap{
justify-content: sb;
}
In order for Sass to read your variables, when you call them you have to hang the $ character in front of them, as you did when you declared them.
Example:
$flx: flex;
$clm: column;
$mpage: 1 0 auto;
$space-between: sb;
$pg1: 100vh;
body {
display: $flx;
min-height: 100vh;
flex-direction: $clm;
}
main {
flex: $mpage;
}
.item-wrap{
justify-content: $sb;
}

Why am I getting "Expected digit" when trying to import a Sass variable from Material using Rollup and PostCSS?

I have the following code...
#use "#material/top-app-bar/_variables.import" as mdc;
.color{
background-color: lightblue;
height: mdc.$row-height;
}
But when I run I get...
Error: Expected digit.
src/components/header/index.style.scss 4:17 root stylesheet
I am guessing I am importing the Sass file incorrectly. I have tried...
#use "#material/top-app-bar/variables";
.color{
background-color: lightblue;
height: variables.$row-height;
}
#use "#material/top-app-bar/mdc-top-app-bar";
.color{
background-color: lightblue;
height: $mdc-top-app-bar-row-height;
}
Etc... but nothing I try is working. How do I import the variable using sass?
Update
I noticed this further up
[!] (plugin postcss) Error: Expected digit.
src/components/header/index.style.scss 9:29 root stylesheet
Could this be a Rollup plugin issue?
Update 2
Looks like part of the problem was installing the node-sass package. Now I get...
[!] (plugin postcss) Error: Invalid CSS after "...ight: variables": expected expression (e.g. 1px, bold), was ".$row-height;"
When I run the following...
#use "#material/top-app-bar/variables" as variables;
.color{
background-color: lightblue;
height: variables.$row-height;
}
I also tried the simpler
// ./_variables.scss
$row-height: 64px !default;
#use "./variables";
.color{
background-color: lightblue;
height: variables.$row-height;
}
And I still get the same thing.
I had a similar issue using the sass color module.
I had to add the following to my rollup.config.js
import sassPlugin from 'rollup-plugin-sass'
import sass from 'sass'
sassPlugin({
runtime: sass,
// Other properties omitted for brevity.
})

Valid SCSS not compiling with Codekit

I'm having trouble with codekit, the code below is correct and should work with sass 3.4.5 (selective steve) which is running with my codekit 2.1.6 - ive tested the code with sassMeister and have provided a link. Has anyone got an idea what is going on?
Codekit was setup as a compass project using the latest compass.
Codekit gives me:
Compass was unable to compile one or more files in the project:
error style.scss (Line 3 of _nav.scss: Invalid CSS after " &": expected "{", was "__list {"
"__list" may only be used at the beginning of a compound selector.)
identical style.css
http://sassmeister.com/gist/f07191a09789e354bae6
nav[role=navigation] {color: black;}
.nav {
&__list {
color: black;
&__item {
color: black;
}
}
&__link {
color: black;
&--active {
color: black;
}
}
}
should convert to
nav[role=navigation] {
color: black;
}
.nav__list {
color: black;
}
.nav__list__item {
color: black;
}
.nav__link {
color: black;
}
.nav__link--active {
color: black;
}
EDIT
if I go about in codekit its using SASS 3.4.5 and Compass 0.12.7 (which is the current) - ill try to installl a later version of compass
IF I RUN COMPASS WATCH ON THE DIRECTORY IT WORKS but Codekit doesnt..
EDIT
Codekit seems to be using an older version of Compass - even if I point it to my locally installed version.
EDIT
I believe that the version of compass codekit is using on my system is too old - 0.12.7 where it needs to run 1.0.1 - but I cant find out how to get it to switch
Codekit didnt seem to pick up the correct version of compass - no documentation, so I moved back to the terminal.

SASS breaks my selector

I'm having trouble with SASS. Locally I have this selector:
#featured-categories{
ul{
li{
width: 33.33%;
}
}
}
which works as expected. Deployed (and compressed) however this is compiling to:
#featured-categoriesulli{width: 33.33%;}
which of course is an invalid selector. The more straight more forward formulation:
#featured-categories ul li{
width: 33.33%;
}
behaves in the same way - i.e. compiles to something munged and broken.
The only way I can get this to compile is to add redundant rules between the elements of the selector:
#featured-categories{
margin: 0;
ul{
margin: 0;
li{
width: 33.33%;
}
}
}
This works, but is obviously not ideal.
Can anyone help? I'm in a ruby 1.9.3 project running sass 3.2.9. Any pointers would be greatly appreciated.
The SCSS that you've provided should work fine. Check it out with SassMeister or http://jsfiddle.net/Kjanu/. It will compile to this:
#featured-categories ul li { width: 33.33%; }
So you've got something else going wrong in your setup.

Less hangs Sinatra application

I am trying to add Bootstrap to a Sinatra application. I have setup routes to compile bootstrap.less and responsive.less. Loading the two stylesheets separately in a web browser works as expected. But when I try to use them in a html page my application hangs. I can only stop the application with kill -9.
It seems that somehow Less imports and multiple stylesheets cause a hang of the application. I was able to isolate the problem:
app.rb
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'less'
get '/' do
haml :index
end
get '/style1.css' do
less :style1, :paths => ['views']
end
get '/style2.css' do
less :style2, :paths => ['views']
end
views/index.haml
!!! 5
%html
%head
%title Hello World
%link{'rel' => 'stylesheet', 'href' => 'style1.css', 'type' => 'text/css'}
%link{'rel' => 'stylesheet', 'href' => 'style2.css', 'type' => 'text/css'}
%body
%h1 Hello World
%p Hello World
views/style1.less
#import "mixins.less";
#import "shadows.less";
#color: #00eeff;
h1 {
color: #color;
}
views/mixins.less
.box-shadow(#shadow) {
-webkit-box-shadow: #shadow;
-moz-box-shadow: #shadow;
box-shadow: #shadow;
}
views/shadows.less
h1 {
.box-shadow(6px 6px 3px #888);
}
views/style2.less
#color: #ccff00;
p {
color: #color;
}
Accessing the index page hangs Sinatra. If I comment out style2.less in the html page or inline shadows.less or mixins.less in style1.less the page loads as expected.
Any idea what could be the problem or how I can debug this further?
I took your files and made small changes to them:
I renamed style2.css to style2.less so i can use Less on it, and eventually download the style2.css with the correct css syntax ---It was not working with the other extension.
And, I told Less that the path to search for directives, was the views path of Sinatra: Less.paths << settings.views.
So, with these changes, the Sinatra application stopped hanging.

Resources