2013-06-20 83 views
1

我需要提供動態CSS內容。總之,我需要這個:如何提供less-css上下文?

<link href="/css/site.css?color=111111" rel="stylesheet" type="text/css"> 

其中site.css具有未處理的較少代碼。

所以我在服務器端安裝的Node.js +以下,且後續行正常工作:

$ lessc testless.less 

但我還是沒弄明白如何配置服務器來回答這些HTTP請求。

1)什麼是最好的選擇:使用apache或node.js? (我已經安裝並運行了apache服務器)

2)我應該如何配置我的服務器和應用程序來實現此目的?

任何幫助,將不勝感激。

感謝 羅南

回答

0

我解決了同樣的問題,以建立http://twitterbootstrap3navbars.w3masters.nl/http://twitterbootstrap3buttons.w3masters.nl/。對於這兩個應用程序我使用Apache與PHP。

對於我使用的按鈕生成器Lessphp和navbar生成器,我通過PHP的exec()調用lessc。

我使用較少的代碼來編寫內聯式樣式表。在你的情況下,你會創建一個動態樣式表。

因此,例如使用:

<link href="/css/site.php?color=111111" rel="stylesheet" type="text/css">

隨着site.php:

<? 
//use lessphp from http://leafo.net/lessphp/ 
header("Content-type: text/css", true); 
$less = new lessc; 
echo $less->compile('p {color: '.$_GET['color'].'; }'); 
exit; 

<? 
//use lessc 
header("Content-type: text/css", true); 
exec(echo "p { color: '.$_GET['color'].'; }" | /usr/local/bin/lessc -',$output,$error); 
echo implode("\n",$output); 
exit; 
0

我會建議其他預處理器,它是基於JavaScript - http://krasimir.github.io/absurd/。這個想法是使用JavaScript對象或JSON並生成CSS。稍後,可以將此CSS添加到文檔中。

api.add({ 
    body: { 
     marginTop: "20px", 
     width: "100%" 
    }, 
    header: { 
     width: "100%" 
    } 
}); 

編譯爲:

body { 
    margin-top: 20px; 
} 
body, header { 
    width: 100%; 
} 

AbsurdJS可用於服務器端(的NodeJS)或客戶端的使用。好處是你可以使用通常的js代碼中可用的所有東西。

相關問題