Skip to content

Commit

Permalink
Start to play and structure the application
Browse files Browse the repository at this point in the history
  • Loading branch information
David Henry committed Oct 20, 2011
1 parent cccb0a1 commit aa56107
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
log/*
*.swp
*.swo
*.un~
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm use --install --create 1.9.2-p180@workflow
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,5 +1,6 @@
source :rubygems
gem 'sinatra', '>= 1.0'
gem 'sinatra'
gem 'sinatra-namespace'
gem 'rake'
gem 'data_mapper'
gem 'dm-core'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Expand Up @@ -67,6 +67,8 @@ GEM
sinatra (1.2.6)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
sinatra-namespace (0.6.1)
sinatra (~> 1.1)
stringex (1.2.1)
tilt (1.3.2)
uuidtools (2.1.2)
Expand All @@ -86,4 +88,5 @@ DEPENDENCIES
rack-test
rake
rspec
sinatra (>= 1.0)
sinatra
sinatra-namespace
23 changes: 0 additions & 23 deletions application.rb

This file was deleted.

13 changes: 7 additions & 6 deletions config.ru
@@ -1,11 +1,12 @@
require File.join(File.dirname(__FILE__), 'application')
require 'rubygems'
require File.join(File.dirname(__FILE__), 'lib', 'workflow.rb')

set :run, false
set :environment, :production

FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a+")
$stdout.reopen(log)
$stderr.reopen(log)
# FileUtils.mkdir_p 'log' unless File.exists?('log')
# log = File.new("log/sinatra.log", "a+")
# $stdout.reopen(log)
# $stderr.reopen(log)

run Sinatra::Application
run Workflow::Routes
51 changes: 26 additions & 25 deletions environment.rb
@@ -1,25 +1,26 @@
require 'rubygems'
require 'bundler/setup'
require 'dm-core'
require 'dm-timestamps'
require 'dm-validations'
require 'dm-aggregates'
require 'dm-migrations'
require 'haml'
require 'ostruct'

require 'sinatra' unless defined?(Sinatra)

configure do
SiteConfig = OpenStruct.new(
:title => 'Your Application Name',
:author => 'Your Name',
:url_base => 'http://localhost:4567/'
)

# load models
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }

DataMapper.setup(:default, (ENV["DATABASE_URL"] || "sqlite3:///#{File.expand_path(File.dirname(__FILE__))}/#{Sinatra::Base.environment}.db"))
end
# require 'rubygems'
# require 'bundler/setup'
# require 'dm-core'
# require 'dm-timestamps'
# require 'dm-validations'
# require 'dm-aggregates'
# require 'dm-migrations'
# require 'haml'
# require 'ostruct'
#
# require 'sinatra' unless defined?(Sinatra)
#
# configure do
# SiteConfig = OpenStruct.new(
# :title => 'Your Application Name',
# :author => 'Your Name',
# :url_base => 'http://localhost:4567/'
# )
#
# # load models
# $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
# Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }
#
# DataMapper.setup(:default, (ENV["DATABASE_URL"] || "sqlite3:///#{File.expand_path(File.dirname(__FILE__))}/#{Sinatra::Base.environment}.db"))
# end
#
11 changes: 11 additions & 0 deletions lib/workflow.rb
@@ -0,0 +1,11 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'sinatra'
require 'sinatra/namespace'
require 'json'
# require 'mongoid'
# require 'airbrake'

require 'workflow/workflow'
require 'workflow/routes'
30 changes: 30 additions & 0 deletions lib/workflow/routes.rb
@@ -0,0 +1,30 @@
SiteConfig = OpenStruct.new(
:title => 'Workflow Monitor',
:author => 'David Henry',
:url_base => 'http://workflow-monitor.herokuapp.com/'
)

module Workflow
class Routes < Sinatra::Base
configure do |config|
# mongo_env = YAML.load_file(File.join(File.dirname(__FILE__) ,'..', '..', 'config', 'mongoid.yml'))[config.environment.to_s]
# Mongoid.config do |config|
# mongo_connection = Mongo::Connection.new(mongo_env["host"]).db(mongo_env["database"])
# mongo_connection.authenticate(mongo_env["user"], mongo_env["password"]) if mongo_env["user"]
# config.master = mongo_connection
# end

end

require 'workflow/routes/root'
use Root

require 'workflow/routes/process'
use Process

require 'workflow/routes/tasks'
use Tasks
end
end


31 changes: 31 additions & 0 deletions lib/workflow/routes/process.rb
@@ -0,0 +1,31 @@
module Workflow
class Routes
class Process < Sinatra::Base
register Sinatra::Namespace

namespace '/process' do
get '' do
haml :'tasks/index'
end

get '/:id/show' do
haml 'show process'
end

namespace '/:process_id/tasks' do
get '/new' do
haml 'new task'
end

post '/create' do
haml 'create task'
end

delete '/:id' do
haml 'delete task'
end
end
end
end
end
end
35 changes: 35 additions & 0 deletions lib/workflow/routes/root.rb
@@ -0,0 +1,35 @@
module Workflow
class Routes
class Root < Sinatra::Base
set :public, 'public/'

get '/application.css' do
sass :style
end

get '/' do
@name, @ruby_version, @gems = self.class.sysinfo
haml :sysinfo
end

def self.sysinfo
[name, ruby_version, gems]
end

private
def self.name
to_s
end

def self.ruby_version
%x[ruby --version]
end

def self.gems
gems = %x[bundle list]
gems.split('*')[1..-1]
end
end
end
end

33 changes: 33 additions & 0 deletions lib/workflow/routes/tasks.rb
@@ -0,0 +1,33 @@
module Workflow
class Routes
class Tasks < Sinatra::Base
register Sinatra::Namespace

namespace '/tasks' do
get '' do
haml :'tasks/index'
end

get '/new' do
haml 'new record??'
end

post '/create' do
haml 'create'
end

get '/show/:id' do
haml 'show'
end

get '/edit/:id' do
haml 'edit'
end

put '/update/:id' do
haml 'update'
end
end
end
end
end
3 changes: 3 additions & 0 deletions lib/workflow/workflow.rb
@@ -0,0 +1,3 @@
module Workflow

end
8 changes: 8 additions & 0 deletions views/sysinfo.haml
@@ -0,0 +1,8 @@
.project_name Project name: #{@name}
.ruby_version Ruby version: #{@ruby_version}
.gems
Gems:
%ul
- @gems.each do |gem|
%li= gem

1 change: 1 addition & 0 deletions views/tasks/index.haml
@@ -0,0 +1 @@
this is a index

0 comments on commit aa56107

Please sign in to comment.