I am working on a Compass project and my final css output is huge so it needs to be be blessed .
I am using Codekit to compile my SCSS files, and it has the bless option for the less and sass files but unluckly this option seems to be not available for the compass projects (BTW there is no workaround to fix the problem https://github.com/bdkjones/CodeKit/issues/163)
Is there an alternative way to do that automatically after the compiling process? Is it possible to watch the css file with nodejs and then bless it?
====================================================
UPDATE
I am not using Codekit anymore I use Grunt to build the project assets and it works like a charm.
Well, it seems that using this reference you can simply do something like:
on_stylesheet_saved do |filename|
system('blessc ' + File.basename(filename))
end
after you have installed Bless.
What it does is simply attaching that event after you compile your Compass file :) Enjoy
This works for the regular compile command, but it doesn't work when you watch it. After Bless is completed the watch process ends.
I found that blessc just wouldn't execute, I'd get one of these two errors:
config.rb: No such file or directory - blessc (whatever filename)
or
env: node: No such file or directory
It turns out this is because blessc/node.js are installed in /usr/local/bin, and that is not in the PATH variable for ruby exec (/usr/bin:/bin:/usr/sbin:/sbin). The following code worked:
on_stylesheet_saved do |filename|
exec('PATH=$PATH:/usr/local/bin; blessc ' + filename + ' -f')
end
Edited to add: If after this you get errors saying that the files aren't css from bless, check if your absolute path to the file contains white space. You can escape the white space by doing the following:
on_stylesheet_saved do |filename|
exec('PATH=$PATH:/usr/local/bin; blessc ' + (filename.gsub! ' ', '\ ') + ' -f')
end
You can try the following code block, I've made couple of changes of Julian Xhokaxhiu answer:
on_stylesheet_saved do |filename|
begin
puts "Counting number of selector in :: " + filename
result = system('blessc',filename,'-f')
if not result
Kernel.exit(false)
else
puts "Blessed the file to support Older version of IE."
end
rescue Exception => e
puts "Please install bless.\nsudo npm install -g bless."
Kernel.exit(false)
end
end
来源:https://stackoverflow.com/questions/13259419/how-to-combine-compass-with-bless