在Grails 2.3.X中使用sass脚本
Sass是可用的最成熟,穩定和強大的專業級CSS擴展語言之一。 在使用Sass之前,我們需要在項目中進行設置。
在grails-2.4.X中,通過資產管道插件很容易使用sass。 但是對于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的默認gem管理器,盡管它可以與任何Ruby項目一起使用,因為它不依賴于框架。
第三步
在項目的根文件夾下添加了名為“ Gemfile”的新文件,其內容如下:
source 'https://rubygems.org'gem 'compass', '~> 0.13.alpha.0'group :development dogem 'guard'gem 'guard-shell' end這樣可以確保Gemfile中指定的所有gem及其依賴關系都可用于您的應用程序。
第四步
項目的內部腳本文件夾:
bundle install運行“捆綁安裝”將生成一個Gemfile.lock文件,該文件應添加到您的git存儲庫中。 Gemfile.lock確保您在Heroku上部署的gem版本與開發計算機上本地安裝的版本匹配。
第5步
在scripts目錄下創建一個名為'compass-compile'的新腳本文件,其內容如下:
#!/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步
在腳本目錄下創建一個新的_Events.groovy文件,其內容如下:
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}"])} }當我們運行grails應用程序時,將調用'compileSass()'函數。 此功能使用步驟5中指定的腳本將“ sass”文件編譯為“ css”文件。
步驟7
將您的sass文件添加到“ src / sass”目錄下。 上面的腳本將“ src / sass”目錄下的所有sass文件轉換為css文件,并將其復制到wep-app / css目錄中。
- 我也為此創建了一個演示應用程序 。
希望能幫助到你!
翻譯自: https://www.javacodegeeks.com/2015/02/working-with-sass-scripts-in-grails-2-3-x.html
總結
以上是生活随笔為你收集整理的在Grails 2.3.X中使用sass脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【SQL时间截取】数据库Sql实现截取时
- 下一篇: Lambda的reduce元素规约