Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "coffee-script"
- require "sass"
- SASS = true
- COFFEE = true
- ScssDir = 'scss'
- CssDir = '../css'
- CoffeeDir = 'coffee'
- JsDir = '../js'
- module CoffeeScript
- class << self
- def compile_file(file, js_file)
- f = File.open(js_file, "wb")
- s = File.open(file, "rb")
- f.write compile(s.read)
- f.close
- end
- end
- end
- def change_names(arr)
- arr.map {|n|
- case File.extname(n)
- when ".scss"
- n.sub(ScssDir, CssDir).sub(".scss",".css")
- when ".coffee"
- n.sub(CoffeeDir, JsDir).sub(".coffee",".js")
- end
- }
- end
- scss = File.join("**", "*.scss") if SASS
- coffee = File.join("**", "*.coffee") if COFFEE
- Dir.mkdir CssDir if SASS and !Dir.exists? CssDir
- Dir.mkdir JsDir if COFFEE and !Dir.exists? JsDir
- scssFiles = Dir.glob(scss) if SASS
- cssFiles = change_names(scssFiles) if SASS
- coffeeFiles = Dir.glob(coffee) if COFFEE
- jsFiles = change_names(coffeeFiles) if COFFEE
- if SASS
- for i in 0...scssFiles.size
- Sass.compile_file(scssFiles[i], cssFiles[i])
- end
- end
- if COFFEE
- for i in 0...coffeeFiles.size
- CoffeeScript.compile_file(coffeeFiles[i], jsFiles[i])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment