0
有沒有什麼辦法讓SASS編譯數據從數據庫傳遞過來?我可以使用DBI + ODBC從MSSQL Server 2008獲取數據,但是如何讓SASS編譯通過數據而不是文件?從數據庫獲取SASS(編譯通過的數據而不是從文件讀取)
找不到任何有用的東西,並且更改sass核心文件聽起來不像是一個好主意......尤其是考慮到零Ruby知識。
有沒有什麼辦法讓SASS編譯數據從數據庫傳遞過來?我可以使用DBI + ODBC從MSSQL Server 2008獲取數據,但是如何讓SASS編譯通過數據而不是文件?從數據庫獲取SASS(編譯通過的數據而不是從文件讀取)
找不到任何有用的東西,並且更改sass核心文件聽起來不像是一個好主意......尤其是考慮到零Ruby知識。
我結束了使用這塊代碼。完全不夠優雅,但我希望它能幫助有需要的人。
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')
它需要額外的dbi
和dbd-odbc
寶石和影響sass - 更新以及--watch。
希望這可以幫助別人。