pakyow-core 0.6.1 → 0.6.3.1

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.
@@ -1,3 +1,21 @@
1
+ = 0.6.3 / 2011-09-13
2
+
3
+ * Fixes several load path issues
4
+ * Fixes gemspecs so gem can be built/used from anywhere
5
+ * Fixes inconsistency with with request.params having string and symbol keys
6
+ * Fixes loading of middleware when staging application (simplifies rackup)
7
+
8
+ = 0.6.2 / 2011-08-20
9
+
10
+ * Fixes issue running pakyow server on Windows
11
+ * Fixes several issues related to error handlers
12
+ * Fixes an issue when using alphanumeric ids in restful routes
13
+ * JRuby Support
14
+
15
+ = 0.6.1 / 2011-08-20
16
+
17
+ * Fixes gemspec problem
18
+
1
19
  = 0.6.0 / 2011-08-20
2
20
 
3
21
  * Initial gem release of 0.6.0 codebase
@@ -6,7 +6,11 @@ module Pakyow
6
6
  # Sets the path to the application file so it can be reloaded later.
7
7
  #
8
8
  def inherited(subclass)
9
- Pakyow::Configuration::App.application_path = caller[0].split(':')[0]
9
+ Pakyow::Configuration::App.application_path = parse_path_from_caller(caller[0])
10
+ end
11
+
12
+ def parse_path_from_caller(caller)
13
+ caller.match(/^(.+)(:?:\d+(:?:in `.+')?$)/)[1]
10
14
  end
11
15
 
12
16
  # Runs the application. Accepts the environment(s) to run, for example:
@@ -14,15 +18,10 @@ module Pakyow
14
18
  # run([:development, :staging])
15
19
  #
16
20
  def run(*args)
17
- self.load_config args.empty? || args.first.nil? ? [Configuration::Base.app.default_environment] : args
18
21
  return if running?
19
-
20
22
  @running = true
21
23
 
22
- builder = Rack::Builder.new
23
- builder.use(Rack::MethodOverride)
24
- builder.instance_eval(&self.middleware_proc) if self.middleware_proc
25
- builder.run(self.new)
24
+ self.builder.run(self.prepare(*args))
26
25
  detect_handler.run(builder, :Host => Pakyow::Configuration::Base.server.host, :Port => Pakyow::Configuration::Base.server.port)
27
26
  end
28
27
 
@@ -30,12 +29,18 @@ module Pakyow
30
29
  # not started. Accepts the same arguments as #run.
31
30
  #
32
31
  def stage(*args)
33
- load_config args.empty? || args.first.nil? ? [Configuration::Base.app.default_environment] : args
34
32
  return if staged?
35
-
36
- app = self.new
37
-
38
33
  @staged = true
34
+
35
+ prepare(*args)
36
+ end
37
+
38
+ def builder
39
+ @builder ||= Rack::Builder.new
40
+ end
41
+
42
+ def prepared?
43
+ @prepared
39
44
  end
40
45
 
41
46
  # Returns true if the application is running.
@@ -100,6 +105,21 @@ module Pakyow
100
105
 
101
106
  protected
102
107
 
108
+ # Prepares the application for running or staging and returns an instance
109
+ # of the application.
110
+ def prepare(*args)
111
+ self.load_config args.empty? || args.first.nil? ? [Configuration::Base.app.default_environment] : args
112
+ return if prepared?
113
+
114
+ self.builder.use(Rack::MethodOverride)
115
+ self.builder.instance_eval(&self.middleware_proc) if self.middleware_proc
116
+
117
+ @prepared = true
118
+
119
+ $:.unshift(Dir.pwd) unless $:.include? Dir.pwd
120
+ return self.new
121
+ end
122
+
103
123
  def load_config(args)
104
124
  if self.configurations
105
125
  args << Configuration::Base.app.default_environment if args.empty?
@@ -178,9 +198,8 @@ module Pakyow
178
198
  self.request.format = ((format && (format[format.length - 1, 1] == '/')) ? format[0, format.length - 1] : format)
179
199
  catch(:halt) do
180
200
  rhs, packet = @route_store.get_block(just_the_path, self.request.method)
181
- packet[:vars].each_pair { |var, val|
182
- request.params[var] = val
183
- }
201
+ request.params.merge!(HashUtils.strhash(packet[:vars]))
202
+
184
203
  self.request.route_spec = packet[:data][:route_spec] if packet[:data]
185
204
  restful_info = packet[:data][:restful] if packet[:data]
186
205
  self.request.restful = restful_info
@@ -210,10 +229,11 @@ module Pakyow
210
229
  Log.enter "[500] #{error}\n"
211
230
  Log.enter error.backtrace.join("\n") + "\n\n"
212
231
 
213
- self.response = Rack::Response.new
232
+ # self.response = Rack::Response.new
214
233
 
215
234
  if Configuration::Base.app.errors_in_browser
216
235
  # Show errors in browser
236
+ self.response.body = []
217
237
  self.response.body << "<h4>#{CGI.escapeHTML(error.to_s)}</h4>"
218
238
  self.response.body << error.backtrace.join("<br />")
219
239
  end
@@ -322,7 +342,7 @@ module Pakyow
322
342
  end
323
343
 
324
344
  # Create the route
325
- register_route(action_url, nil, opts[:method], controller, opts[:action], true)
345
+ register_route(action_url, nil, opts[:method], controller, opts[:action], :restful)
326
346
 
327
347
  # Store url for later use (currently used by Binder#action)
328
348
  @restful_routes[model][opts[:action]] = action_url if model
@@ -333,13 +353,13 @@ module Pakyow
333
353
  end
334
354
 
335
355
  @@restful_actions = [
336
- { :action => :index, :method => :get },
356
+ { :action => :edit, :method => :get, :url_suffix => 'edit/:id' },
337
357
  { :action => :show, :method => :get, :url_suffix => ':id' },
338
358
  { :action => :new, :method => :get, :url_suffix => 'new' },
339
- { :action => :create, :method => :post },
340
- { :action => :edit, :method => :get, :url_suffix => 'edit/:id' },
341
359
  { :action => :update, :method => :put, :url_suffix => ':id' },
342
- { :action => :delete, :method => :delete, :url_suffix => ':id' }
360
+ { :action => :delete, :method => :delete, :url_suffix => ':id' },
361
+ { :action => :index, :method => :get },
362
+ { :action => :create, :method => :post }
343
363
  ]
344
364
 
345
365
  protected
@@ -350,7 +370,7 @@ module Pakyow
350
370
 
351
371
  # Handles route registration.
352
372
  #
353
- def register_route(route, block, method, controller = nil, action = nil, restful = false)
373
+ def register_route(route, block, method, controller = nil, action = nil, type = :user)
354
374
  if controller
355
375
  controller = eval(controller.to_s)
356
376
  action ||= Configuration::Base.app.default_action
@@ -364,8 +384,8 @@ module Pakyow
364
384
  }
365
385
  end
366
386
 
367
- data = {:route_spec=>route}
368
- if restful
387
+ data = {:route_type=>type, :route_spec=>route}
388
+ if type == :restful
369
389
  data[:restful] = {:restful_action=>action}
370
390
  end
371
391
  @route_store.add_route(route, block, method, data)
@@ -400,11 +420,13 @@ module Pakyow
400
420
  return unless handler = self.class.error_handlers[code]
401
421
 
402
422
  if handler.is_a? Proc
403
- handler.call
423
+ Pakyow.app.instance_eval(&handler)
404
424
  else
405
425
  c = eval(handler[:controller].to_s).new
406
426
  c.send(handler[:action])
407
427
  end
428
+
429
+ self.response.body = [self.presenter.content]
408
430
  end
409
431
 
410
432
  def set_cookies
@@ -21,9 +21,8 @@ module Pakyow
21
21
  klass.instance_variables.each do |var|
22
22
  # Assumes application_path shouldn't be reset, since it's only set
23
23
  # once when Pakyow::Application is inherited.
24
- next if var == '@application_path'
25
-
26
- klass.send("#{var.gsub('@', '')}=", nil)
24
+ next if var.to_sym == :'@application_path'
25
+ klass.send("#{var.to_s.gsub('@', '')}=", nil)
27
26
  end
28
27
  end
29
28
  end
@@ -18,20 +18,29 @@ module Pakyow
18
18
 
19
19
  def add_route(route_spec, block, method, data)
20
20
  route_spec = normalize_route(route_spec)
21
- route_to_match, vars = extract_route_vars(route_spec)
22
- if route_to_match.class == String
21
+ route_to_match, vars = build_route_matcher(route_spec, data)
22
+
23
+ if route_to_match.is_a?(String)
23
24
  @store[:string][method][route_to_match]={:block => block,
24
25
  :order => @order,
25
26
  :data => data}
26
27
  @order = @order + 1
27
- elsif route_to_match.class == Regexp
28
+ elsif route_to_match.is_a?(Regexp)
28
29
  @store[:regex][method] << {:regex => route_to_match,
29
30
  :block => block,
30
31
  :order => @order,
31
32
  :vars => vars,
32
33
  :data => data}
33
34
  @order = @order + 1
35
+ else
36
+ if Configuration::Base.app.dev_mode == true
37
+ Log.warn("Unsupported route spec class. (#{route_spec.class})")
38
+ else
39
+ Log.warn("Unsupported route spec class. (#{route_spec.class})")
40
+ raise "Unsupported route spec class. (#{route_spec.class})"
41
+ end
34
42
  end
43
+
35
44
  end
36
45
 
37
46
  # returns block, {:vars=>{:var=>matched_value, ...}, :data=>data}
@@ -74,34 +83,80 @@ module Pakyow
74
83
  private
75
84
 
76
85
  # Returns a regex and an array of variable info
77
- def extract_route_vars(route_spec)
86
+ def build_route_matcher(route_spec, data)
78
87
  return route_spec, [] if route_spec.is_a?(Regexp)
79
88
 
80
- unless route_spec[0,1] == ':' || route_spec.index('/:')
81
- return route_spec, []
89
+ if route_spec.is_a?(String)
90
+ # check for vars
91
+ return route_spec, [] unless route_spec[0,1] == ':' || route_spec.index('/:')
92
+ # we have vars
93
+ if data[:route_type] == :user
94
+ return build_user_route_matcher(route_spec)
95
+ elsif data[:route_type] == :restful
96
+ return build_restful_route_matcher(route_spec, data)
97
+ else
98
+ raise "Unknown route type. (#{data[:route_type]})"
99
+ end
82
100
  end
83
101
 
102
+ return route_spec, []
103
+ end
104
+
105
+ def build_user_route_matcher(route_spec)
84
106
  vars = []
85
- position_counter = 0
107
+ position_counter = 1
86
108
  regex_route = route_spec
87
- route_spec.split('/').each_with_index do |segment, i|
109
+ route_segments = route_spec.split('/')
110
+ route_segments.each_with_index { |segment, i|
88
111
  if segment.include?(':')
89
- position_counter += 1
90
- vars << { :position => position_counter, :var => segment.gsub(':', '').to_sym }
91
- regex_route = regex_route.gsub(segment, '([^new/]+)')
112
+ vars << { :position => position_counter, :var => segment.gsub(':', '') }
113
+ if i == route_segments.length-1 then
114
+ regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
115
+ position_counter += 2
116
+ else
117
+ regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
118
+ position_counter += 2
119
+ end
92
120
  end
93
- end
94
-
121
+ }
95
122
  reg = Regexp.new("^#{regex_route}$")
123
+ return reg, vars
124
+ end
125
+
126
+ def build_restful_route_matcher(route_spec, data)
127
+ build_user_route_matcher(route_spec) unless data[:restful][:restful_action] == :show
96
128
 
129
+ #special case for restful show route, can't match 'new' on last var
130
+ vars = []
131
+ position_counter = 1
132
+ regex_route = route_spec
133
+ route_segments = route_spec.split('/')
134
+ route_segments.each_with_index { |segment, i|
135
+ if segment.include?(':')
136
+ vars << { :position => position_counter, :var => segment.gsub(':', '') }
137
+ if i == route_segments.length-1 then
138
+ regex_route = regex_route.sub(segment, '((?!(new\b|.*?\/))(\w|[-.~:@!$\'\(\)\*\+,;])*)')
139
+ position_counter += 1
140
+ else
141
+ regex_route = regex_route.sub(segment, '((\w|[-.~:@!$\'\(\)\*\+,;])*)')
142
+ position_counter += 2
143
+ end
144
+ end
145
+ }
146
+ reg = Regexp.new("^#{regex_route}$")
97
147
  return reg, vars
98
148
  end
99
149
 
100
150
  # remove leading/trailing forward slashes
101
151
  def normalize_route(route_spec)
102
152
  return route_spec if route_spec.is_a?(Regexp)
103
- route_spec = route_spec[1, route_spec.length - 1] if route_spec[0, 1] == '/'
104
- route_spec = route_spec[0, route_spec.length - 1] if route_spec[route_spec.length - 1, 1] == '/'
153
+
154
+ if route_spec.is_a?(String) then
155
+ route_spec = route_spec[1, route_spec.length - 1] if route_spec[0, 1] == '/'
156
+ route_spec = route_spec[0, route_spec.length - 1] if route_spec[route_spec.length - 1, 1] == '/'
157
+ route_spec
158
+ end
159
+
105
160
  route_spec
106
161
  end
107
162
 
@@ -1,10 +1,4 @@
1
- require 'config/application'
2
- PakyowApplication::Application.stage(:development)
1
+ env = ENV['RACK_ENV'] || 'production'
3
2
 
4
- app = Rack::Builder.new do
5
- # Needed for Pakyow to work
6
- use Rack::MethodOverride
7
- run PakyowApplication::Application.new
8
- end.to_app
9
-
10
- run(app)
3
+ require File.expand_path('../config/application', __FILE__)
4
+ run PakyowApplication::Application.stage(env)
@@ -1,5 +1,5 @@
1
1
  env = ARGV[1] || 'development'
2
2
  env = env.split('=')[1] || env
3
3
 
4
- require 'config/application'
4
+ require File.expand_path('../config/application', __FILE__)
5
5
  PakyowApplication::Application.stage(env.to_sym)
metadata CHANGED
@@ -1,21 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 113
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
+ - 3
9
10
  - 1
10
- version: 0.6.1
11
+ version: 0.6.3.1
11
12
  platform: ruby
12
13
  authors:
13
14
  - Bryan Powell
15
+ - Bret Young
14
16
  autorequire:
15
17
  bindir: pakyow-core/bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-08-20 00:00:00 Z
20
+ date: 2011-09-13 00:00:00 -05:00
21
+ default_executable:
19
22
  dependencies:
20
23
  - !ruby/object:Gem::Dependency
21
24
  name: rack
@@ -23,13 +26,13 @@ dependencies:
23
26
  requirement: &id001 !ruby/object:Gem::Requirement
24
27
  none: false
25
28
  requirements:
26
- - - ">="
29
+ - - ~>
27
30
  - !ruby/object:Gem::Version
28
- hash: 11
31
+ hash: 9
29
32
  segments:
30
33
  - 1
31
- - 2
32
- version: "1.2"
34
+ - 3
35
+ version: "1.3"
33
36
  type: :runtime
34
37
  version_requirements: *id001
35
38
  description: pakyow-core
@@ -65,7 +68,6 @@ files:
65
68
  - pakyow-core/lib/generators/pakyow/app/templates/app/views/pakyow.html
66
69
  - pakyow-core/lib/generators/pakyow/app/templates/config/application.rb
67
70
  - pakyow-core/lib/generators/pakyow/app/templates/config.ru
68
- - pakyow-core/lib/generators/pakyow/app/templates/logs/requests.log
69
71
  - pakyow-core/lib/generators/pakyow/app/templates/public/favicon.ico
70
72
  - pakyow-core/lib/generators/pakyow/app/templates/rakefile
71
73
  - pakyow-core/lib/generators/pakyow/app/templates/README
@@ -74,6 +76,7 @@ files:
74
76
  - pakyow-core/lib/utils/hash.rb
75
77
  - pakyow-core/lib/utils/string.rb
76
78
  - pakyow-core/bin/pakyow
79
+ has_rdoc: true
77
80
  homepage: http://pakyow.com
78
81
  licenses: []
79
82
 
@@ -105,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
108
  requirements: []
106
109
 
107
110
  rubyforge_project: pakyow-core
108
- rubygems_version: 1.8.8
111
+ rubygems_version: 1.6.2
109
112
  signing_key:
110
113
  specification_version: 3
111
114
  summary: pakyow-core