I am porting an legacy web project that used Compass for SCSS compilation to build with node-sass since Compass requires Ruby and seems to be about three years dead.
One of the SCSS files contains calls to the 'image-width' function supported by Compass:
padding-left: $message-box-icon-padding * 2 + image-width('messages/loading.gif');
width: image-width('messages/loading.gif');
height: image-width('messages/loading.gif');
Fortunately there are only three and it seems the third should have been image-height.
What should replace these calls to image-width?
sprite-magic-importer replaces most of the features of COMPASS.
Related
I have a variable file in scss and import it with Symfony encore for my scss and sass files (see the code below).
// enables Sass/SCSS support
Encore.enableSassLoader((options) => {
options.implementation = require('sass')
options.additionalData = `#import "#/scss/variables.scss"`
});
The problem is there are sass (node-module(s)) and scss (template) files in my project which needs them.
If I run it like the snippet above it went fine for the sass files, but the scss files give an error: 'SassError: expected ";" after the #import line in the additionalData'.
However if I add the ; after the import line I get an error from the sass files 'SassError: semicolons aren't allowed in the indented syntax.'.
It's probably a small issue which I miss but I have no clue at the moment. I tried it with the added parameter indentedSyntax with true and false in the sassOptions but this was no success.
Anyone have an idea?
With kind regards
Just plugged in gulp-sass into an existing project, and I'm getting an error when I try to write an RGB syntax as follows:
rgb(70 168 255 / 0.05)
The log:
[17:51:58] Starting 'compileCSS'...
Error in plugin "sass"
Message:
src/xxx.css
Error: Function rgb is missing argument $green.
on line 77 of src/xxx.css
>> background-color: rgb(70 168 255 / 0.05);
This is a valid CSS sytnax (which my chrome apparently decided it should be my default syntax). Am I forced to replace all of the occurrences with commas?
Use sass instead of node-sass.
% npm uninstall node-sass
% npm install sass
Update:
dart-sass has been deprecated in favor of sass
According to sass, node-sass doesn't support color level 4. Therefore, I used the dart-sass compiler instead.
This question already has answers here:
Is Sass 3.3 compatible with Compass?
(3 answers)
Closed 7 years ago.
I have a SASS file _button-map-mixin.css that starts with the following associative array:
$cache: (
color: (),
font-size: (),
line-height: (),
background-color: (),
font-family: ()
);
When I compile the file, I get the following error:
Invalid CSS after " color": expected ")", was ": (),"
I don't understand - isn't this valid syntax?
It almost seems like the compiler doesn't recognize an associative array - but I'm using SASS version 3.3.6 (and Compass 0.12.6).
Use sass 3.3.7 and compass 1.0 (it's in alpha gem install compass --pre) If you got wdm related error then also install wdm(require "Ruby Development Kit") gem. If you keep your gem list clean it will be easier to catch dependency errors. Run gem list --local and uninstall all previous versions of compass and sass if you don't need them.
Is possible decode a JSON file with Node-Sass?
Ex:
#import "../data/data.json";
I need iterate this data directly into a variable
Any help is welcome :)
sass-json-vars is an excellent gem, but won't work with node-sass (which is a requirement of the original question).
Instead, try node-sass-json-importer, which is essentially the same thing, only re-worked to fit into node-sass's importer api.
There's a gem called Sass JSON Vars that does exactly what you want.
You can install the gem with the following command line code:
gem install sass-json-vars
HOW TO USE Sass JSON Vars
For projects using Sass >= 3.3
Place variables in a JSON file:
// variables.json
{
"font-sans": "Helvetica, sans-serif",
"colors": {
"red": "#c33"
}
}
Import the file in Sass to expose variable names:
#import "variables.json"
body {
color: map-get($colors, red);
font: $font-sans;
}
Require sass-json-vars when compiling:
sass style.scss -r sass-json-vars
For projects using Sass <= 3.2
Place variables in a JSON file:
// variables.json
{
"font-sans": "Helvetica, sans-serif",
"colors-red": "#c33"
}
Import the file in Sass to expose variable names:
#import "variables.json"
body {
color: $colors-red;
font: $font-sans;
}
Require sass-json-vars when compiling:
sass style.scss -r sass-json-vars
More info :
The project's Github page
Sharing Data Between Sass and JavaScript with JSON
I'm not quite sure how you would do it but here is a great example on how to add custom ruby functions to sass:
https://gist.github.com/chriseppstein/1561650
And heres one on how to parse json:
Parsing a JSON string in Ruby
Maybe after putting them together you could do something like this?
module Sass::Script::Functions
def json(Sass::Script::String)
require 'rubygems'
require 'json'
JSON.parse(string)
end
end
Add it to the end of your config.rb file, and make sure you have json ruby gem installed:
gem install json
and run:
compass compile --force
to get it all to work.
* this is obviously untested and doesn't work, but it might help you get where you need to go.
Is it possible to automatically add a timestamp on the compiled CSS file using SASS?
e.g.
/* CSS Compiled on: {date+time} */
...compiled css goes here...
I've checked the SASS and Compass docs but no mention of such a feature.
I don't know of any built-in SASS or Compass feature for this, but it's not too hard to add a custom Ruby function to do it. (See the section entitled "Adding Custom Functions" in the SASS reference here.)
Your file with the Ruby function would look like this (let's call it "timestamp.rb"):
module Sass::Script::Functions
def timestamp()
return Sass::Script::String.new(Time.now.to_s)
end
end
And you'd reference the new timestamp function in your SASS file like this:
/*!
* CSS Compiled on: #{timestamp()}
*/
You just need to make sure your "timestamp.rb" file is loaded when you compile the SASS, either by requiring it from a Compass config file, or by using the --require parameter with the SASS command line. When all is said and done, you should get output like the following:
/*
* CSS Compiled on: 2012-10-23 08:53:03 -0400
*/
If you are using the command line version of SCSS you can do the following:
Install sass-timestamp
gem install sass-timestamp
Use it within your code like (see documentation for more information)
/* Compiled on #{timestamp()} */
Require it on the command line
scss -r sass-timestamp ...
Output will be
/* Compiled on 2015-02-02 13:01:40 +0800 */
Note: Use #{unix_timestamp()} for a unix timestamp
I don't know if everyone needs it (cause the question is a long time answered ago),
but a simple solution is to write the timestamp/date
to a single sass/scss file as SASS variable,
import them to the location where the timestamp should be
and then let a comment in sass write them out.
Nothing to install, compile or anything else - just using scripts and sass:
1.) Write the timestamp to a separate sass file: (Here a dos-script, but you can also use any other script/language to generate the simple file):
echo $BuildTimeStamp : "%date% %time%"> _timestamp.scss
2.) Import the generated file with the timestamp:
#import '_timestamp.scss';
3.) Write the header out as comment:
/*! Automatic build at: #{$BuildTimeStamp} */
Write the timestamp before you call the original sass command
and it will also work without the need to install, build or do anything else.