mack 0.8.0.101 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGELOG +29 -0
  2. data/bin/mackery-console +6 -5
  3. data/bin/mackery-server +23 -7
  4. data/lib/mack.rb +0 -3
  5. data/lib/mack/application.rb +161 -0
  6. data/lib/mack/assets/asset_helpers.rb +8 -0
  7. data/lib/mack/assets/assets_mgr.rb +0 -10
  8. data/lib/mack/boot/app.rb +46 -0
  9. data/lib/mack/boot/assets.rb +10 -0
  10. data/lib/mack/boot/configuration.rb +87 -0
  11. data/lib/mack/boot/console.rb +36 -0
  12. data/lib/mack/boot/core.rb +21 -0
  13. data/lib/mack/boot/environment.rb +22 -0
  14. data/lib/mack/boot/extensions.rb +13 -0
  15. data/lib/mack/boot/gem_tasks.rb +20 -0
  16. data/lib/mack/boot/gems.rb +18 -0
  17. data/lib/mack/boot/hello.rb +11 -0
  18. data/lib/mack/{initialization → boot}/helpers.rb +8 -3
  19. data/lib/mack/boot/initializers.rb +17 -0
  20. data/lib/mack/boot/lib.rb +19 -0
  21. data/lib/mack/{initialization → boot}/logging.rb +16 -9
  22. data/lib/mack/{initialization → boot}/logging/basic_layout.rb +0 -0
  23. data/lib/mack/{initialization → boot}/logging/color_layout.rb +1 -1
  24. data/lib/mack/{initialization → boot}/logging/filter.rb +0 -0
  25. data/lib/mack/boot/paths.rb +234 -0
  26. data/lib/mack/boot/plugins.rb +26 -0
  27. data/lib/mack/boot/portlets.rb +20 -0
  28. data/lib/mack/boot/routes.rb +15 -0
  29. data/lib/mack/boot/version.rb +7 -0
  30. data/lib/mack/controller/request.rb +5 -2
  31. data/lib/mack/controller/uploaded_file.rb +4 -0
  32. data/lib/mack/core_extensions/kernel.rb +26 -0
  33. data/lib/mack/core_extensions/object.rb +16 -0
  34. data/lib/mack/generators/mack_application_generator/manifest.yml +5 -3
  35. data/lib/mack/generators/mack_application_generator/templates/config/initializers/portlets.rb.template +9 -0
  36. data/lib/mack/generators/mack_application_generator/templates/public/stylesheets/scaffold.css.template +4 -0
  37. data/lib/mack/generators/portlet_generator/portlet_generator.rb +2 -0
  38. data/lib/mack/generators/portlet_generator/templates/README.template +3 -0
  39. data/lib/mack/generators/portlet_generator/templates/portlet_config/portlet.spec.template +28 -0
  40. data/lib/mack/portlets/manager.rb +27 -0
  41. data/lib/mack/portlets/portlet.rb +93 -0
  42. data/lib/mack/portlets/unpacker.rb +34 -0
  43. data/lib/mack/rendering/engine/erubis.rb +2 -2
  44. data/lib/mack/rendering/type/file_base.rb +8 -4
  45. data/lib/mack/rendering/type/public.rb +4 -2
  46. data/lib/mack/routing/resource_proxy.rb +30 -4
  47. data/lib/mack/routing/route_map.rb +28 -15
  48. data/lib/mack/routing/route_object.rb +57 -24
  49. data/lib/mack/routing/urls.rb +12 -2
  50. data/lib/mack/runner.rb +6 -154
  51. data/lib/mack/sessions/cookie_session_store.rb +2 -1
  52. data/lib/mack/tasks/mack_dump_tasks.rake +62 -18
  53. data/lib/mack/tasks/mack_tasks.rake +1 -15
  54. data/lib/mack/tasks/portlet_tasks.rake +33 -0
  55. data/lib/mack/tasks/rake_rules.rake +6 -0
  56. data/lib/mack/tasks/test_tasks.rake +4 -6
  57. data/lib/mack/testing/helpers.rb +12 -4
  58. data/lib/mack/utils/server.rb +7 -1
  59. data/lib/mack/utils/static.rb +19 -0
  60. data/lib/mack/version.rb +1 -1
  61. data/lib/mack/view_helpers/all_helpers.rb +0 -8
  62. data/lib/mack/view_helpers/date_time_helpers.rb +18 -12
  63. data/lib/mack/view_helpers/form_helpers.rb +9 -0
  64. data/lib/mack/view_helpers/html_helpers.rb +18 -7
  65. data/lib/mack/view_helpers/link_helpers.rb +2 -1
  66. data/lib/mack/view_helpers/object_helpers.rb +1 -1
  67. data/lib/mack_app.rb +26 -14
  68. data/lib/mack_core.rb +50 -39
  69. data/lib/mack_tasks.rb +46 -19
  70. metadata +37 -18
  71. data/lib/mack/initialization/application.rb +0 -53
  72. data/lib/mack/initialization/boot_loader.rb +0 -72
  73. data/lib/mack/initialization/configuration.rb +0 -101
  74. data/lib/mack/initialization/console.rb +0 -29
  75. data/lib/mack/initialization/environment.rb +0 -16
  76. data/lib/mack/initialization/plugins.rb +0 -16
  77. data/lib/mack/initialization/server/simple_server.rb +0 -19
  78. data/lib/mack/tasks/mack_server_tasks.rake +0 -24
  79. data/lib/mack/utils/paths.rb +0 -154
@@ -0,0 +1,26 @@
1
+ require 'mack-facets'
2
+
3
+ run_once do
4
+
5
+ require File.join_from_here('gems.rb')
6
+
7
+ init_message('plugins')
8
+
9
+ plugins = [] # a list of all plugins
10
+
11
+ Mack.search_path(:plugins).each do |path|
12
+ Dir.glob(File.join(path, '*')).each do |d|
13
+ plugins << d
14
+ $: << File.join(d, "lib") # add the lib for this plugin to the global load path
15
+ end
16
+ end
17
+ plugins.sort.each do |plug|
18
+ begin
19
+ require File.join(plug, "init.rb") # load the init.rb for each plugin.
20
+ rescue Exception => e
21
+ puts e.message
22
+ end
23
+ $:.delete(File.join(plug, "lib")) # remove the plugins lib directory from the global load path.
24
+ end
25
+
26
+ end
@@ -0,0 +1,20 @@
1
+ run_once do
2
+
3
+ require File.join_from_here('paths.rb')
4
+
5
+ Dir.glob(File.join_from_here('..', 'portlets', '**/*.rb')).each do |d|
6
+ require File.expand_path(d)
7
+ end
8
+
9
+ Mack.search_path(:initializers).each do |path|
10
+ f = File.join(path, 'portlets.rb')
11
+ require f if File.exists?(f)
12
+ end
13
+
14
+ required_portlets_list.each do |p|
15
+ puts "portlet: #{p}"
16
+ gem p.to_s
17
+ require p.to_s
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'mack-facets'
2
+
3
+ run_once do
4
+
5
+ require File.join_from_here('lib')
6
+
7
+ init_message('routes')
8
+
9
+ # We want local routes to be first
10
+ Mack.search_path_local_first(:config).each do |path|
11
+ f = File.join(path, 'routes.rb')
12
+ require f if File.exists?(f)
13
+ end
14
+
15
+ end
@@ -0,0 +1,7 @@
1
+ require 'mack-facets'
2
+
3
+ run_once do
4
+
5
+ require File.join_from_here('..', 'version.rb')
6
+
7
+ end
@@ -6,13 +6,14 @@ module Mack
6
6
  alias_instance_method :[], :old_hash
7
7
  alias_instance_method :store
8
8
  def [](key)
9
- data = old_hash(key.to_sym) || old_hash(key.to_s)
9
+ key = key.to_s.downcase
10
+ data = old_hash(key.to_sym) || old_hash(key)
10
11
  data = data.to_s if data.is_a?(Symbol)
11
12
  return data
12
13
  end
13
14
 
14
15
  def []=(key, value)
15
- _original_store(key.to_sym, value)
16
+ _original_store(key.downcase.to_sym, value)
16
17
  end
17
18
 
18
19
  def to_s
@@ -135,6 +136,8 @@ module Mack
135
136
  if k.to_s.match(/.+\[.+\]/)
136
137
  nv = k.to_s.match(/.+\[(.+)\]/).captures.first
137
138
  nk = k.to_s.match(/(.+)\[.+\]/).captures.first
139
+ nk.downcase!
140
+ nv.downcase!
138
141
  @mack_params[nk.to_sym] = {} if @mack_params[nk.to_sym].nil?
139
142
  v = v.uri_unescape if v.is_a?(String)
140
143
  @mack_params[nk.to_sym].merge!(nv.to_sym => v)
@@ -53,5 +53,9 @@ module Mack
53
53
  FileUtils.mv(self.temp_file.path, self.destination_path)
54
54
  end
55
55
 
56
+ def valid?
57
+ !self.file_name.blank? && !self.temp_file.nil?
58
+ end
59
+
56
60
  end
57
61
  end # :nodoc:
@@ -1,5 +1,31 @@
1
1
  module Kernel
2
2
 
3
+ def init_message(message) # :nodoc:
4
+ message = "Initializing '#{message}' ..."
5
+ if Mack.methods.include?('logger')
6
+ Mack.logger.debug(message) unless configatron.mack.log.disable_initialization_logging
7
+ else
8
+ puts message
9
+ end
10
+ end
11
+
12
+ # Returns Mack::Portlets::Manager
13
+ def require_portlets
14
+ yield Mack::Portlet::Manager.instance
15
+ end
16
+
17
+ # Returns an Array of gems required by the Mack::Portlets::Manager
18
+ def required_portlets_list
19
+ Mack::Portlet::Manager.instance.required_portlet_list
20
+ end
21
+
22
+ #
23
+ # Return the instance of the AssetManager class.
24
+ #
25
+ def assets_mgr
26
+ return Mack::Assets::Manager.instance
27
+ end
28
+
3
29
  # Returns Mack::Utils::GemManager
4
30
  def require_gems
5
31
  yield Mack::Utils::GemManager.instance
@@ -0,0 +1,16 @@
1
+ class Object
2
+
3
+ def errors_for(meth_name)
4
+ if self.respond_to?("errors") and self.errors
5
+ return self.errors[meth_name.to_sym]
6
+ end
7
+ return nil
8
+ end
9
+
10
+ def has_errors?(meth_name)
11
+ res = errors_for(meth_name)
12
+ return !res.empty? if res.is_a?(Array)
13
+ return !res.blank?
14
+ end
15
+
16
+ end
@@ -35,10 +35,12 @@ database_yml:
35
35
  template_path: <%= File.join(templates_directory_path, "config", "#{f}.template") %>
36
36
  output_path: <%= File.join(app_name, "config", f) %>
37
37
  <% end -%>
38
- gems_rb:
38
+ <% [:gems, :inflections, :mime_types, :portlets].each do |f| -%>
39
+ initializers_<%= f %>_rb:
39
40
  type: file
40
- template_path: <%= File.join(templates_directory_path, "config", "initializers", "gems.rb.template") %>
41
- output_path: <%= File.join(app_name, "config", "initializers", "gems.rb") %>
41
+ template_path: <%= File.join(templates_directory_path, "config", "initializers", "#{f}.rb.template") %>
42
+ output_path: <%= File.join(app_name, "config", "initializers", "#{f}.rb") %>
43
+ <% end -%>
42
44
  favicon:
43
45
  type: file
44
46
  template_path: <%= File.join(templates_directory_path, "public", "favicon.ico.template") %>
@@ -0,0 +1,9 @@
1
+ # Using this file you can Portlets to your application.
2
+ # Portlets are Mack applications that have been packaged as Gems using
3
+ # a few simple Rake tasks. These Portlets can extend your application
4
+ # and bring new functionality to them very, very easily.
5
+ require_portlets do |p|
6
+ # examples:
7
+ # p.add :my_cool_portlet, :version => "1.2.2"
8
+ # p.add :my_cool_portlet, :source => "http://gems.rubyforge.org"
9
+ end
@@ -168,3 +168,7 @@ label {
168
168
  display: inline-block;
169
169
  }
170
170
 
171
+ .error {
172
+ border: 2px solid red;
173
+ padding: 2px 2px 2px 2px;
174
+ }
@@ -0,0 +1,2 @@
1
+ class PortletGenerator < Genosaurus # :nodoc:
2
+ end
@@ -0,0 +1,3 @@
1
+ <%= File.basename(Mack.root) %> Portlet for the Mack Framework
2
+ -----------------------------------------------------------------
3
+ Developed by: <%= (ENV["USERNAME"] || ENV["USER"]) %>
@@ -0,0 +1,28 @@
1
+ Mack::Portlet.portlet_spec = Gem::Specification.new do |s|
2
+ s.name = "<%= File.basename(Mack.root) %>"
3
+ s.version = "0.0.1"
4
+ s.summary = "<%= File.basename(Mack.root) %> portlet for the Mack Framework"
5
+ s.description = "<%= File.basename(Mack.root) %> portlet for the Mack Framework"
6
+ s.author = "<%= (ENV["USERNAME"] || ENV["USER"]) %>"
7
+ s.email = ""
8
+ s.homepage = ""
9
+
10
+ s.test_files = FileList['test/**/*']
11
+
12
+ s.files = FileList['lib/**/*', 'README', 'doc/**/*.*', 'bin/**/*']
13
+ s.require_paths << 'lib'
14
+
15
+ s.bindir = "bin"
16
+ # s.executables << ""
17
+ #s.default_executable = ""
18
+ #s.add_dependency("", "")
19
+ #s.add_dependency("", "")
20
+ #s.extensions << ""
21
+ s.extra_rdoc_files = ["README"]
22
+ s.has_rdoc = true
23
+ #s.platform = "Gem::Platform::Ruby"
24
+ #s.required_ruby_version = ">= 1.8.6"
25
+ #s.requirements << "An ice cold beer."
26
+ #s.requirements << "Some free time!"
27
+ s.rubyforge_project = "<%= File.basename(Mack.root) %>"
28
+ end
@@ -0,0 +1,27 @@
1
+ require File.join_from_here('..', 'utils', 'gem_manager.rb')
2
+
3
+ module Mack
4
+ module Portlet # :nodoc:
5
+
6
+ # Used to manage the Portlets associated with the application.
7
+ class Manager
8
+ include Singleton
9
+
10
+ attr_accessor :required_portlet_list
11
+
12
+ def initialize # :nodoc:
13
+ @required_portlet_list = []
14
+ end
15
+
16
+ # Adds a Portlet to the application. This takes the same parameters as
17
+ # Mack::Utils::GemManager.instance.add
18
+ def add(name, options = {})
19
+ @required_portlet_list << name
20
+ @required_portlet_list.uniq!
21
+ Mack::Utils::GemManager.instance.add(name, options)
22
+ end
23
+
24
+
25
+ end # Manager
26
+ end # Portlet
27
+ end # Mack
@@ -0,0 +1,93 @@
1
+ module Mack
2
+
3
+ module Portlet # :nodoc:
4
+
5
+ class << self
6
+
7
+ attr_accessor :portlet_spec # :nodoc:
8
+
9
+ def clean # :nodoc:
10
+ FileUtils.rm_rf(Mack::Paths.portlet_package, :verbose => configatron.mack.portlet.verbose)
11
+ end
12
+
13
+ def prepare # :nodoc:
14
+ unless File.exists?(Mack::Paths.portlet_config)
15
+ PortletGenerator.run
16
+ end
17
+ load Mack::Paths.portlet_config('portlet.spec')
18
+ FileUtils.mkdir_p(Mack::Paths.portlet_package('lib'), :verbose => configatron.mack.portlet.verbose)
19
+ files = []
20
+ File.open(Mack::Paths.portlet_package('lib', "#{@portlet_spec.name}.rb"), 'w') do |f|
21
+
22
+ f.puts %{
23
+ Mack.add_search_path(:app, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'app'))
24
+ Mack.add_search_path(:controllers, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'app', 'controllers'))
25
+ Mack.add_search_path(:helpers, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'app', 'helpers'))
26
+ Mack.add_search_path(:models, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'app', 'models'))
27
+ Mack.add_search_path(:views, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'app', 'views'))
28
+ Mack.add_search_path(:config, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'config'))
29
+ Mack.add_search_path(:configatron, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'config', 'configatron'))
30
+ Mack.add_search_path(:initializers, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'config', 'initializers'))
31
+ Mack.add_search_path(:db, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'db'))
32
+ Mack.add_search_path(:lib, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'lib'))
33
+ Mack.add_search_path(:public, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'public'))
34
+ Mack.add_search_path(:vendor, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'vendor'))
35
+ Mack.add_search_path(:plugins, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}', 'vendor', 'plugins'))
36
+
37
+ Mack.set_base_path(:#{@portlet_spec.name.methodize}, File.join(File.dirname(__FILE__), '#{@portlet_spec.name}'))
38
+ }.strip
39
+
40
+ end # File.open
41
+
42
+ files << Dir.glob(Mack::Paths.app('**/*.*'))
43
+ files << Dir.glob(Mack::Paths.config('**/*.*'))
44
+ files << Dir.glob(Mack::Paths.db('**/*.*'))
45
+ files << Dir.glob(Mack::Paths.lib('**/*.*'))
46
+ files << Dir.glob(Mack::Paths.public('**/*.*'))
47
+ files << Dir.glob(Mack::Paths.plugins('**/*.*'))
48
+
49
+ files.flatten.compact.uniq.each do |file|
50
+ copy_file(file)
51
+ end
52
+
53
+ Dir.glob(Mack::Paths.bin('**/*')).each do |file|
54
+ copy_bin_file(file)
55
+ end
56
+
57
+ copy_bin_file(Mack::Paths.root('README'))
58
+
59
+ end # prepare
60
+
61
+ def package # :nodoc:
62
+ FileUtils.rm_rf(Mack::Paths.root('pkg'), :verbose => configatron.mack.portlet.verbose)
63
+ FileUtils.cd(Mack::Paths.portlet_package, :verbose => configatron.mack.portlet.verbose)
64
+ load Mack::Paths.portlet_config('portlet.spec')
65
+ Rake::GemPackageTask.new(Mack::Portlet.portlet_spec) do |pkg|
66
+ pkg.need_zip = configatron.mack.portlet.need_zip
67
+ pkg.need_tar = configatron.mack.portlet.need_tar
68
+ pkg.package_dir = Mack::Paths.root('pkg')
69
+ end
70
+ Rake::Task['package'].invoke
71
+ FileUtils.cd(Mack.root, :verbose => configatron.mack.portlet.verbose)
72
+ end
73
+
74
+ private
75
+ def copy_file(file)
76
+ n_path = file.gsub(Mack.root, '')
77
+ n_path = Mack::Paths.portlet_package('lib', @portlet_spec.name, n_path)
78
+ FileUtils.mkdir_p(File.dirname(n_path), :verbose => configatron.mack.portlet.verbose)
79
+ FileUtils.cp(file, n_path, :verbose => configatron.mack.portlet.verbose)
80
+ end
81
+
82
+ def copy_bin_file(file)
83
+ n_path = file.gsub(Mack.root, '')
84
+ n_path = Mack::Paths.portlet_package(n_path)
85
+ FileUtils.mkdir_p(File.dirname(n_path), :verbose => configatron.mack.portlet.verbose)
86
+ FileUtils.cp(file, n_path, :verbose => configatron.mack.portlet.verbose)
87
+ end
88
+
89
+ end # class << self
90
+
91
+ end # Portlet
92
+
93
+ end # Mack
@@ -0,0 +1,34 @@
1
+ module Mack
2
+ module Portlet
3
+ class Unpacker < Mack::Utils::RegistryMap
4
+
5
+ def unpack(key, force = false)
6
+ m = self.registered_items[key.to_sym]
7
+ if m
8
+ m.call((force || false))
9
+ else
10
+ Mack.search_path(key.to_sym, false).each do |path|
11
+ Dir.glob(File.join(path, '**/*')).each do |f|
12
+ f = File.expand_path(f)
13
+ dest = f.gsub(path, Mack::Paths.send(key))
14
+ FileUtils.mkdir_p(File.dirname(dest))
15
+ if File.file?(f)
16
+ cp = File.exists?(dest) ? force : true
17
+ if cp
18
+ FileUtils.cp(f, f.gsub(path, Mack::Paths.send(key)), :verbose => true) if cp
19
+ else
20
+ puts "Skipping: #{dest}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def initial_state
29
+ {}
30
+ end
31
+
32
+ end # Unpacker
33
+ end # Portlet
34
+ end # Mack
@@ -22,14 +22,14 @@ module Mack
22
22
  eruby.result(binding)
23
23
  rescue NoMethodError => e
24
24
  if file_name
25
- m = NoMethodError.new("undefined method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d)/).captures.first}")
25
+ m = NoMethodError.new("undefined method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d+)/).captures.first}")
26
26
  m.set_backtrace(e.backtrace)
27
27
  raise m
28
28
  end
29
29
  raise e
30
30
  rescue NameError => e
31
31
  if file_name
32
- m = NameError.new("undefined local variable or method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d)/).captures.first}")
32
+ m = NameError.new("undefined local variable or method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d+)/).captures.first}")
33
33
  m.set_backtrace(e.backtrace)
34
34
  raise m
35
35
  end
@@ -10,10 +10,14 @@ module Mack
10
10
  # Since engines are stored in an array, the are looped through until a template is found on disk.
11
11
  # If no template is found then a Mack::Errors::ResourceNotFound exception is thrown.
12
12
  def render_file(file, type = :action)
13
- Mack::Rendering::Engine::Registry.engines[type].each do |e|
14
- @engine = find_engine(e).new(self.view_template)
15
- find_file(file + ".#{@engine.extension}") do |f|
16
- return @engine.render(File.new(f), self._binder)
13
+ # we want to look local first, hence the reverse
14
+ Mack.search_path_local_first(:app).each do |path|
15
+ tfile = file.gsub(Mack::Paths.app, path)
16
+ Mack::Rendering::Engine::Registry.engines[type].each do |e|
17
+ @engine = find_engine(e).new(self.view_template)
18
+ find_file(tfile + ".#{@engine.extension}") do |f|
19
+ return @engine.render(File.new(f), self._binder)
20
+ end
17
21
  end
18
22
  end
19
23
  raise Mack::Errors::ResourceNotFound.new(file + ".*")
@@ -13,8 +13,10 @@ module Mack
13
13
  if File.extname(p_file).blank?
14
14
  p_file = "#{p_file}.#{self._options[:format]}"
15
15
  end
16
- find_file(Mack::Paths.public(p_file)) do |f|
17
- return File.open(f).read
16
+ Mack.search_path(:public).each do |path|
17
+ find_file(File.join(path, p_file)) do |f|
18
+ return File.open(f).read
19
+ end
18
20
  end
19
21
  raise Mack::Errors::ResourceNotFound.new(p_file)
20
22
  end
@@ -6,27 +6,53 @@ module Mack
6
6
 
7
7
  attr_accessor :controller
8
8
  attr_accessor :routes
9
+ attr_accessor :resources
9
10
 
10
- def initialize(controller)
11
+ def initialize(controller, resources = [])
11
12
  self.controller = controller
12
13
  self.routes = []
14
+ self.resources = resources
13
15
  end
14
16
 
15
17
  def method_missing(sym, *args)
16
18
  connect(sym, *args)
17
19
  end
18
20
 
21
+ def resource(name, options = {}, &block)
22
+ if block_given?
23
+ proxy = Mack::Routes::ResourceProxy.new(name, [self.resources, name].flatten)
24
+ yield proxy
25
+ proxy.routes.each do |route|
26
+ Mack::Routes::RouteMap.instance.connect_with_name("#{name}_#{route[:name]}", route[:path], options.merge(route[:options]))
27
+ end
28
+ end
29
+ Mack::Routes::RouteMap.instance.build_resource_routes(name, compile_path(name, self.resources), name, options)
30
+ end
31
+
19
32
  private
20
33
  def connect(name, path, options = {})
21
34
  route = {}
22
35
  route[:name] = name.to_s.gsub(/^#{self.controller}/, '')
23
36
  route[:options] = {:controller => self.controller, :action => route[:name].to_sym, :method => :get}.merge(options)
24
- paths = path.split('/')
25
- paths.insert(0, self.controller.to_s)
26
- route[:path] = paths.reject{|m| m.blank?}.uniq.join('/')
37
+ paths = compile_path(self.controller, self.resources.reject{|m| m === self.resources.last}).split('/')
38
+ paths << path.split('/')
39
+ paths.flatten!
40
+ paths.compact!
41
+ paths.uniq!
42
+ route[:path] = paths.reject{|m| m.blank?}.join('/')
27
43
  routes << route
28
44
  end
29
45
 
46
+ def compile_path(name, res)
47
+ x = []
48
+ res.each do |r|
49
+ x << r
50
+ x << ":#{r.to_s.singular}_id"
51
+ end
52
+ x << name
53
+ x.compact.join('/')
54
+ end
55
+
30
56
  end # ResourceProxy
31
57
 
32
58
  end # Routes