Class: Stic::CLI::Build

Inherits:
Command
  • Object
show all
Defined in:
lib/stic/cli/command.rb

Instance Method Summary collapse

Methods inherited from Command

define, #site, #to_help

Instance Method Details

#run(_result) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/stic/cli/command.rb', line 48

def run(_result)
  STDOUT.puts  " Configuration files: #{site.config.files.join(", ")}"
  STDOUT.puts  "              Source: #{site.source}"
  STDOUT.puts  "              Target: #{site.target}"
  STDOUT.print '       Generating ... '
  STDOUT.flush

  str_length = 0

  log = lambda do |str|
    STDOUT.print "\r                      " + ' ' * str_length
    STDOUT.print "\r                  ... #{str}"
    STDOUT.flush
    str_length = str.length
  end

  begin
    site.run {|generator| log.call "Running #{generator.class.name}" }
    site.write {|blob| log.call "Write #{blob.relative_url}" }
    site.cleanup
  rescue => e
    STDOUT.puts
    raise e
  end

  log.call 'done.'
  STDOUT.puts
end