grippy-doozer 0.1.3 → 0.1.4

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.
Files changed (51) hide show
  1. data/VERSION +1 -1
  2. data/doozer.gemspec +40 -3
  3. data/lib/doozer.rb +6 -1
  4. data/lib/doozer/app.rb +28 -19
  5. data/lib/doozer/configs.rb +18 -12
  6. data/lib/doozer/controller.rb +2 -2
  7. data/lib/doozer/exceptions.rb +12 -0
  8. data/lib/doozer/initializer.rb +8 -6
  9. data/lib/doozer/logger.rb +2 -1
  10. data/lib/doozer/partial.rb +3 -3
  11. data/lib/doozer/rackup/test.rb +2 -1
  12. data/lib/doozer/redirect.rb +1 -1
  13. data/lib/doozer/route.rb +34 -6
  14. data/lib/doozer/scripts/cluster.rb +9 -10
  15. data/lib/doozer/version.rb +1 -1
  16. data/lib/doozer/view_helpers.rb +100 -12
  17. data/lib/generator/generator.rb +0 -2
  18. data/templates/skeleton/config/environment.rb +1 -1
  19. data/templates/skeleton/config/routes.rb +2 -2
  20. data/test/doozer_test.rb +1 -1
  21. data/test/project/Rakefile +3 -0
  22. data/test/project/app/controllers/application_controller.rb +2 -0
  23. data/test/project/app/controllers/index_controller.rb +7 -0
  24. data/test/project/app/helpers/application_helper.rb +17 -0
  25. data/test/project/app/views/global/_header.html.erb +7 -0
  26. data/test/project/app/views/global/_navigation.html.erb +6 -0
  27. data/test/project/app/views/index/index.html.erb +108 -0
  28. data/test/project/app/views/layouts/default.html.erb +23 -0
  29. data/test/project/config/app.yml +31 -0
  30. data/test/project/config/database.yml +25 -0
  31. data/test/project/config/environment.rb +11 -0
  32. data/test/project/config/rack.rb +30 -0
  33. data/test/project/config/routes.rb +72 -0
  34. data/test/project/script/cluster +6 -0
  35. data/test/project/script/console +15 -0
  36. data/test/project/script/migrate +6 -0
  37. data/test/project/script/task +6 -0
  38. data/test/project/script/test +6 -0
  39. data/test/project/static/404.html +16 -0
  40. data/test/project/static/500.html +16 -0
  41. data/test/project/static/css/style.css +32 -0
  42. data/test/project/static/favicon.ico +0 -0
  43. data/test/project/static/js/application.js +1 -0
  44. data/test/project/static/js/jquery-1.3.min.js +19 -0
  45. data/test/project/static/robots.txt +5 -0
  46. data/test/project/test/fixtures/setup.rb +6 -0
  47. data/test/project/test/setup.rb +33 -0
  48. data/test/routing_test.rb +66 -0
  49. data/test/test_helper.rb +18 -2
  50. metadata +40 -3
  51. data/lib/doozer/README.rb +0 -40
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/doozer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{doozer}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["grippy"]
12
- s.date = %q{2009-08-11}
12
+ s.date = %q{2009-08-14}
13
13
  s.default_executable = %q{doozer}
14
14
  s.description = %q{This GEM provides a small, barebones framework for creating MVC Rack applications.}
15
15
  s.email = %q{gmelton@whorde.com}
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
28
28
  "bin/doozer",
29
29
  "doozer.gemspec",
30
30
  "lib/doozer.rb",
31
- "lib/doozer/README.rb",
32
31
  "lib/doozer/active_support/array.rb",
33
32
  "lib/doozer/active_support/class.rb",
34
33
  "lib/doozer/active_support/date_time.rb",
@@ -37,6 +36,7 @@ Gem::Specification.new do |s|
37
36
  "lib/doozer/app.rb",
38
37
  "lib/doozer/configs.rb",
39
38
  "lib/doozer/controller.rb",
39
+ "lib/doozer/exceptions.rb",
40
40
  "lib/doozer/extend.rb",
41
41
  "lib/doozer/initializer.rb",
42
42
  "lib/doozer/lib.rb",
@@ -91,6 +91,34 @@ Gem::Specification.new do |s|
91
91
  "templates/skeleton/test/fixtures/setup.rb",
92
92
  "templates/skeleton/test/setup.rb",
93
93
  "test/doozer_test.rb",
94
+ "test/project/Rakefile",
95
+ "test/project/app/controllers/application_controller.rb",
96
+ "test/project/app/controllers/index_controller.rb",
97
+ "test/project/app/helpers/application_helper.rb",
98
+ "test/project/app/views/global/_header.html.erb",
99
+ "test/project/app/views/global/_navigation.html.erb",
100
+ "test/project/app/views/index/index.html.erb",
101
+ "test/project/app/views/layouts/default.html.erb",
102
+ "test/project/config/app.yml",
103
+ "test/project/config/database.yml",
104
+ "test/project/config/environment.rb",
105
+ "test/project/config/rack.rb",
106
+ "test/project/config/routes.rb",
107
+ "test/project/script/cluster",
108
+ "test/project/script/console",
109
+ "test/project/script/migrate",
110
+ "test/project/script/task",
111
+ "test/project/script/test",
112
+ "test/project/static/404.html",
113
+ "test/project/static/500.html",
114
+ "test/project/static/css/style.css",
115
+ "test/project/static/favicon.ico",
116
+ "test/project/static/js/application.js",
117
+ "test/project/static/js/jquery-1.3.min.js",
118
+ "test/project/static/robots.txt",
119
+ "test/project/test/fixtures/setup.rb",
120
+ "test/project/test/setup.rb",
121
+ "test/routing_test.rb",
94
122
  "test/test_helper.rb"
95
123
  ]
96
124
  s.has_rdoc = true
@@ -101,6 +129,15 @@ Gem::Specification.new do |s|
101
129
  s.summary = %q{A little MVC framework for Rack applications.}
102
130
  s.test_files = [
103
131
  "test/doozer_test.rb",
132
+ "test/project/app/controllers/application_controller.rb",
133
+ "test/project/app/controllers/index_controller.rb",
134
+ "test/project/app/helpers/application_helper.rb",
135
+ "test/project/config/environment.rb",
136
+ "test/project/config/rack.rb",
137
+ "test/project/config/routes.rb",
138
+ "test/project/test/fixtures/setup.rb",
139
+ "test/project/test/setup.rb",
140
+ "test/routing_test.rb",
104
141
  "test/test_helper.rb"
105
142
  ]
106
143
 
data/lib/doozer.rb CHANGED
@@ -20,8 +20,13 @@ module Doozer
20
20
  end
21
21
 
22
22
  module Util
23
- autoload :Logger, "doozer/logger"
23
+ autoload :Logger, "doozer/logger"
24
24
  end
25
+
26
+ module Exceptions
27
+ autoload :Route, "doozer/exceptions"
28
+ end
29
+
25
30
  autoload :ViewHelpers, "doozer/view_helpers"
26
31
  autoload :Version, "doozer/version"
27
32
 
data/lib/doozer/app.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Doozer
2
2
  class App
3
- APP_PATH = Dir.pwd
4
3
  include Doozer::Util::Logger
5
4
  attr_accessor :options
6
5
 
@@ -108,6 +107,7 @@ module Doozer
108
107
  end
109
108
  end
110
109
 
110
+ # Load all application files for app/helpers/*, app/views/layouts/*, app/views/* and app/controllers/*
111
111
  def load_files
112
112
  # load models
113
113
  load_models
@@ -118,7 +118,7 @@ module Doozer
118
118
  @@errors={}
119
119
 
120
120
  # require helper files and include into Doozer::Partial
121
- helper_files = Dir.glob(File.join(APP_PATH,'app/helpers/*_helper.rb'))
121
+ helper_files = Dir.glob(File.join(app_path,'app/helpers/*_helper.rb'))
122
122
  helper_files.each {|f|
123
123
  require f
124
124
  key = f.split("helpers/")[1].gsub(/.rb/,'')
@@ -126,7 +126,7 @@ module Doozer
126
126
  }
127
127
 
128
128
  # cache contoller classes
129
- controller_files = Dir.glob(File.join(APP_PATH,'app/controllers/*_controller.rb'))
129
+ controller_files = Dir.glob(File.join(app_path,'app/controllers/*_controller.rb'))
130
130
  # we need to load the application_controller first since this might not be the first in the list...
131
131
  if controller_files.length > 0
132
132
  i=0
@@ -160,9 +160,9 @@ module Doozer
160
160
  }
161
161
 
162
162
  # cache layout erb's
163
- layout_files = Dir.glob(File.join(APP_PATH,'app/views/layouts/*.erb'))
163
+ layout_files = Dir.glob(File.join(app_path,'app/views/layouts/*.erb'))
164
164
  layout_files.each {|f|
165
- key = f.split("layouts/")[1].split(".html.erb")[0].gsub(/.xml.erb/, '_xml').gsub(/.json.erb/, '_json')
165
+ key = f.split("layouts/")[1].split(".html.erb")[0].gsub(/.xml.erb/, '_xml').gsub(/.json.erb/, '_json').gsub(/.js.erb/, '_js').gsub(/.rss.erb/, '_rss').gsub(/.atom.erb/, '_atom')
166
166
  results = []
167
167
  File.new(f, "r").each { |line| results << line }
168
168
  @@layouts[key.to_sym] = ERB.new(results.join(""))
@@ -171,7 +171,7 @@ module Doozer
171
171
  #lood 404 and 500 pages if they exist
172
172
  pnf = Doozer::Configs.page_not_found_url
173
173
  if pnf
174
- file = File.join(APP_PATH,"#{pnf}")
174
+ file = File.join(app_path,"#{pnf}")
175
175
  results = []
176
176
  File.new(file, "r").each { |line| results << line }
177
177
  @@errors[404] = results.join("")
@@ -180,7 +180,7 @@ module Doozer
180
180
  end
181
181
  ise = Doozer::Configs.internal_server_error_url
182
182
  if ise
183
- file = File.join(APP_PATH,"#{ise}")
183
+ file = File.join(app_path,"#{ise}")
184
184
  results = []
185
185
  File.new(file, "r").each { |line| results << line }
186
186
  @@errors[500] = results.join("")
@@ -190,7 +190,7 @@ module Doozer
190
190
 
191
191
  @@controllers.each_key { | key |
192
192
  # p key.inspect
193
- files = Dir.glob(File.join(APP_PATH,"app/views/#{key.to_s}/*.erb"))
193
+ files = Dir.glob(File.join(app_path,"app/views/#{key.to_s}/*.erb"))
194
194
  files.each { | f |
195
195
  #!!!don't cache partials here!!!
196
196
  view = f.split("#{key.to_s}/")[1].split(".erb")[0].gsub(/\./,'_')
@@ -205,18 +205,23 @@ module Doozer
205
205
  }
206
206
  }
207
207
  end
208
-
208
+
209
+ # Load application routes
209
210
  def load_routes
210
- require File.join(APP_PATH, 'config/routes')
211
+ require File.join(app_path, 'config/routes')
211
212
  end
212
-
213
+
214
+ # Load all application models in app/models
213
215
  def load_models
214
216
  printf "Loading models...\n"
215
- Dir.glob(File.join(APP_PATH,'app/models/*.rb')).each { | model |
217
+ Dir.glob(File.join(app_path,'app/models/*.rb')).each { | model |
216
218
  require model
217
219
  }
218
220
  end
219
-
221
+
222
+ # Loads the file watcher for all application files while in development mode-only.
223
+ #
224
+ # This allows you to edit files without restarting the app server to pickup new changes.
220
225
  def load_watcher
221
226
  require 'doozer/watcher'
222
227
 
@@ -224,12 +229,12 @@ module Doozer
224
229
  watcher = FileSystemWatcher.new()
225
230
 
226
231
  # watcher.addDirectory(File.join(File.dirname(__FILE__),'../doozer/'), "*.rb")
227
- watcher.addDirectory( APP_PATH + '/app/', "**/*")
228
- watcher.addDirectory( APP_PATH + '/app', "**/**/*")
229
- watcher.addDirectory( APP_PATH + '/config/', "*.*")
230
- watcher.addDirectory( APP_PATH + '/lib/', "*.*")
231
- watcher.addDirectory( APP_PATH + '/static/', "*.*")
232
- watcher.addDirectory( APP_PATH + '/static/', "**/**/*")
232
+ watcher.addDirectory( app_path + '/app/', "**/*")
233
+ watcher.addDirectory( app_path + '/app', "**/**/*")
234
+ watcher.addDirectory( app_path + '/config/', "*.*")
235
+ watcher.addDirectory( app_path + '/lib/', "*.*")
236
+ watcher.addDirectory( app_path + '/static/', "*.*")
237
+ watcher.addDirectory( app_path + '/static/', "**/**/*")
233
238
 
234
239
 
235
240
  watcher.sleepTime = 1
@@ -258,6 +263,10 @@ module Doozer
258
263
  return Object.const_get(@@controllers[key])
259
264
  end
260
265
 
266
+ def app_path
267
+ Doozer::Configs.app_path
268
+ end
269
+
261
270
  def self.controllers
262
271
  @@controllers
263
272
  end
@@ -6,18 +6,16 @@ module Doozer
6
6
 
7
7
  # This is the main Configs class which loads root/config/app.yml and root/config/database.yml
8
8
  #
9
- # It also provides a few helper methods like logger, env_path, base_url and app_name
9
+ # It also provides a few helper methods like logger, app_path, base_url and app_name
10
10
  class Configs
11
- APP_PATH = Dir.pwd
12
11
  @@possible_orm = [:active_record, :data_mapper, :sequel]
12
+ @@app_path = nil
13
13
 
14
- # Rack refers to production as deployment.
14
+ # Load all the config files for the application. Also instantiates a default application Logger.
15
15
  def self.load(rack_env)
16
- printf "APP_ROOT: #{APP_PATH}\n"
16
+ printf "Application path: #{app_path}\n"
17
17
  printf "Loading configs for #{rack_env}\n"
18
18
 
19
- # TODO: remove this and replace with APP_PATH
20
- @@env_path = Dir.pwd
21
19
  @@config = Config::CONFIG
22
20
  rack_env = (rack_env.kind_of? String) ? rack_env.to_sym : rack_env
23
21
  case rack_env
@@ -33,20 +31,20 @@ module Doozer
33
31
  if [:development, :test].include?(rack_env)
34
32
  @@logger = Logger.new(STDOUT)
35
33
  else
36
- @@logger = Logger.new("#{APP_PATH}/log/#{rack_env}.log")
34
+ @@logger = Logger.new("#{app_path}/log/#{rack_env}.log")
37
35
  end
38
36
 
39
37
  @@config[:rack_env] = rack_env
40
38
  # p ":rack_env set to #{@@config[:rack_env]}"
41
39
 
42
40
  begin
43
- @@config[:database] = Configs.symbolize_keys( YAML.load(File.read(File.join(APP_PATH,'config/database.yml'))) )
41
+ @@config[:database] = Configs.symbolize_keys( YAML.load(File.read(File.join(app_path,'config/database.yml'))) )
44
42
  rescue
45
43
  printf "--Failed to load config/database.yml \n"
46
44
  end
47
45
 
48
46
  begin
49
- @@config[:app] = Configs.symbolize_keys( YAML.load(File.read(File.join(APP_PATH,'config/app.yml'))) )
47
+ @@config[:app] = Configs.symbolize_keys( YAML.load(File.read(File.join(app_path,'config/app.yml'))) )
50
48
  rescue
51
49
  printf "--Failed to load config/app.yml\n"
52
50
  end
@@ -57,10 +55,18 @@ module Doozer
57
55
  @@logger
58
56
  end
59
57
 
58
+ # Hook for setting the application path.
59
+ #
60
+ # This allows the an application to be initialized from a different location then the project directory.
61
+ def self.set_app_path(path=nil)
62
+ @@app_path = path || Dir.pwd
63
+ end
64
+
60
65
  # This is the file path the app was loaded under. Dir.pwd moves to root in daemon mode so we cache this.
61
- def self.env_path
62
- @@env_path
63
- end
66
+ def self.app_path
67
+ set_app_path if @@app_path.nil?
68
+ return @@app_path
69
+ end
64
70
 
65
71
  # Take a hash and turn all the keys into symbols
66
72
  def self.symbolize_keys(hash=nil)
@@ -237,7 +237,7 @@ module Doozer
237
237
 
238
238
  # Method for setting metatags via Controllers.
239
239
  #
240
- # Pass an options hash to meta and all the keys are turned into metatags with the corresponding values.
240
+ # Pass an options hash to @view[:meta] and all the key/values are turned into metatags with the corresponding values. See Doozer::ViewHelpers#metatags for creating the metatags for view.
241
241
  #
242
242
  # Example: meta({:description=>'The awesome metatag description is awesome', :keywords=>'awesome, blog, of awesomeness'})
243
243
  def meta(opt={})
@@ -328,7 +328,7 @@ module Doozer
328
328
  elsif args.kind_of? ERB
329
329
  view = args
330
330
  end
331
- view = ERB.new("Missing view for controller#action") if view.nil?
331
+ view = ERB.new("Missing view for #{@route.view_path}") if view.nil?
332
332
  @render_args[:view] = view
333
333
  end
334
334
  end
@@ -0,0 +1,12 @@
1
+ module Doozer
2
+ module Exceptions
3
+
4
+ # Runtime Error for handling Route intialization errors.
5
+ class Route < RuntimeError
6
+ def initialize(message)
7
+ @message=message
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -14,9 +14,11 @@ module Doozer
14
14
  @@before_rackup = []
15
15
 
16
16
  # env - :development, :deployment, or :test
17
- def self.boot(env)
17
+ # app_path - optional path which overrides where the application is loaded from. Defaults to the Dir.pwd of script loading this file
18
+ def self.boot(env, app_path=nil)
18
19
  #--load configs
19
20
  require 'doozer/configs'
21
+ Doozer::Configs.set_app_path(app_path)
20
22
  Doozer::Configs.load(env)
21
23
 
22
24
  #--load orm
@@ -64,16 +66,16 @@ module Doozer
64
66
  # end
65
67
  def self.environment
66
68
  begin
67
- require "#{Dir.pwd}/config/environment"
69
+ require "#{Doozer::Configs.app_path}/config/environment"
68
70
  rescue => e
69
71
  Doozer::Configs.logger.error(e)
70
72
  end
71
73
  end
72
74
 
73
-
74
- def self.console(env)
75
- self.boot(env)
76
- app = Doozer::App.new(env)
75
+ # TODO: test this again
76
+ def self.console(env, app_path=nil)
77
+ self.boot(env, app_path=app_path)
78
+ app = Doozer::App.new(args={})
77
79
  end
78
80
 
79
81
  # Primary hook for extending/overriding ORM. Code block is pushed onto an array which allows for multiple hooks throughtout different files.
data/lib/doozer/logger.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Doozer
2
2
  module Util
3
3
  module Logger
4
-
4
+
5
+ # Helper function for returning logger.
5
6
  def logger
6
7
  Doozer::Configs.logger
7
8
  end
@@ -24,7 +24,7 @@ module Doozer
24
24
  include Doozer::Util::Logger
25
25
  include Doozer::ViewHelpers
26
26
 
27
- APP_PATH = Dir.pwd
27
+ # APP_PATH = Dir.pwd
28
28
  @@partials={}
29
29
 
30
30
  def initialize(erb, locals, route)
@@ -74,14 +74,14 @@ module Doozer
74
74
 
75
75
  # Load and cache partial ERB template with the given file_name.
76
76
  def self.load_partial(name)
77
- file = File.join(APP_PATH,"/app/views/#{name}.html.erb")
77
+ file = File.join(Doozer::Configs.app_path,"app/views/#{name}.html.erb")
78
78
  results = []
79
79
  begin
80
80
  File.new(file, "r").each { |line| results << line }
81
81
  # TODO: throw error if doesn't exist
82
82
  @@partials[name] = ERB.new(results.join(""))
83
83
  rescue
84
- p "sorry couldn't load partial #{name} (#{file})"
84
+ printf "sorry couldn't load partial #{name} (#{file}) \n"
85
85
  end
86
86
  end
87
87
 
@@ -3,7 +3,8 @@
3
3
  since rackup doesn't call Rackup::Builder in test (in rackup this is 'none') mode
4
4
 
5
5
  """
6
- config = 'doozer/rackup/server.ru'
6
+
7
+ config = File.expand_path(File.join(File.dirname(__FILE__), 'server.ru'))
7
8
  env = :test
8
9
  cfgfile = File.read(config)
9
10
  if cfgfile[/^#\\(.*)/]
@@ -1,5 +1,5 @@
1
1
  module Doozer
2
- class Redirect < Exception
2
+ class Redirect < RuntimeError
3
3
  attr_accessor :url
4
4
  attr_reader :status
5
5
 
data/lib/doozer/route.rb CHANGED
@@ -2,6 +2,9 @@ require 'doozer/app'
2
2
 
3
3
  module Doozer
4
4
  module Routing
5
+
6
+
7
+ # Route manager for drawing and adding routes.
5
8
  class Routes
6
9
  @@parts=[] # stored as [route.name, route.path]
7
10
  @@dict={} # route hash
@@ -22,6 +25,9 @@ module Doozer
22
25
  printf "Routes drawn and sorted...\n"
23
26
  # @@parts.each { | i | p i[1] }
24
27
  end
28
+
29
+
30
+ # An empty path defaults to a path of '/'
25
31
  def self.add(name=nil, path=nil, args=nil)
26
32
  # p name
27
33
  # p path
@@ -33,6 +39,11 @@ module Doozer
33
39
  for format in formats
34
40
  args.delete(:formats)
35
41
  if name != :magic
42
+ path = '/' if path == ''
43
+
44
+ raise Doozer::Exceptions::Route.new("Route name must be a symbol. #{name} given.") if not name.kind_of? Symbol
45
+ raise Doozer::Exceptions::Route.new("Route already exists with the name of #{name}.") if @@dict[name]
46
+ @@parts.each { |p| raise Doozer::Exceptions::Route.new("Route already defined with a path of '#{path}'") if p[1] == path }
36
47
  parts = [name, path, args]
37
48
  # p parts.inspect
38
49
  args[:format] = format
@@ -48,6 +59,7 @@ module Doozer
48
59
  end
49
60
  end
50
61
 
62
+ # sets up default formats to initialize a mapped route
51
63
  def self.init_formats(args)
52
64
  formats = args[:formats]
53
65
  formats = [] if formats.nil?
@@ -56,11 +68,13 @@ module Doozer
56
68
  return args
57
69
  end
58
70
 
71
+ # return a route by name
59
72
  def self.get_by_name(name)
60
73
  # p @@dict.inspect
61
74
  return @@dict[name]
62
75
  end
63
-
76
+
77
+ # return the route which matches the request path
64
78
  def self.match(path)
65
79
  # p path
66
80
  # p @@cache.inspect
@@ -76,6 +90,7 @@ module Doozer
76
90
  return nil
77
91
  end
78
92
 
93
+ # caches the request path and with the route.name
79
94
  def self.cache_request_path(route,path)
80
95
  # p "route cache request path"
81
96
  @@cache[path] = route.name
@@ -177,6 +192,10 @@ module Doozer
177
192
  attr_accessor :name, :path, :controller, :action,
178
193
  :layout, :status, :content_type, :tokens,
179
194
  :grouping, :app, :format, :view, :view_path
195
+
196
+
197
+ # Initializes a route with the following parameters
198
+ # route - [:name, 'path', {args}]
180
199
  def initialize(route)
181
200
  #p "Doozer::Route#new: #{route}"
182
201
  args = route[2]
@@ -207,13 +226,14 @@ module Doozer
207
226
  path = '/' if path == ''
208
227
  @path = (@format == :html) ? path : "#{path}.#{format}"
209
228
  @name = (@format == :html) ? route[0] : "#{route[0]}_#{format.to_s}".to_sym
210
- @layout = :none if @format != :html and @layout == 'default'
229
+ @layout = "default_#{@format.to_s}".to_sym if @format != :html and @layout == 'default'
211
230
 
212
231
  @view = "#{@action}_#{@format.to_s}"
213
232
  @view_path = "#{@controller}/#{@action}.#{@format.to_s}.erb"
214
233
  regify()
215
234
  end
216
-
235
+
236
+ # Creates the Regex grouping for matching and parsing route tokens
217
237
  def regify
218
238
  if (@path.index('/'))
219
239
  grouping = []
@@ -224,12 +244,13 @@ module Doozer
224
244
  # part = '(?P<'+token+'>.)'
225
245
  # part = '(\.*)'
226
246
  # part = '(\w*)'
227
- part = '([a-zA-Z0-9,-.%]*)' # this picks up all allowable route tokens (a-zA-Z0-9,-.%)
247
+ part = '([a-zA-Z0-9,-.%_~;]*)' # this picks up all allowable route tokens (a-zA-Z0-9,-.%)
228
248
  @tokens.push(token)
229
249
  end
230
250
  grouping.push(part)
231
251
  end
232
252
  out = "^#{grouping.join('/')}"
253
+ out += ".#{@format.to_s}" if @format != :html # we need to include the
233
254
  @grouping = Regexp.compile(out)
234
255
  else
235
256
  #handle default index route
@@ -237,21 +258,28 @@ module Doozer
237
258
  end
238
259
  end
239
260
 
261
+ # Matches a request path against a route.path if a direct match or route.grouping
240
262
  def match(path)
241
263
  # p "#{path} vs #{@path}"
242
264
  # p path =~ @grouping
243
- #short-circut for root
265
+ # short-circut for root
244
266
  return false if path == '/' and @path != '/' #handles root condition
267
+ # short-circut for exact match with no tokens
268
+ return true if path == @path
269
+ # test for tokens
245
270
  pass=(path =~ @grouping) == 0 ? true : false
246
271
  # p @tokens.inspect if pass
247
272
  if @tokens.empty?; pass=false if @path != path; end #handles root condition '/'
248
273
  pass=false if path.split('/').length != @path.split('/').length #handles the root condition /:token
249
274
  return pass
250
275
  end
251
-
276
+
277
+ # Parses route tokens and creates a hash of extra params
252
278
  def extra_params(path)
253
279
  hashish = {}
254
280
  params = @grouping.match(path)
281
+ # make sure to remove the format from the last token
282
+ @tokens.last.gsub!(Regexp.compile("\.#{@format.to_s}$"), '') if @format != :html if not @tokens.empty?
255
283
  i = 1
256
284
  for token in @tokens
257
285
  hashish[token.to_sym] = params[i]