pakyow-core 0.7.2 → 0.8rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/pakyow-core/bin/pakyow +7 -6
  2. data/pakyow-core/lib/commands/USAGE +2 -1
  3. data/pakyow-core/lib/commands/console.rb +1 -1
  4. data/pakyow-core/lib/commands/server.rb +1 -1
  5. data/pakyow-core/lib/core/application.rb +129 -404
  6. data/pakyow-core/lib/core/base.rb +16 -4
  7. data/pakyow-core/lib/core/configuration/app.rb +6 -2
  8. data/pakyow-core/lib/core/configuration/server.rb +6 -1
  9. data/pakyow-core/lib/core/fn_context.rb +5 -0
  10. data/pakyow-core/lib/core/helpers.rb +16 -0
  11. data/pakyow-core/lib/core/loader.rb +1 -2
  12. data/pakyow-core/lib/core/log.rb +13 -9
  13. data/pakyow-core/lib/core/middleware/logger.rb +37 -0
  14. data/pakyow-core/lib/core/middleware/not_found.rb +40 -0
  15. data/pakyow-core/lib/core/middleware/presenter.rb +25 -0
  16. data/pakyow-core/lib/core/middleware/reloader.rb +14 -0
  17. data/pakyow-core/lib/core/middleware/router.rb +33 -0
  18. data/pakyow-core/lib/core/middleware/setup.rb +15 -0
  19. data/pakyow-core/lib/core/middleware/static.rb +27 -0
  20. data/pakyow-core/lib/core/presenter_base.rb +4 -0
  21. data/pakyow-core/lib/core/request.rb +43 -15
  22. data/pakyow-core/lib/core/response.rb +6 -0
  23. data/pakyow-core/lib/core/route_lookup.rb +37 -0
  24. data/pakyow-core/lib/core/route_set.rb +260 -0
  25. data/pakyow-core/lib/core/route_template.rb +77 -0
  26. data/pakyow-core/lib/core/route_template_defaults.rb +29 -0
  27. data/pakyow-core/lib/core/router.rb +156 -0
  28. data/pakyow-core/lib/generators/pakyow/app/app_generator.rb +12 -2
  29. data/pakyow-core/lib/generators/pakyow/app/templates/app.rb +12 -0
  30. data/pakyow-core/lib/generators/pakyow/app/templates/config.ru +1 -1
  31. data/pakyow-core/lib/generators/pakyow/app/templates/rakefile +1 -1
  32. data/pakyow-core/lib/generators/pakyow/app/templates/{app/views → views}/main.html +0 -0
  33. data/pakyow-core/lib/generators/pakyow/app/templates/{app/views → views}/pakyow.html +1 -1
  34. data/pakyow-core/lib/utils/string.rb +11 -10
  35. metadata +61 -71
  36. data/pakyow-core/lib/core/logger.rb +0 -33
  37. data/pakyow-core/lib/core/reloader.rb +0 -12
  38. data/pakyow-core/lib/core/route_store.rb +0 -220
  39. data/pakyow-core/lib/core/static.rb +0 -25
  40. data/pakyow-core/lib/generators/pakyow/app/templates/app/lib/application_controller.rb +0 -6
  41. data/pakyow-core/lib/generators/pakyow/app/templates/config/application.rb +0 -18
  42. data/pakyow-core/lib/generators/pakyow/app/templates/logs/requests.log +0 -0
metadata CHANGED
@@ -1,62 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pakyow-core
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 0
8
- - 7
9
- - 2
10
- version: 0.7.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8rc1
5
+ prerelease: 3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Bryan Powell
14
9
  - Bret Young
15
10
  autorequire:
16
11
  bindir: pakyow-core/bin
17
12
  cert_chain: []
18
-
19
- date: 2012-02-29 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2013-02-11 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 1
32
- - 3
33
- version: "1.3"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.3'
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: shoulda
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: turn
33
+ requirement: !ruby/object:Gem::Requirement
40
34
  none: false
41
- requirements:
35
+ requirements:
42
36
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 2
47
- - 11
48
- version: "2.11"
37
+ - !ruby/object:Gem::Version
38
+ version: '0.9'
49
39
  type: :development
50
- version_requirements: *id002
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
51
47
  description: pakyow-core
52
48
  email: bryan@metabahn.com
53
- executables:
49
+ executables:
54
50
  - pakyow
55
51
  extensions: []
56
-
57
52
  extra_rdoc_files: []
58
-
59
- files:
53
+ files:
60
54
  - pakyow-core/CHANGES
61
55
  - pakyow-core/README
62
56
  - pakyow-core/MIT-LICENSE
@@ -72,25 +66,33 @@ files:
72
66
  - pakyow-core/lib/core/configuration/app.rb
73
67
  - pakyow-core/lib/core/configuration/base.rb
74
68
  - pakyow-core/lib/core/configuration/server.rb
69
+ - pakyow-core/lib/core/fn_context.rb
75
70
  - pakyow-core/lib/core/helpers.rb
76
71
  - pakyow-core/lib/core/loader.rb
77
72
  - pakyow-core/lib/core/log.rb
78
- - pakyow-core/lib/core/logger.rb
73
+ - pakyow-core/lib/core/middleware/logger.rb
74
+ - pakyow-core/lib/core/middleware/not_found.rb
75
+ - pakyow-core/lib/core/middleware/presenter.rb
76
+ - pakyow-core/lib/core/middleware/reloader.rb
77
+ - pakyow-core/lib/core/middleware/router.rb
78
+ - pakyow-core/lib/core/middleware/setup.rb
79
+ - pakyow-core/lib/core/middleware/static.rb
79
80
  - pakyow-core/lib/core/presenter_base.rb
80
- - pakyow-core/lib/core/reloader.rb
81
81
  - pakyow-core/lib/core/request.rb
82
- - pakyow-core/lib/core/route_store.rb
83
- - pakyow-core/lib/core/static.rb
82
+ - pakyow-core/lib/core/response.rb
83
+ - pakyow-core/lib/core/route_lookup.rb
84
+ - pakyow-core/lib/core/route_set.rb
85
+ - pakyow-core/lib/core/route_template.rb
86
+ - pakyow-core/lib/core/route_template_defaults.rb
87
+ - pakyow-core/lib/core/router.rb
84
88
  - pakyow-core/lib/generators/pakyow/app/app_generator.rb
85
- - pakyow-core/lib/generators/pakyow/app/templates/app/lib/application_controller.rb
86
- - pakyow-core/lib/generators/pakyow/app/templates/app/views/main.html
87
- - pakyow-core/lib/generators/pakyow/app/templates/app/views/pakyow.html
88
- - pakyow-core/lib/generators/pakyow/app/templates/config/application.rb
89
+ - pakyow-core/lib/generators/pakyow/app/templates/app.rb
89
90
  - pakyow-core/lib/generators/pakyow/app/templates/config.ru
90
- - pakyow-core/lib/generators/pakyow/app/templates/logs/requests.log
91
91
  - pakyow-core/lib/generators/pakyow/app/templates/public/favicon.ico
92
92
  - pakyow-core/lib/generators/pakyow/app/templates/rakefile
93
93
  - pakyow-core/lib/generators/pakyow/app/templates/README
94
+ - pakyow-core/lib/generators/pakyow/app/templates/views/main.html
95
+ - pakyow-core/lib/generators/pakyow/app/templates/views/pakyow.html
94
96
  - pakyow-core/lib/pakyow-core.rb
95
97
  - pakyow-core/lib/utils/dir.rb
96
98
  - pakyow-core/lib/utils/hash.rb
@@ -98,38 +100,26 @@ files:
98
100
  - pakyow-core/bin/pakyow
99
101
  homepage: http://pakyow.com
100
102
  licenses: []
101
-
102
103
  post_install_message:
103
104
  rdoc_options: []
104
-
105
- require_paths:
105
+ require_paths:
106
106
  - pakyow-core/lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 57
113
- segments:
114
- - 1
115
- - 8
116
- - 7
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
117
112
  version: 1.8.7
118
- required_rubygems_version: !ruby/object:Gem::Requirement
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
114
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
115
+ requirements:
116
+ - - ! '>'
117
+ - !ruby/object:Gem::Version
118
+ version: 1.3.1
127
119
  requirements: []
128
-
129
120
  rubyforge_project: pakyow-core
130
- rubygems_version: 1.8.11
121
+ rubygems_version: 1.8.23
131
122
  signing_key:
132
123
  specification_version: 3
133
124
  summary: pakyow-core
134
125
  test_files: []
135
-
@@ -1,33 +0,0 @@
1
- module Pakyow
2
- class Logger
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- began_at = Time.now
9
-
10
- Log.enter "Processing #{env['PATH_INFO']} (#{env['REMOTE_ADDR']} at #{began_at}) [#{env['REQUEST_METHOD']}]"
11
-
12
- result = nil
13
-
14
- if error = catch(:error) {
15
- result = @app.call(env)
16
- nil
17
- }
18
- Log.enter "[500] #{error}\n"
19
- Log.enter error.backtrace.join("\n") + "\n\n"
20
-
21
- result = Pakyow.app.response.finish
22
- end
23
-
24
- ended_at = Time.now.to_f
25
- difference = ((ended_at - began_at.to_f) * 1000).to_f
26
-
27
- Log.enter "Completed in #{difference}ms | #{Pakyow.app.response.status} | [#{Pakyow.app.request.url}]"
28
- Log.enter
29
-
30
- result
31
- end
32
- end
33
- end
@@ -1,12 +0,0 @@
1
- module Pakyow
2
- class Reloader
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- @app.reload
9
- @app.call(env)
10
- end
11
- end
12
- end
@@ -1,220 +0,0 @@
1
- module Pakyow
2
- class RouteStore
3
-
4
- def initialize()
5
- @order = 1
6
- @store =
7
- {
8
- # string routes are stored, for each method, as a hash of 'route'=>{:block=>b,:order=>n,:hooks=>{...}}}
9
- :string => {:get=>{}, :post=>{}, :put=>{}, :delete=>{}},
10
-
11
- # regex routes are stored, for each method, as an array of hashes {:regex=>r,:block=>b,:order=>n,:vars=>{n=>var},:hooks=>{...}}
12
- # they are in definition order in the array
13
- :regex => {:get=>[], :post=>[], :put=>[], :delete=>[]},
14
-
15
- # :order is a global order across both string and regex routes.
16
-
17
- # hooks are blocks stored by name and used to augment returned block from get_block
18
- :hooks => {}
19
- }
20
- end
21
-
22
- def add_route(route_spec, block, method, data, hooks)
23
- route_spec = normalize_route(route_spec)
24
- hooks = normalize_hooks(hooks)
25
- route_to_match, vars = build_route_matcher(route_spec, data)
26
-
27
- if route_to_match.is_a?(String)
28
- @store[:string][method][route_to_match]={:block => block,
29
- :order => @order,
30
- :hooks => hooks,
31
- :data => data}
32
- @order = @order + 1
33
- elsif route_to_match.is_a?(Regexp)
34
- @store[:regex][method] << {:regex => route_to_match,
35
- :block => block,
36
- :order => @order,
37
- :vars => vars,
38
- :hooks => hooks,
39
- :data => data}
40
- @order = @order + 1
41
- else
42
- if Configuration::Base.app.dev_mode == true
43
- Log.warn("Unsupported route spec class. (#{route_spec.class})")
44
- else
45
- Log.warn("Unsupported route spec class. (#{route_spec.class})")
46
- raise "Unsupported route spec class. (#{route_spec.class})"
47
- end
48
- end
49
-
50
- end
51
-
52
- def add_hook(name, hook)
53
- @store[:hooks][name] = hook
54
- end
55
-
56
- # returns block, {:vars=>{:var=>matched_value, ...}, :data=>data}
57
- def get_block(route, method)
58
- route = normalize_route(route)
59
- # Get the match for a string route
60
- string_route_match = @store[:string][method][route]
61
-
62
- # Get first regex match
63
- regex_route_match = nil
64
- match_data = nil
65
- @store[:regex][method].each { |rinfo|
66
- if match_data = rinfo[:regex].match(route)
67
- regex_route_match = rinfo
68
- break
69
- end
70
- }
71
-
72
- # return block for match with smaller :order
73
- if string_route_match && regex_route_match
74
- if string_route_match[:order] < regex_route_match[:order]
75
- data = string_route_match[:data]
76
- return build_hooked_block(string_route_match[:block], string_route_match[:hooks]),
77
- {:vars=>{}, :data=>data}
78
- else
79
- data = regex_route_match[:data]
80
- return build_hooked_block(regex_route_match[:block], regex_route_match[:hooks]),
81
- {:vars=>build_regex_var_values(regex_route_match[:vars], match_data), :data=>data}
82
- end
83
- elsif string_route_match
84
- data = string_route_match[:data]
85
- return build_hooked_block(string_route_match[:block], string_route_match[:hooks]),
86
- {:vars=>{}, :data=>data}
87
- elsif regex_route_match
88
- data = regex_route_match[:data]
89
- return build_hooked_block(regex_route_match[:block], regex_route_match[:hooks]),
90
- {:vars=>build_regex_var_values(regex_route_match[:vars], match_data), :data=>data}
91
- else
92
- return nil,
93
- {:vars=>{}, :data=>nil}
94
- end
95
-
96
- end
97
-
98
- private
99
-
100
- def build_hooked_block(block, hooks)
101
- unless hooks
102
- return block
103
- end
104
- lambda {
105
- hooks[:before].map { |h|
106
- @store[:hooks][h].call() if @store[:hooks][h]
107
- } if hooks && hooks[:before]
108
-
109
- hooks[:around].map { |h|
110
- @store[:hooks][h].call() if @store[:hooks][h]
111
- } if hooks && hooks[:around]
112
-
113
- block.call()
114
-
115
- hooks[:around].map { |h|
116
- @store[:hooks][h].call() if @store[:hooks][h]
117
- } if hooks && hooks[:around]
118
-
119
- hooks[:after].map { |h|
120
- @store[:hooks][h].call() if @store[:hooks][h]
121
- } if hooks && hooks[:after]
122
- }
123
- end
124
-
125
- # Returns a regex and an array of variable info
126
- def build_route_matcher(route_spec, data)
127
- return route_spec, [] if route_spec.is_a?(Regexp)
128
-
129
- if route_spec.is_a?(String)
130
- # check for vars
131
- return route_spec, [] unless route_spec[0,1] == ':' || route_spec.index('/:')
132
- # we have vars
133
- if data[:route_type] == :user
134
- return build_user_route_matcher(route_spec)
135
- elsif data[:route_type] == :restful
136
- return build_restful_route_matcher(route_spec, data)
137
- else
138
- raise "Unknown route type. (#{data[:route_type]})"
139
- end
140
- end
141
-
142
- return route_spec, []
143
- end
144
-
145
- def build_user_route_matcher(route_spec)
146
- vars = []
147
- position_counter = 1
148
- regex_route = route_spec
149
- route_segments = route_spec.split('/')
150
- route_segments.each_with_index { |segment, i|
151
- if segment.include?(':')
152
- vars << { :position => position_counter, :var => segment.gsub(':', '') }
153
- if i == route_segments.length-1 then
154
- regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
155
- position_counter += 2
156
- else
157
- regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
158
- position_counter += 2
159
- end
160
- end
161
- }
162
- reg = Regexp.new("^#{regex_route}$")
163
- return reg, vars
164
- end
165
-
166
- def build_restful_route_matcher(route_spec, data)
167
- build_user_route_matcher(route_spec) unless data[:restful][:restful_action] == :show
168
-
169
- #special case for restful show route, can't match 'new' on last var
170
- vars = []
171
- position_counter = 1
172
- regex_route = route_spec
173
- route_segments = route_spec.split('/')
174
- route_segments.each_with_index { |segment, i|
175
- if segment.include?(':')
176
- vars << { :position => position_counter, :var => segment.gsub(':', '') }
177
- if i == route_segments.length-1 then
178
- regex_route = regex_route.sub(segment, '((?!(new\b|.*?\/))(\w|[-.~:@!$\'\(\)\*\+,;])*)')
179
- position_counter += 1
180
- else
181
- regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
182
- position_counter += 2
183
- end
184
- end
185
- }
186
- reg = Regexp.new("^#{regex_route}$")
187
- return reg, vars
188
- end
189
-
190
- # remove leading/trailing forward slashes
191
- def normalize_route(route_spec)
192
- return route_spec if route_spec.is_a?(Regexp)
193
-
194
- if route_spec.is_a?(String) then
195
- route_spec = route_spec[1, route_spec.length - 1] if route_spec[0, 1] == '/'
196
- route_spec = route_spec[0, route_spec.length - 1] if route_spec[route_spec.length - 1, 1] == '/'
197
- route_spec
198
- end
199
-
200
- route_spec
201
- end
202
-
203
- def normalize_hooks(hooks)
204
- hooks.each_pair { |k,v|
205
- unless v.is_a?(Array)
206
- hooks[k] = [v]
207
- end
208
- } if hooks
209
- end
210
-
211
- def build_regex_var_values(vars_info, match_data)
212
- var_values = {}
213
- vars_info.each { |vi|
214
- var_values[vi[:var]] = match_data[vi[:position]]
215
- }
216
- var_values
217
- end
218
-
219
- end
220
- end
@@ -1,25 +0,0 @@
1
- module Pakyow
2
- class Static
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- if is_static?(env)
9
- Pakyow.app.response = Rack::Response.new
10
-
11
- catch(:halt) do
12
- Pakyow.app.send_file!(File.join(Configuration::Base.app.public_dir, env['PATH_INFO']))
13
- end
14
- else
15
- @app.call(env)
16
- end
17
- end
18
-
19
- private
20
-
21
- def is_static?(env)
22
- env['PATH_INFO'] =~ /\.(.*)$/ && File.exists?(File.join(Configuration::Base.app.public_dir, env['PATH_INFO']))
23
- end
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- class ApplicationController
2
- include Pakyow::Helpers
3
-
4
- def index
5
- end
6
- end
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'pakyow'
3
-
4
- module PakyowApplication
5
- class Application < Pakyow::Application
6
- config.app.default_environment = :development
7
-
8
- configure(:development) do
9
- end
10
-
11
- routes do
12
- default :ApplicationController, :index
13
- end
14
-
15
- middleware do
16
- end
17
- end
18
- end