making a release to celebrate miniunit 1.1.0
[augment.git] / lib / augment.rb
blob116887bd7ca212d2660c09d4bc95f3e4ffaa36d3
1 $LOAD_PATH << File.dirname(__FILE__)
2 $LOAD_PATH << File.dirname(__FILE__) + '/backends'
3 $LOAD_PATH << File.dirname(__FILE__) + '/frontends'
5 require 'rubygems'
7 require 'layer'
8 require 'flet'
9 require 'backend'
10 require 'frontend'
12 class Augment
13   VERSION = '1.0.1'
14   BACKENDS = {}
15   FRONTENDS = {}
16   
17   def initialize(action, file)
18     raise "No backend or frontend with that name." if action.nil?
19     action.run(file)
20   end
22   class << self
23     ##
24     # Interactive mode allows you to repeatedly give augment a filename and have
25     # it spit back layer JSON immediately. By default only uses the test backend.
26     #
27     def interactive(backend_names = 'test')
28       loop do
29         begin
30           filename = STDIN.gets.chomp
31           backend_names.each { |backend| BACKENDS[backend].run(filename) }
32           puts "{\"#{filename}\" : #{File.read(augment_path(filename))} }"
33         rescue
34           puts "Error augmenting #{filename}."
35         end
36       end
37     end
39     # Where should the JSON layer files be given a file?
40     def augment_path(original)
41       "#{File.dirname(File.expand_path(original))}/.augment/#{File.basename(original)}"
42     end
43   end
44 end
46 # Load up backends and frontends
47 Dir.glob(File.dirname(__FILE__) + '/*ends/*rb').each { |b| require b[0 .. -4] }