SASS: Invalid #import: expected end of line, was ";" - sometimes - sass

I've got a sass file that only contains import statements
#import "this";
#import "that";
if I run sass from the command line everything's good
bundle exec sass foo.scss:foo.css
If, however I run it from within a script (also via bundle exec) it gets upset about those semicolons. This...
template = File.read("foundation.scss")
sass_engine = Sass::Engine.new(template)
sass_output = sass_engine.render
...produces the following on the sass_engine.render call:
(sass):1: Invalid #import: expected end of line, was ";". (Sass::SyntaxError)
if i get rid of the semicolons then the situation is reversed. It complains on the command line and not in the script.
What's going on, and how do I get it to accept the semicolons when run from a script?

The difference is that the Sass command line program notices the "scss" extension and parses the file as SCSS instead of traditional Sass. When doing it programatically, you are starting a Sass engine and not telling it that it is SCSS instead.
So, the error is that its reading it as Sass instead of SCSS.
http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options
This should fix your problem right up!
template = File.read("foundation.scss")
sass_engine = Sass::Engine.new(template, :syntax => :scss)
sass_output = sass_engine.render
Viola!

Related

translate scss to css in ruby cmd for writing sass code

i have faced this problem
Errno::ENOENT: No such file or directory # rb_sysopen - D:\Tasks\Bootstrap
Use --trace for backtrace.
after i have write this command in ruby cmd:
sass D:\Tasks\Bootstrap 4\css\style.scss D:\Tasks\Bootstrap 4\compiledcss\style.css
You've got spaces in your path and the shell is breaking the arguments on spaces, so either eliminate those or quote each path:
sass "D:\Tasks\Bootstrap 4\css\style.scss" "D:\Tasks\Bootstrap 4\compiledcss\style.css"
Spaces in filenames are super annoying, so they're best avoided if you can.

Setting expanded output style in sass doesn´t work

I want to change output style in my sass file to expanded but setting :
sass --watch style.scss:style.css --style expanded
doesn´t work for me. Instead it return me this
Encoding::CompatibilityError: incompatible character encodings: CP852 and UTF-8
Use --trace for backtrace.
Is there any possible to fix it? I´m not quite sure about it too because I´m new in Sass.But when I tried first , things went well in my single line selector in compresed style .I did some changes in sass file, I have here now more selectors formated in expanded output style , but it seems that problem is that compiler still want to see my sass file in compresed output style because it gives me back this:
Compilation Error
Error: Invalid CSS after "body {": expected "}", was "{"
on line 1 of sass/c:\Users\Doma\Desktop\Nové webovky\Javascript
& webovky\alfabeta\pionyr.sass
body { {
Can someone please help? Maybe is some basic thing but I really didn´t find solution to this and I searched in many sources
Thank you very much
that happening because you use native language not english for your operation system to change that and make sure sass compiler working without errors write this in terminal/command line before you use sass compiling command chcp 1252 after code activated use sass compile as expected sass --watch style.scss:style.css --style expanded
update
sometimes this error happening because silly mistake try this may help some causes this solution with helpfully change the path name from c:\Users\Doma\Desktop\Nové webovky\Javascript & webovky\alfabeta\pionyr.sass to c:\Users\Doma\Desktop\Nov webovky\Javascript & webovky\alfabeta\pionyr.sass
just take out é form the folder path and try again.

Compass & Sass Deprecation warning

I just installed and Compass & Sass as described here.
I got the following warning when I ran compass watch for the first time. What exactly does it mean? What should I do to fix it, do I need to do anything?
$ (master) compass watch
>>> Compass is watching for changes. Press Ctrl-C to Stop.
DEPRECATION WARNING on line 87 of /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/css3/_deprecated-support.scss: #{} interpolation near operators will be simplified
in a future version of Sass. To preserve the current behavior, use quotes:
unquote('"$moz-"#{$experimental-support-for-mozilla} "$webkit-"#{$experimental-support-for-webkit} "$opera-"#{$experimental-support-for-opera} "$microsoft-"#{$experimental-support-for-microsoft} "$khtml-"#{$experimental-support-for-khtml}')
You can use the sass-convert command to automatically fix most cases.
DEPRECATION WARNING on line 92 of /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/css3/_deprecated-support.scss: #{} interpolation near operators will be simplified
in a future version of Sass. To preserve the current behavior, use quotes:
unquote('"$ie6-"#{$legacy-support-for-ie6} "$ie7-"#{$legacy-support-for-ie7} "$ie8-"#{$legacy-support-for-ie8}')
You can use the sass-convert command to automatically fix most cases.
write css/styles.css
To fix the error message, just change the line 87 from your "_deprecated-support.scss" file to this:
// A debug tool for checking browser support
#mixin debug-support-matrix($experimental: true, $ie: true) {
#debug '#{"$moz-"}$experimental-support-for-mozilla'
'#{"$webkit-"}$experimental-support-for-webkit'
'#{"$opera-"}$experimental-support-for-opera'
'#{"$microsoft-"}$experimental-support-for-microsoft'
'#{"$khtml-"}$experimental-support-for-khtml';
#debug '#{"$ie6-"}$legacy-support-for-ie6'
'#{"$ie7-"}$legacy-support-for-ie7'
'#{"$ie8-"}$legacy-support-for-ie8';
}
The file can be found at your /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/css3/_deprecated-support.scss

Compass watch generates syntax error in config.rb after editing it

I'm using SASS with Compass on my webserver. After editing my config.rb file and running "compass watch" it throws up following error. Before having edited the file it didn't throw the error. What could be going wrong here? Could it be the way the file is saved by my editor (coda)? Or is something else going on?
syntax error, unexpected tSTRING_BEG, expecting $end
#import "compass"
config.rb
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
#import "compass"
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
It is most likely that Coda is changing the formatting of the file, my bet is on the EOL (end of line) character. My config.rb has UNIX newlines and compiles as it should (Windows newlines are also OK). If I change it to Mac newlines, I get this error (which is pretty close to your error):
$ compass watch
SyntaxError on line ["24"] of /usr/local/lib/ruby/gems/1.9.1/gems/compass-0.12.2/lib/compass/configuration/serialization.rb: /path/to/config.rb:1: syntax error, unexpected tIDENTIFIER, expecting $end
# Require any addit...
My editor (Notepad++) says the file is encoded as ANSI. Changing it to some of the other encodings that my editor supports will give an error like this:
$ compass watch
SyntaxError on line ["24"] of /usr/local/lib/ruby/gems/1.9.1/gems/compass-0.12.2/lib/compass/configuration/serialization.rb: /path/to/config.rb:1: invalid multibyte char (US-ASCII)
Run with --trace to see the full backtrace

programatically invoking Sass::Exec::SassConvert generates wrong syntax

Sass::Exec::SassConvert.new(["{path_to_scss_file}.scss", "{path_to_css_file_to_generate}.css"]).process_result
When I run following command from inside a ruby script, the generated file contains "sass"-syntax instead of valid css
When I try to add a set_opts command to specify "-F scss -T css", just to be sure the convertor knows what to do, it throws an error:
NoMethodError: undefined method `banner=' for ["-F scss -T css"]:Array
The goal is to compile scss files to css files from inside an ant build script.
Everything is working except for the wrong syntax issue.
Is there anything I'm missing here?
I rewrote the script to use Sass::Engine instead of SassConvert.
After looking through the code of the SassConvert class, the following fragment pointed me to the solution:
unless [:scss, :sass].include?(#options[:to])
raise "Unknown format for sass-convert --to: #{name}"
end
It appears the SassConvert class only converts CSS files to .scss or .sass, not the other way around.
Also, the correct way to add option flags when calling Sass::Exec::SassConvert, is by doing the following:
sassConvert = Sass::Exec::SassConvert.new(["-F scss", "-T sass", "{path_to_from_file}", "{path_to_file_to_generate}"]
sassConvert.parse!
sassConvert.process_result

Resources