Class: KiskoSuits::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/kisko-suits/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Application

Returns a new instance of Application.



3
4
5
# File 'lib/kisko-suits/application.rb', line 3

def initialize(argv)
  @params, @files = parse_options(argv)
end

Instance Method Details

#parse_options(argv) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/kisko-suits/application.rb', line 27

def parse_options(argv)
  params = {}
  parser = OptionParser.new

  parser.on("-w") { params[:watch] = true }
  files = parser.parse(argv)

  [params, files]
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kisko-suits/application.rb', line 7

def run
  if @files.empty? || @files.size > 1 || !@files.first.include?(".suits")
    abort "Usage: 'kisko-suits my-presentation.md.suits'\n\nOr start watching file with: 'kisko-suits -w my-presentation.md.suits'"
  else
    if @params[:watch]
      on_update = ->(filename) {
        compiler = KiskoSuits::Compiler.new(@files.first)
        compiler.render
        puts "Processed files and compiled '#{compiler.output_filename}'"
        compiler.included_filenames
      }
      KiskoSuits::Watcher.new(@files.first, on_update).start
    else
      compiler = KiskoSuits::Compiler.new(@files.first)
      compiler.render
      puts "Processed files and compiled '#{compiler.output_filename}'"
    end
  end
end