在Grails 2.3.X中使用sass脚本
Sass是可用的最成熟,穩(wěn)定和強(qiáng)大的專業(yè)級(jí)CSS擴(kuò)展語(yǔ)言之一。 在使用Sass之前,我們需要在項(xiàng)目中進(jìn)行設(shè)置。
在grails-2.4.X中,通過(guò)資產(chǎn)管道插件很容易使用sass。 但是對(duì)于grails-2.3.x版本,我們需要遵循以下步驟:
步驟1
使用RVM安裝Ruby :
在以上命令中,我們正在使用“ RVM”安裝“ Ruby”。
第2步
安裝捆綁包和指南針寶石:
sudo apt-get install gem gem install bundle bundle -v gem install compassBundler是Rails 3的默認(rèn)gem管理器,盡管它可以與任何Ruby項(xiàng)目一起使用,因?yàn)樗灰蕾囉诳蚣堋?
第三步
在項(xiàng)目的根文件夾下添加了名為“ Gemfile”的新文件,其內(nèi)容如下:
source 'https://rubygems.org'gem 'compass', '~> 0.13.alpha.0'group :development dogem 'guard'gem 'guard-shell' end這樣可以確保Gemfile中指定的所有g(shù)em及其依賴關(guān)系都可用于您的應(yīng)用程序。
第四步
項(xiàng)目的內(nèi)部腳本文件夾:
bundle install運(yùn)行“捆綁安裝”將生成一個(gè)Gemfile.lock文件,該文件應(yīng)添加到您的git存儲(chǔ)庫(kù)中。 Gemfile.lock確保您在Heroku上部署的gem版本與開發(fā)計(jì)算機(jī)上本地安裝的版本匹配。
第5步
在scripts目錄下創(chuàng)建一個(gè)名為'compass-compile'的新腳本文件,其內(nèi)容如下:
#!/bin/shSTYLE="compact"if [ $1 ] thenSTYLE=$1 ficd $2 bundle exec compass compile --force --output-style $STYLE --environment production --css-dir web-app/css --sass-dir src/sass --images-dir web-app/images/在這里,在此腳本中,我們將“ sass”文件編譯為“ css”文件。
第6步
在腳本目錄下創(chuàng)建一個(gè)新的_Events.groovy文件,其內(nèi)容如下:
import grails.util.Environment eventCompileEnd = {x ->if(Environment.currentEnvironment!=Environment.TEST) {compileSass()} }def compileSass() {def baseDir = System.getProperty("base.dir")def commandif(baseDir != null) {command = """${baseDir}/scripts/compass-compile compact ${baseDir}"""// Create the String} else {command = """scripts/compass-compile compact ."""// Create the String}def proc = command.execute() // Call *execute* on the stringproc.waitFor() // Wait for the command to finishif(proc.exitValue() == 0) {def messages = proc.in.text.split("\n")messages.each { message ->event("StatusUpdate",[message])}} else {event("StatusError", ["Problem compiling SASS ${proc.err.text}"])} }當(dāng)我們運(yùn)行g(shù)rails應(yīng)用程序時(shí),將調(diào)用'compileSass()'函數(shù)。 此功能使用步驟5中指定的腳本將“ sass”文件編譯為“ css”文件。
步驟7
將您的sass文件添加到“ src / sass”目錄下。 上面的腳本將“ src / sass”目錄下的所有sass文件轉(zhuǎn)換為css文件,并將其復(fù)制到wep-app / css目錄中。
- 我也為此創(chuàng)建了一個(gè)演示應(yīng)用程序 。
希望能幫助到你!
翻譯自: https://www.javacodegeeks.com/2015/02/working-with-sass-scripts-in-grails-2-3-x.html
總結(jié)
以上是生活随笔為你收集整理的在Grails 2.3.X中使用sass脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【SQL时间截取】数据库Sql实现截取时
- 下一篇: Lambda的reduce元素规约