mcgluszak

CoffeeScript SCSS compiler

Apr 8th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.10 KB | None | 0 0
  1. require "coffee-script"
  2. require "sass"
  3.  
  4. SASS = true
  5. COFFEE = true
  6.  
  7. ScssDir = 'scss'
  8. CssDir = '../css'
  9. CoffeeDir = 'coffee'
  10. JsDir = '../js'
  11.  
  12. module CoffeeScript
  13.     class << self
  14.         def compile_file(file, js_file)
  15.             f = File.open(js_file, "wb")
  16.             s = File.open(file, "rb")
  17.             f.write compile(s.read)
  18.             f.close
  19.         end
  20.     end
  21. end
  22.  
  23. def change_names(arr)
  24.     arr.map {|n|
  25.         case File.extname(n)
  26.         when ".scss"
  27.             n.sub(ScssDir, CssDir).sub(".scss",".css")
  28.         when ".coffee"
  29.             n.sub(CoffeeDir, JsDir).sub(".coffee",".js")
  30.         end
  31.     }
  32. end
  33.  
  34. scss = File.join("**", "*.scss") if SASS
  35. coffee = File.join("**", "*.coffee") if COFFEE
  36.  
  37. Dir.mkdir CssDir if SASS and !Dir.exists? CssDir
  38. Dir.mkdir JsDir if COFFEE and !Dir.exists? JsDir
  39.  
  40. scssFiles = Dir.glob(scss) if SASS
  41. cssFiles = change_names(scssFiles) if SASS
  42. coffeeFiles = Dir.glob(coffee) if COFFEE
  43. jsFiles = change_names(coffeeFiles) if COFFEE
  44.  
  45. if SASS
  46.     for i in 0...scssFiles.size
  47.         Sass.compile_file(scssFiles[i], cssFiles[i])
  48.     end
  49. end
  50.  
  51. if COFFEE
  52.     for i in 0...coffeeFiles.size
  53.         CoffeeScript.compile_file(coffeeFiles[i], jsFiles[i])
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment