How to combine compass with bless?

一世执手 提交于 2019-12-19 17:35:13

问题


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.


回答1:


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




回答2:


This works for the regular compile command, but it doesn't work when you watch it. After Bless is completed the watch process ends.




回答3:


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



回答4:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!