Class: TableSetter::Command

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

Constant Summary

"table-setter is a Sinatra application for rendering and processing CSVs from google docs into HTML.\n\nUsage:\ntable-setter COMMAND path/to/table-setter/assets OPTIONS\n\ncommands:\nstart    run the development server, for deployment use config.ru\ninstall  copy the table-setter assets into the the directory\nbuild    statically build tables in the ./out/ directory\n\noptions:\n"

Instance Method Summary (collapse)

Constructor Details

- (Command) initialize

A new instance of Command



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

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 
  end
end

Instance Method Details

- (Object) build_out



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

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

- (Object) install_assets



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

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

- (Object) start_server



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

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