require 'sinatra/base' require 'yaml' require 'json' require 'uri' require_relative 'teamster/login' require_relative 'teamster/general_helper' require_relative 'teamster/base_module' module Teamster module Core class App < Sinatra::Base @@modules = [] @@views = [] @@title = 'TEAMSTER' CORE_CONFIG = 'conf/teamster.conf' # NOTE: Class methods used in configure block needs be declared # before the configure block. def self.set_default_options_from(core_opts) @@title = core_opts[:title] end def self.current_working_folder Dir.pwd end configure do set :root, current_working_folder @@views << "#{settings.root}/views" enable :sessions set :session_secret, 'THIS IS MY SESSION SECRET KEY' set :core_opts, YAML.load_file(CORE_CONFIG) set_default_options_from settings.core_opts use Login end helpers GeneralHelper get '/' do erb :index end def summary_div_class_for(index) size = all_modules.size if size == 1 "col-lg-12" elsif size%2 == 0 "col-lg-6" else last = size - 1 index == last ? "col-lg-12" : "col-lg-6" end end def summary_of(module_name) name = module_name.downcase if send(:"#{name}_summary?") send(:"#{name}_summary") else erb :no_summary end end def self.modules @@modules end def self.views @@views end def self.title @@title end def self.use_module(teamster_module) if @@modules.include? teamster_module puts "Module #{teamster_module} already registered!" else @@modules << teamster_module @@views << teamster_module.views end teamster_module.helpers GeneralHelper if teamster_module.has_helper? teamster_module.helper_module.flatten.each do |mod| helpers mod end end use teamster_module end end end end