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

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

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.

Add a Ruby command-line application to /usr/bin?

I have written a shell program in Ruby. Now I want to add it to my bin directory so that I can call the program by running $ my-rb-prog ....
First I tried to symlink my file into /usr/bin but then it said that it couldn't load the modules that I required.
On my second try, I tried to build a gem out of my project which worked fine, but I can still not access my shell program. After that I installed the gem. Here's what my gemspec looks like:
# -*- encoding: utf-8 -*-
$:.unshift(File.join(File.dirname(__FILE__), "/lib"))
require 'webcheck'
Gem::Specification.new do |s|
s.name = "webcheck"
s.version = WebCheck::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Victor Jonsson"]
s.email = ["kontakt#victorjonsson.se"]
s.homepage = "http://victorjonsson.se"
s.summary = %q{Check your website man!}
s.description = %q{Just check it!}
s.required_ruby_version = '>= 1.9.3'
s.add_dependency "httparty", "~> 0.12.0"
s.post_install_message = "Just check it!"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end
I thought that I would get access to my shell program, which is a Ruby file located in the bin directory inside my project, after that I had installed the gem but it clearly isn't that easy.
This is my first day of coding Ruby if you can't tell.
First, add a "she-bang" string as first line of your file. It will allow the shell to run the file. It should be:
#!/usr/bin/env ruby
Then give execution permissions to the file:
$ chmod +x your_file_name.rb
Now you can run your application:
./your_file_name.rb
Also you can add the path to the directory with this script to the PATH variable and run the application from anywhere you want.
# You may do this in ~/.bashrc file
PATH=$PATH:path/to/dir/with/script/
Don't forget to add #!/usr/bin/env ruby to the top of your Ruby script.
"Making a Ruby Script Executable" is a really good tutorial on making your executable available system wide, without the use of a gem.

How to ignore multiline comments in sass?

Is there a way to make sass ignore multiline comments when generating the css file:
// these comments are ignored
These are not (only ignored in compressed mode):
/*
* multiline comments
*
*/
I found this ticket on Github where the author says:
If you really want, you can monkeypatch Sass to silence /* */ comments as well.
But I don't know what he means by monkeypatch sass, so how can I do this ?
Yay! I've learned monkey patching SASS while answering this question:
Sass mixin recursion; #include loop
And now i can help you too!
1) Install Compass
For this solution to work, you'll need Compass. Install it with:
gem install compass
2) Configure Compass
Create a compass.rb file in your project's root and define directories where you keep your SASS and CSS code, e. g.:
css_dir = "stylesheets"
sass_dir = "sass"
3) Create a monkey patch
Create a file called remove-all-comments-monkey-patch.rb in your project's root:
class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base
# Removes all comments completely
def visit_comment(node)
return []
end
end
4) Require the monkey patch from the config.rb
In the config.rb, add:
# Removing all comments by applying a monkey patch to SASS compiler
require "./remove-all-comments-monkey-patch"
5) Compile your project with Compass
Use compass compile to compile SASS into CSS. You can also use compass watch to make the Compass command line tool constantly monitor your code for changes and recompile parts that you modify.
Considerations
This will not remove comments with line numbers generated by SASS. To disable them comment out the line_comments = true line in config.rb or set it to false.
To re-enable multiline comments, just comment out the line that requires the monkey patch and do compass clean.
Don't use it! Use single-line comments with Ctrl+/.
Though this solution is portable and will work for everybody without hacking SASS code manually, you should really consider using an IDE that allows commenting out whole paragraphs with single-line comments using a single keystroke. For me it's Ctrl+/.
Here, i've filmed a short video for you to show that using line comments is actually quicker and more effective than using multiline comments: http://www.youtube.com/watch?feature=player_detailpage&v=DTyMAPZrwyc
Line comments also let you comment out comments without breaking the code.
Consider you have the following code:
foo
/* Bla bla */
bar
baz
And you need to comment it all out. If you wrap it all with /* */...
/*foo
/* Bla bla */
bar
baz*/
...then you broke the code! Now you have a comment that starts with /*foo and ends with bla */, and also a syntax error at baz*/.
Instead, just select the whole code and hit Ctrl+/ (provided that use some IDE or programmer's notepad), it will all be commented out immediately:
//foo
//
///* Bla bla */
//bar
//
//baz
And of course it can later be uncommented with the same hotkey.
You could wrap the comment in an unused #mixin - not an ideal fix but it works.
#mixin ignore {
/*
COMMENT
*/
}

Can SASS/Compass compile foo.scss to foo.min.css and foo.dbg.css?

I want to compile a set of .scss files to different filenames.
In development, I want to compile eg. foo.scss to foo.dbg.css (unminified and with comments). In production, I want to have eg. foo.min.css (minified).
Is there a way to tell SASS/Compass what to use as the target extension? A command-line switch? A config.rb option?
Writing a script that first compiles and then renames files seems like a bad option, because then I can't use compass watch efficiently.
(Well, I could compile to two different output directories and then write a script that copies the files from there. That feels a bit clumsy.)
UPDATE: I worked around the problem by writing a simplified version of the watch code. When something changes, it triggers a recompile to two different output directories, then renames and moves the files to place.
I couldn't get Alireza Fattahi's answer to work because it threw errors so I found another example which works for me
http://h3r2on.com/2013/05/17/rename-css-on-compile.html
require "fileutils"
on_stylesheet_saved do |file|
if File.exists?(file)
filename = File.basename(file, File.extname(file))
File.rename(file, css_dir + "/" + filename + ".min" + File.extname(file))
end
end
No it can't. I asked the same question in the mailing lists about RTL stylesheets.
However, you can run compass compile using different 'config.rb' files.
Try compass compile -c debug.rb.
UPDATE: Compass still can't, but Gulp can watch and generate several target css files using Sass and Compass. See https://github.com/Snugug/gulp-css-target/
You can add this to your config.
Please see https://github.com/sbspk/Prepros/issues/38
require 'fileutils'
on_stylesheet_saved do |file|
if file.match('.min') == nil
require 'compass'
Compass.add_configuration(
{
:project_path => File.dirname(File.dirname(file)),
:sass_dir => File.basename(File.dirname(file)),
:css_path => File.basename(File.dirname(file)),
:output_style => :compressed
},
'alwaysmin' # A name for the configuration, can be anything you want
)
Compass.compiler.compile(File.dirname(file) + "/" + File.basename(file, '.css') + '.scss', File.dirname(file) + "/" + File.basename(file, '.css') + ".min.css")
end
end

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

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!

Resources