2012-07-18 44 views

回答

1

我結束了使用這塊代碼。完全不夠優雅,但我希望它能幫助有需要的人。

sql.rb在青菜寶石DIR:

require 'dbi' 
require 'sass' 
require config with database credentials 

if File.exist?(config) 
    require config 

    SQL_OPTIONS = { 
     :style => :nested, 
     :load_paths => ['.'], 
     :cache => true, 
     :cache_location => './.sass-cache', 
     :syntax => :scss, 
     :filesystem_importer => Sass::Importers::Filesystem, 
     :css_location => "./public/stylesheets", 
     :always_update => true, 
     :template_location => [["scss", "css"]] 
    }.freeze 

    db = DBI.connect('dbi:ODBC:driver={SQL Server};server=' + $db_host, $db_user, $db_pass) 

    db.select_all('SELECT name, scope, content FROM ' + $db_name + '.dbo.scss') do | row | 
     File.open(Dir.pwd + '/css/' + row['name'] + '.css', 'w') do |css| 
      css.puts Sass::Engine.new(row['content'], SQL_OPTIONS).render 
      puts ' overwrite css/' + row['name'] + '.css [db]' 
     end 
    end 
else 
    puts 'ignore database stylesheets, config_ruby doesn\'t exist' 
end 

在LIB /上海社會科學院/ engine.rb我包括在最後這個文件:

require File.expand_path(File.dirname(__FILE__) + '../../../sql') 

它需要額外的dbidbd-odbc寶石和影響sass - 更新以及--watch。

希望這可以幫助別人。