Class: Convey::Compiler
- Inherits:
-
Object
- Object
- Convey::Compiler
- Includes:
- Convey
- Defined in:
- lib/convey/compiler.rb
Constant Summary
Constants included from Convey
Class Method Summary collapse
Methods included from Convey
Class Method Details
.compile!(base_path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/convey/compiler.rb', line 5 def self.compile!(base_path) `rm -rf #{base_path}/compiled` Dir.mkdir("#{base_path}/compiled") files = Dir.glob("#{base_path}/**/*") root = "#{base_path}/compiled" files.each do |path| if File.directory?(path) unless path =~ /compiled/ Dir.mkdir("#{root}/#{path.gsub!(base_path, "")}") end next end = Convey::Compiler.process_file(path) local_path = [:path].gsub(base_path, "") if [:path] != path puts "Compiled #{path.gsub(base_path, "")} to /compiled#{local_path}" else puts "Copied #{path.gsub(base_path, "")} to /compiled#{local_path}" end File.open("#{root}#{local_path}", 'w') {|f| f.write([:data]) } end end |
.process_file(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/convey/compiler.rb', line 32 def self.process_file(path) = {} if File.exists?(path) if path =~ /\.haml/ [:data] = Haml::Engine.new( File.read(path) ).render [:type] = 'html' [:path] = path.gsub(".haml", ".html") elsif path =~ /\.sass/ [:data] = Sass::Engine.new( File.read(path) , :syntax => :sass).render [:type] = 'css' [:path] = path.gsub(".sass", ".css") elsif path =~ /\.coffee/ if coffee_installed? [:data] = `coffee -p #{path}` [:type] = 'javascript' [:path] = path.gsub(".coffee", ".js") else raise "CoffeeScript not installed! Run `brew install coffee` on OS X." end else = {:data => File.read(path), :path => path, :type => path.split('.').last} end else raise "Path '#{path}' doesn't exist." end return end |