Class: TableSetter::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/table_setter/command.rb

Constant Summary collapse

<<-EOB
table-setter is a Sinatra application for rendering and processing CSVs from google docs into HTML.

Usage:
  table-setter COMMAND path/to/table-setter/assets OPTIONS

commands:
  start    run the development server, for deployment use config.ru
  install  copy the table-setter assets into the the directory
  build    statically build tables in the ./out/ directory

options:
EOB

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/table_setter/command.rb', line 24

def initialize
  @prefix = ""
  parse_options
  @prefix = "/#{@prefix}/".gsub(/^\/\//, "/")
  command = ARGV.shift
  @directory = ARGV.shift || '.'
  TableSetter.configure @directory
  case command
  when 'start' then start_server
  when 'install' then install_assets
  when 'build' then build_out
  else puts BANNER
  end
end

Instance Method Details

#build_outObject



52
53
54
55
56
57
58
59
60
# File 'lib/table_setter/command.rb', line 52

def build_out
  @out_dir = File.join(TableSetter.config_path, 'out', @prefix)
  puts "\nBuilding your TableSetter files...\n\n"
  app = build_rack
  @request = Rack::MockRequest.new(app)
  build_index
  build_assets
  build_tables
end

#install_assetsObject



44
45
46
47
48
49
50
# File 'lib/table_setter/command.rb', line 44

def install_assets
  FileUtils.mkdir_p @directory unless File.exists? @directory
  puts "\nInstalling TableSetter files...\n\n"
  base_files.each do |path|
    copy_file path, File.join(TableSetter.config_path, path.gsub(ROOT + "/template/", "/"))
  end
end

#start_serverObject



39
40
41
42
# File 'lib/table_setter/command.rb', line 39

def start_server
  app = build_rack
  Rack::Handler::Thin.run app, :Port => "3000"
end