Class: WPRoot::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/wproot/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
7
8
# File 'lib/wproot/cli.rb', line 3

def initialize(argv)
  case argv.shift
  when 'watch'
    watch File.expand_path('.')
  end
end

Instance Method Details

#watch(directory) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wproot/cli.rb', line 10

def watch(directory)
  puts "Watching #{directory}"
  compile = lambda do |base, relative|
    path = File.join(base, relative)
    dir = File.dirname(path)
    if File.extname(relative) == '.haml'
      new_path = File.join(dir, File.basename(path, '.haml'))
      File.open(new_path, 'w') do |f|
        f.write(Haml.new(File.read(path)).compile)
        puts ">>> Compiled #{path} to #{new_path}"
      end
    elsif File.extname(relative) == '.sass'
      new_path = File.join(dir, File.basename(path, '.sass'))
      File.open(new_path, 'w') do |f|
        f.write(Compass.new(File.read(path)).compile)
        puts ">>> Compiled #{path} to #{new_path}"
      end
    end
  end

  Dir["**/*"].each do |f|
    compile.call(File.dirname(f), File.basename(f))
  end

  FSSM.monitor directory do
    update &compile
    create &compile
  end
end