hotchkiss 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/hk +4 -28
- data/lib/hotchkiss/application.rb +2 -1
- data/lib/hotchkiss/cli/const.rb +8 -0
- data/lib/hotchkiss/cli/generate.rb +24 -0
- data/lib/hotchkiss/cli/migrate.rb +41 -0
- data/lib/hotchkiss/cli/willy.rb +33 -0
- data/lib/hotchkiss/cli.rb +4 -0
- data/lib/hotchkiss/controller.rb +2 -0
- data/lib/hotchkiss/router.rb +33 -6
- data/lib/hotchkiss/templates/generate/migration/migration +9 -0
- data/lib/hotchkiss/templates/new/Gemfile +2 -0
- data/lib/hotchkiss/templates/new/code/app/views/application.html.erb +2 -1
- data/lib/hotchkiss/templates/new/config/db.yml.example +3 -0
- data/lib/hotchkiss/templates/new/config/init.rb +3 -4
- data/lib/hotchkiss/templates/new/config.ru +1 -0
- data/lib/hotchkiss/version.rb +5 -0
- data/lib/hotchkiss.rb +1 -6
- metadata +40 -17
- data/lib/hotchkiss/templates/new/config/database.rb +0 -1
data/bin/hk
CHANGED
@@ -3,33 +3,9 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'rack'
|
5
5
|
require 'tilt'
|
6
|
+
require 'sequel'
|
7
|
+
require 'sqlite3'
|
6
8
|
require 'hotchkiss'
|
9
|
+
require 'hotchkiss/cli'
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
TEMPLATE_DIR = Gem::Specification.find_by_name("hotchkiss").gem_dir +
|
11
|
-
"/lib/hotchkiss/templates/"
|
12
|
-
|
13
|
-
desc "new NAME", "Create new hotchkiss application directories with skel files."
|
14
|
-
def new(name)
|
15
|
-
dir = Dir.pwd + '/' + name
|
16
|
-
FileUtils.mkdir(dir)
|
17
|
-
FileUtils.cp_r(TEMPLATE_DIR + "new/.", dir)
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "server", "Run development server"
|
21
|
-
def server(port = nil)
|
22
|
-
port ||= 3000
|
23
|
-
host ||= "127.0.0.1"
|
24
|
-
[:INT, :TERM].each { |sig| trap(sig) { exit } }
|
25
|
-
options = {}
|
26
|
-
options[:Host] = host
|
27
|
-
options[:Port] = port
|
28
|
-
options[:config] = "config.ru"
|
29
|
-
options[:server] = :webrick
|
30
|
-
HK::Server.start!(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
end # Generator
|
34
|
-
|
35
|
-
Generator.start(ARGV)
|
11
|
+
Cli::Willy.start(ARGV)
|
@@ -34,7 +34,8 @@ module HK
|
|
34
34
|
def self.burnbabyburn!
|
35
35
|
lambda do |env|
|
36
36
|
begin
|
37
|
-
route = @@router.match?(env)
|
37
|
+
route, params = @@router.match?(env)
|
38
|
+
env['hk.params'] = (params.nil? ? "" : params)
|
38
39
|
if !route.nil? && route.has_key?(:special)
|
39
40
|
env['hk.controller'] = route[:controller]
|
40
41
|
elsif !route.nil?
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Cli
|
2
|
+
|
3
|
+
class Generate < Thor
|
4
|
+
|
5
|
+
desc "model NAME", "Generate model files."
|
6
|
+
def model(name)
|
7
|
+
puts name
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "controller NAME", "Generate controller files."
|
11
|
+
def controller(name)
|
12
|
+
puts name
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "migration NAME", "Generate migration file."
|
16
|
+
def migration(name)
|
17
|
+
timestamp = Time.now.to_i
|
18
|
+
final_name = "#{timestamp}_#{name}"
|
19
|
+
FileUtils.cp_r(Cli::TEMPLATE_DIR + "generate/migration/migration", Dir.pwd + "/db/migrations/#{final_name}.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
end # Generate
|
23
|
+
|
24
|
+
end ## Cli
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Cli
|
2
|
+
|
3
|
+
class Migrate < Thor
|
4
|
+
|
5
|
+
desc "reset", "migration reset (erase and migration up)"
|
6
|
+
def reset
|
7
|
+
init
|
8
|
+
Sequel::Migrator.run(@db, MG_DIR, :target => 0)
|
9
|
+
Sequel::Migrator.run(@db, MG_DIR)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "to", "Update migrations (up or down) to VERSION."
|
13
|
+
def to
|
14
|
+
init
|
15
|
+
version = ENV['VERSION'].to_i
|
16
|
+
raise "No VERSION was provided" if version.nil?
|
17
|
+
Sequel::Migrator.run(@db, MG_DIR, :target => version)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "up", "Update migrations to latest available."
|
21
|
+
def up
|
22
|
+
init
|
23
|
+
Sequel::Migrator.run(@db, MG_DIR)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "down", "Full migration downgrade (erase all data)."
|
27
|
+
def down
|
28
|
+
init
|
29
|
+
Sequel::Migrator.run(@db, MG_DIR, :target => 0)
|
30
|
+
end
|
31
|
+
|
32
|
+
no_tasks do
|
33
|
+
def init
|
34
|
+
Sequel.extension :migration
|
35
|
+
@db = Sequel.connect(DB_INFOS[:url], DB_INFOS[:options])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end # Migrate
|
40
|
+
|
41
|
+
end ## Cli
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Cli
|
2
|
+
|
3
|
+
class Willy < Thor
|
4
|
+
|
5
|
+
desc "new NAME", "Create new hotchkiss application directories with skel files."
|
6
|
+
def new(name)
|
7
|
+
dir = Dir.pwd + '/' + name
|
8
|
+
FileUtils.mkdir(dir)
|
9
|
+
FileUtils.cp_r(TEMPLATE_DIR + "new/", dir)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "server [host - default 127.0.0.1] [port - default 3000]", "Run development server."
|
13
|
+
def server(host = nil, port = nil)
|
14
|
+
port ||= 3000
|
15
|
+
host ||= "127.0.0.1"
|
16
|
+
[:INT, :TERM].each { |sig| trap(sig) { exit } }
|
17
|
+
options = {}
|
18
|
+
options[:Host] = host
|
19
|
+
options[:Port] = port
|
20
|
+
options[:config] = "config.ru"
|
21
|
+
options[:server] = :webrick
|
22
|
+
HK::Server.start!(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "generate SUBCOMMAND", "Generators for model and controller files."
|
26
|
+
subcommand "generate", Generate
|
27
|
+
|
28
|
+
desc "migrate SUBCOMMAND", "Up/down migration tool."
|
29
|
+
subcommand "migrate", Migrate
|
30
|
+
|
31
|
+
end # Willy
|
32
|
+
|
33
|
+
end ## Cli
|
data/lib/hotchkiss/controller.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pp'
|
1
2
|
module HK
|
2
3
|
|
3
4
|
class Controller
|
@@ -5,6 +6,7 @@ module HK
|
|
5
6
|
def call(env)
|
6
7
|
@request = Rack::Request.new(env)
|
7
8
|
@response = Rack::Response.new()
|
9
|
+
@request.update_param :url, env['hk.params']
|
8
10
|
resp = self.send(env['hk.action'])
|
9
11
|
@response.write(resp)
|
10
12
|
@response.finish
|
data/lib/hotchkiss/router.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
1
3
|
module HK
|
2
4
|
|
3
5
|
class Router
|
4
6
|
|
5
7
|
def initialize
|
8
|
+
@routes_by_method = {}
|
6
9
|
@routes = []
|
7
10
|
yield(self)
|
8
11
|
finish
|
@@ -22,29 +25,53 @@ module HK
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def match?(env)
|
25
|
-
method = env['REQUEST_METHOD']
|
28
|
+
method = env['REQUEST_METHOD'].downcase.to_sym
|
26
29
|
path = env['REQUEST_PATH'].eql?("/") ? "/" : env['REQUEST_PATH'].gsub(/\/$/, '')
|
27
|
-
@
|
30
|
+
@routes_by_method[method].each do |route|
|
28
31
|
if path.match(route[:regexp])
|
29
|
-
return route
|
32
|
+
return route, extract_params(route, path.scan(route[:regexp]).flatten!)
|
30
33
|
end
|
31
34
|
end
|
32
|
-
return nil
|
35
|
+
return nil, nil
|
33
36
|
end
|
34
37
|
|
35
38
|
private
|
36
39
|
|
37
40
|
def compute
|
38
41
|
@routes.each do |route|
|
42
|
+
backup = String.new(route[:path])
|
39
43
|
computed_route = route[:path].gsub!(/((:\w+)|\*)/, /(\w+)/.to_s)
|
40
|
-
computed_route = "^#{route[:path]}$"
|
44
|
+
computed_route = "^#{route[:path]}$"
|
41
45
|
computed_route = Regexp.new(computed_route)
|
42
46
|
route[:regexp] = computed_route
|
47
|
+
route[:path] = backup
|
48
|
+
route[:params] = route[:path].scan(/:\w*/).map {|a| a.tr(':', '').to_sym}
|
49
|
+
if @routes_by_method.has_key? route[:method]
|
50
|
+
@routes_by_method[route[:method]] << route
|
51
|
+
else
|
52
|
+
@routes_by_method[route[:method]] = [route]
|
43
53
|
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_params(route, params)
|
58
|
+
length = route[:params].length
|
59
|
+
if length > 0 && length = params.length
|
60
|
+
par = {}
|
61
|
+
i = 0
|
62
|
+
while i < length
|
63
|
+
par[route[:params][i]] = params[i]
|
64
|
+
i += 1
|
65
|
+
end
|
66
|
+
par
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
44
70
|
end
|
45
71
|
|
46
72
|
def finish
|
47
|
-
@routes << {:path => "/favicon.ico", :action => "favicon",
|
73
|
+
@routes << { :method => :get, :path => "/favicon.ico", :action => "favicon",
|
74
|
+
:controller => :FastResponder, :special => true }
|
48
75
|
end
|
49
76
|
|
50
77
|
end # Router
|
@@ -1,8 +1,7 @@
|
|
1
1
|
|
2
|
+
db = YAML::load(File.open("#{HK::Application.root}/config/db.yml"))
|
3
|
+
Sequel.connect(db[:url], db[:options])
|
4
|
+
|
2
5
|
Dir["#{HK::Application.root}/code/lib/**/*.rb"].each { |file| require file }
|
3
6
|
Dir["#{HK::Application.root}/code/app/**/*.rb"].each { |file| require file }
|
4
7
|
|
5
|
-
# Add your custom requires.
|
6
|
-
#
|
7
|
-
# require HK::Application.root + '/a/path'
|
8
|
-
|
data/lib/hotchkiss.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotchkiss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: thor
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sequel
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description: Ruby web framework
|
95
111
|
email: tib@rocknroot.org
|
96
112
|
executables:
|
@@ -99,24 +115,31 @@ extensions: []
|
|
99
115
|
extra_rdoc_files:
|
100
116
|
- LICENSE.txt
|
101
117
|
files:
|
118
|
+
- lib/hotchkiss.rb
|
119
|
+
- lib/hotchkiss/application.rb
|
120
|
+
- lib/hotchkiss/cli.rb
|
121
|
+
- lib/hotchkiss/cli/const.rb
|
122
|
+
- lib/hotchkiss/cli/generate.rb
|
123
|
+
- lib/hotchkiss/cli/migrate.rb
|
124
|
+
- lib/hotchkiss/cli/willy.rb
|
125
|
+
- lib/hotchkiss/controller.rb
|
126
|
+
- lib/hotchkiss/errors.rb
|
102
127
|
- lib/hotchkiss/fast_responder.rb
|
128
|
+
- lib/hotchkiss/router.rb
|
129
|
+
- lib/hotchkiss/server.rb
|
130
|
+
- lib/hotchkiss/templates/generate/migration/migration
|
103
131
|
- lib/hotchkiss/templates/new/Gemfile
|
104
|
-
- lib/hotchkiss/templates/new/public/favicon.ico
|
105
|
-
- lib/hotchkiss/templates/new/config.ru
|
106
|
-
- lib/hotchkiss/templates/new/code/app/routes.rb
|
107
132
|
- lib/hotchkiss/templates/new/code/app/controllers/application_controller.rb
|
133
|
+
- lib/hotchkiss/templates/new/code/app/routes.rb
|
108
134
|
- lib/hotchkiss/templates/new/code/app/views/application.html.erb
|
109
|
-
- lib/hotchkiss/templates/new/config
|
135
|
+
- lib/hotchkiss/templates/new/config.ru
|
136
|
+
- lib/hotchkiss/templates/new/config/db.yml.example
|
110
137
|
- lib/hotchkiss/templates/new/config/init.rb
|
111
|
-
- lib/hotchkiss/
|
112
|
-
- lib/hotchkiss/
|
113
|
-
- lib/hotchkiss/application.rb
|
114
|
-
- lib/hotchkiss/controller.rb
|
115
|
-
- lib/hotchkiss/router.rb
|
116
|
-
- lib/hotchkiss.rb
|
138
|
+
- lib/hotchkiss/templates/new/public/favicon.ico
|
139
|
+
- lib/hotchkiss/version.rb
|
117
140
|
- LICENSE.txt
|
118
141
|
- bin/hk
|
119
|
-
homepage: https://github.com/RocknRoot/
|
142
|
+
homepage: https://github.com/RocknRoot/Hotchkiss
|
120
143
|
licenses:
|
121
144
|
- BSD
|
122
145
|
post_install_message:
|
@@ -137,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
160
|
version: '0'
|
138
161
|
requirements: []
|
139
162
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.8.
|
163
|
+
rubygems_version: 1.8.25
|
141
164
|
signing_key:
|
142
165
|
specification_version: 3
|
143
|
-
summary:
|
166
|
+
summary: Ruby web framework
|
144
167
|
test_files: []
|
@@ -1 +0,0 @@
|
|
1
|
-
# In 0.0.2
|