pancake 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/bin/pancake +96 -0
  2. data/lib/pancake.rb +5 -7
  3. data/lib/pancake/configuration.rb +2 -23
  4. data/lib/pancake/core_ext/object.rb +1 -1
  5. data/lib/pancake/defaults/configuration.rb +21 -1
  6. data/lib/pancake/generators.rb +0 -3
  7. data/lib/pancake/hooks/inheritable_inner_classes.rb +15 -2
  8. data/lib/pancake/master.rb +34 -1
  9. data/lib/pancake/mixins/render.rb +1 -2
  10. data/lib/pancake/mixins/stack_helper.rb +1 -1
  11. data/lib/pancake/router.rb +18 -63
  12. data/lib/pancake/stack/configuration.rb +3 -5
  13. data/lib/pancake/stack/router.rb +10 -33
  14. data/lib/pancake/stack/stack.rb +70 -50
  15. data/{spec/helpers → lib/pancake/test}/helpers.rb +3 -3
  16. data/lib/pancake/test/matchers.rb +20 -0
  17. data/lib/pancake/vendor/hashie/.document +5 -0
  18. data/lib/pancake/vendor/hashie/.gitignore +7 -0
  19. data/lib/pancake/vendor/hashie/Gemfile +11 -0
  20. data/lib/pancake/vendor/hashie/Gemfile.lock +25 -0
  21. data/lib/pancake/{generators/templates/short/%stack_name%/LICENSE.tt → vendor/hashie/LICENSE} +1 -1
  22. data/lib/pancake/vendor/hashie/README.rdoc +101 -0
  23. data/lib/pancake/{generators/templates/micro/%stack_name%/Rakefile.tt → vendor/hashie/Rakefile} +3 -13
  24. data/lib/pancake/vendor/hashie/VERSION +1 -0
  25. data/lib/pancake/vendor/hashie/hashie.gemspec +33 -0
  26. data/lib/pancake/vendor/hashie/lib/hashie.rb +5 -0
  27. data/lib/pancake/vendor/hashie/lib/hashie/clash.rb +86 -0
  28. data/lib/pancake/vendor/hashie/lib/hashie/dash.rb +108 -0
  29. data/lib/pancake/vendor/hashie/lib/hashie/hash.rb +22 -0
  30. data/lib/pancake/vendor/hashie/lib/hashie/hash_extensions.rb +49 -0
  31. data/lib/pancake/vendor/hashie/lib/hashie/mash.rb +148 -0
  32. data/lib/pancake/vendor/hashie/spec/hashie/clash_spec.rb +42 -0
  33. data/lib/pancake/vendor/hashie/spec/hashie/dash_spec.rb +103 -0
  34. data/lib/pancake/vendor/hashie/spec/hashie/hash_spec.rb +22 -0
  35. data/lib/pancake/vendor/hashie/spec/hashie/mash_spec.rb +135 -0
  36. data/lib/pancake/vendor/hashie/spec/spec.opts +2 -0
  37. data/lib/pancake/{generators/templates/short/%stack_name%/spec/spec_helper.rb.tt → vendor/hashie/spec/spec_helper.rb} +7 -7
  38. data/spec/pancake/configuration_spec.rb +1 -1
  39. data/spec/pancake/constants_spec.rb +1 -1
  40. data/spec/pancake/defaults/configuration_spec.rb +1 -1
  41. data/spec/pancake/hooks/on_inherit_spec.rb +13 -13
  42. data/spec/pancake/inheritance_spec.rb +22 -22
  43. data/spec/pancake/middleware_spec.rb +6 -5
  44. data/spec/pancake/middlewares/logger_spec.rb +1 -1
  45. data/spec/pancake/middlewares/static_spec.rb +1 -1
  46. data/spec/pancake/mime_types_spec.rb +1 -1
  47. data/spec/pancake/mixins/publish_spec.rb +24 -24
  48. data/spec/pancake/mixins/render/template_spec.rb +1 -1
  49. data/spec/pancake/mixins/render/view_context_spec.rb +1 -1
  50. data/spec/pancake/mixins/render_spec.rb +1 -1
  51. data/spec/pancake/mixins/request_helper_spec.rb +1 -1
  52. data/spec/pancake/mixins/stack_helper_spec.rb +3 -3
  53. data/spec/pancake/pancake_spec.rb +1 -1
  54. data/spec/pancake/paths_spec.rb +30 -30
  55. data/spec/pancake/stack/router_spec.rb +24 -62
  56. data/spec/pancake/stack/stack_configuration_spec.rb +1 -1
  57. data/spec/pancake/stack/stack_spec.rb +47 -4
  58. data/spec/spec_helper.rb +3 -3
  59. metadata +56 -128
  60. data/bin/pancake-gen +0 -30
  61. data/lib/pancake/bootloaders.rb +0 -187
  62. data/lib/pancake/generators/base.rb +0 -12
  63. data/lib/pancake/generators/micro_generator.rb +0 -17
  64. data/lib/pancake/generators/short_generator.rb +0 -18
  65. data/lib/pancake/generators/templates/common/dotgitignore +0 -22
  66. data/lib/pancake/generators/templates/common/dothtaccess +0 -17
  67. data/lib/pancake/generators/templates/micro/%stack_name%/%stack_name%.rb.tt +0 -8
  68. data/lib/pancake/generators/templates/micro/%stack_name%/config.ru.tt +0 -12
  69. data/lib/pancake/generators/templates/micro/%stack_name%/pancake_init.rb.tt +0 -1
  70. data/lib/pancake/generators/templates/micro/%stack_name%/public/.empty_directory +0 -0
  71. data/lib/pancake/generators/templates/micro/%stack_name%/tmp/.empty_directory +0 -0
  72. data/lib/pancake/generators/templates/micro/%stack_name%/views/root.html.haml +0 -1
  73. data/lib/pancake/generators/templates/short/%stack_name%/README.tt +0 -7
  74. data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +0 -56
  75. data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +0 -1
  76. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +0 -12
  77. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +0 -6
  78. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +0 -10
  79. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/config.rb.tt +0 -23
  80. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +0 -15
  81. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +0 -16
  82. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/staging.rb.tt +0 -17
  83. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/models/.empty_directory +0 -0
  84. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  85. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  86. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tasks/%stack_name%.rake.tt +0 -4
  87. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  88. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/views/root.html.haml +0 -2
  89. data/lib/pancake/generators/templates/short/%stack_name%/pancake_init.rb.tt +0 -1
  90. data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +0 -11
  91. data/lib/pancake/stack/app.rb +0 -10
  92. data/lib/pancake/stack/bootloader.rb +0 -114
  93. data/lib/pancake/stack/middleware.rb +0 -0
  94. data/lib/pancake/stacks/short.rb +0 -3
  95. data/lib/pancake/stacks/short/bootloaders.rb +0 -5
  96. data/lib/pancake/stacks/short/controller.rb +0 -184
  97. data/lib/pancake/stacks/short/default/views/base.html.haml +0 -5
  98. data/lib/pancake/stacks/short/default/views/error.html.haml +0 -12
  99. data/lib/pancake/stacks/short/stack.rb +0 -207
  100. data/spec/helpers/matchers.rb +0 -25
  101. data/spec/pancake/bootloaders_spec.rb +0 -119
  102. data/spec/pancake/stack/app_spec.rb +0 -28
  103. data/spec/pancake/stack/bootloader_spec.rb +0 -41
  104. data/spec/pancake/stack/middleware_spec.rb +0 -0
  105. data/spec/pancake/stacks/short/controller_spec.rb +0 -442
  106. data/spec/pancake/stacks/short/middlewares_spec.rb +0 -22
  107. data/spec/pancake/stacks/short/router_spec.rb +0 -150
  108. data/spec/pancake/stacks/short/stack_spec.rb +0 -117
@@ -1,16 +0,0 @@
1
- Pancake.logger.info "Loading Production Environment"
2
-
3
- Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
4
-
5
- class <%= stack_name.camel_case %>
6
- # include middleware for the development stack
7
- # stack(:middleware_name).use(MiddlewareClass)
8
- end
9
-
10
- # Add code to hooks. Default available hooks:
11
- # :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
12
-
13
- # <%= stack_name.camel_case %>.before_build_stack do
14
- # # stuff to do
15
- # end
16
-
@@ -1,17 +0,0 @@
1
- Pancake.logger.info "Loading Staging Environment"
2
-
3
- Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
4
-
5
- class <%= stack_name.camel_case %>
6
- # include middleware for the development stack
7
- # stack(:middleware_name).use(MiddlewareClass)
8
- end
9
-
10
- # Add code to hooks. Default available hooks:
11
- # :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
12
-
13
- # <%= stack_name.camel_case %>.before_build_stack do
14
- # # stuff to do
15
- # end
16
-
17
-
@@ -1,4 +0,0 @@
1
- namespace :<%= stack_name %> do
2
- # Create your tasks here
3
- end
4
-
@@ -1 +0,0 @@
1
- require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "lib", "<%= stack_name %>")
@@ -1,11 +0,0 @@
1
- require ::File.expand_path(::File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "<%= stack_name %>" do
4
- def app
5
- <%= stack_name %>.stackup
6
- end
7
-
8
- it "fails" do
9
- fail "hey buddy, you should probably rename this file and start specing for real"
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- module Pancake
2
- class Stack
3
- # get a new instance of the application for this stack
4
- # Ovewrite this to provide custom application initialization
5
- # :api: overwritable
6
- def self.new_app_instance
7
- MISSING_APP
8
- end
9
- end # Pancake
10
- end # Pancake
@@ -1,114 +0,0 @@
1
- module Pancake
2
- class Stack
3
- inheritable_inner_classes :BootLoader
4
-
5
- # The default bootloader is where the stack default bootloaders are stored
6
- # These are shared across all bootloaders
7
- class BootLoader # :nodoc:
8
- extend ::Pancake::BootLoaderMixin
9
- end
10
-
11
- end # Stack
12
- end # Pancake
13
-
14
- #################### Define the bootloaders here #############################
15
- # :level => :init bootloaders only have the stack class available
16
- # They do not have :stack available
17
- # These are not run directly, but are run from inherited stacks
18
-
19
- Pancake::Stack::BootLoader.add(:load_configuration, :level => :init) do
20
- def run!
21
- stack_class.paths_for(:config).each{|f| require f.join}
22
- end
23
- end
24
-
25
- Pancake::Stack::BootLoader.add(:load_mounted_inits, :level => :init) do
26
- def run!
27
- # Mount any stacks this stack may have in it.
28
- stack_class.paths_for(:mounts).each{|f| require f.join}
29
- end
30
- end
31
-
32
- Pancake::Stack::BootLoader.add(:before_stack_loads) do
33
- def run!
34
- stack_class.before_stack_loads.each{|blk| blk.call}
35
- end
36
- end
37
-
38
- Pancake::Stack::BootLoader.add(:load_application, :level => :init) do
39
- def run!
40
- [:models, :controllers].each do |type|
41
- stack_class.paths_for(type).each{|f| require f.join}
42
- end
43
- end
44
- end
45
-
46
- # Pancake stacks need to be built with the following options
47
- # MyApp::BootLoader.run!({
48
- # :stack_class => self.class,
49
- # :stack => self,
50
- # :app => app,
51
- # :app_name => app_name,
52
- # })
53
- #
54
- #
55
-
56
-
57
- Pancake::Stack::BootLoader.add(:load_routes, :level => :init) do
58
- def run!
59
- stack_class.paths_for(:router).each{|f| require f.join}
60
- end
61
- end
62
-
63
- Pancake::Stack::BootLoader.add(:before_mount_applicaions) do
64
- def run!
65
- stack_class.before_mount_applications.each{|blk| blk.call}
66
- end
67
- end
68
-
69
- Pancake::Stack::BootLoader.add(:load_middlewares) do
70
- def run!
71
- stack_class.paths_for(:middlewares).each{|f| require f.join}
72
- end
73
- end
74
-
75
- Pancake::Stack::BootLoader.add(:mount_applications) do
76
- def run!
77
- stack_class.router.mount_applications!
78
- end
79
- end
80
-
81
- Pancake::Stack::BootLoader.add(:initialize_application) do
82
- def run!
83
- config[:app] ||= stack_class.new_app_instance
84
- end
85
- end
86
-
87
- Pancake::Stack::BootLoader.add(:after_initialize_application) do
88
- def run!
89
- stack_class.after_initialize_application.each{|blk| blk.call}
90
- end
91
- end
92
-
93
- Pancake::Stack::BootLoader.add(:before_build_stack) do
94
- def run!
95
- stack_class.before_build_stack.each{|blk| blk.call}
96
- end
97
- end
98
-
99
- Pancake::Stack::BootLoader.add(:build_stack) do
100
- def run!
101
- mwares = stack_class.middlewares
102
- app = Pancake::Middleware.build(config[:app], mwares)
103
- app_config = Pancake.configuration.configs(config[:app_name])
104
- app_config.app = app
105
- app_config.stack = stack_class
106
- app_config.router.configuration = app_config
107
- end
108
- end
109
-
110
- Pancake::Stack::BootLoader.add(:after_build_stack) do
111
- def run!
112
- stack_class.after_build_stack.each{|blk| blk.call}
113
- end
114
- end
File without changes
@@ -1,3 +0,0 @@
1
- require 'pancake/stacks/short/stack'
2
- require 'pancake/stacks/short/controller'
3
- require 'pancake/stacks/short/bootloaders'
@@ -1,5 +0,0 @@
1
- Pancake::Stacks::Short::BootLoader.add(:default_middlewares, :before => :load_mounted_inits) do
2
- def run!
3
- stack_class.stack(:static_files).use(Pancake::Middlewares::Static, stack_class)
4
- end
5
- end
@@ -1,184 +0,0 @@
1
- module Pancake
2
- module Stacks
3
- class Short
4
- inheritable_inner_classes :Controller
5
- class Controller
6
- extend Mixins::Publish
7
- include Mixins::Render
8
- include Mixins::RequestHelper
9
- include Mixins::ResponseHelper
10
- include Mixins::StackHelper
11
-
12
- class self::ViewContext
13
- include Mixins::RequestHelper
14
- include AnyView
15
-
16
- # No way to get the env into the view context... this is not good :(
17
- def env
18
- _view_context_for.env
19
- end
20
-
21
- def self.template(name_or_template, opts = {})
22
- opts[:format] ||= content_type
23
- super
24
- end
25
-
26
- def template(name_or_template, opts={})
27
- opts[:format] ||= content_type
28
- super
29
- end
30
-
31
- def _template_name_for(name, opts = {})
32
- opts[:format] ||= :html
33
- "#{name}.#{opts[:format]}"
34
- end
35
- end
36
-
37
- extlib_inheritable_accessor :_handle_exception
38
-
39
- push_paths(:views, ["app/views", "views"], "**/*")
40
-
41
- DEFAULT_EXCEPTION_HANDLER = lambda do |error|
42
- use_layout = env[Router::LAYOUT_KEY]
43
- if use_layout
44
- layout = env['layout']
45
- layout.content = render :error, :error => error
46
- layout
47
- else
48
- render :error, :error => error
49
- end
50
- end unless defined?(DEFAULT_EXCEPTION_HANDLER)
51
-
52
- # @api private
53
- def self.call(env)
54
- app = new(env)
55
- app.dispatch!
56
- end
57
-
58
- def layout
59
- env['layout']
60
- end
61
-
62
- # @api public
63
- attr_accessor :status
64
-
65
- def initialize(env)
66
- @env, @request = env, Rack::Request.new(env)
67
- @status = 200
68
- end
69
-
70
- # Provides access to the request params
71
- # @api public
72
- def params
73
- request.params
74
- end
75
-
76
- # Dispatches to an action based on the params["action"] parameter
77
- def dispatch!
78
-
79
- params["action"] ||= params[:action]
80
- params[:format] ||= params["format"]
81
-
82
- if logger
83
- logger.info "Request: #{request.path}"
84
- logger.info "Params: #{params.inspect}"
85
- end
86
-
87
- # Check that the action is available
88
- raise Errors::NotFound, "No Action Found" unless allowed_action?(params["action"])
89
-
90
- @action_opts = actions[params["action"]]
91
-
92
- negotiate_content_type!(@action_opts.formats, params)
93
-
94
- # Setup the layout
95
- use_layout = env[Router::LAYOUT_KEY]
96
- layout = env['layout']
97
-
98
- # Set the layout defaults before the action is rendered
99
- if use_layout && stack_class.default_layout
100
- layout.template_name = stack_class.default_layout
101
- end
102
- layout.format = params['format'] if use_layout
103
-
104
- logger.info "Dispatching to #{params["action"].inspect}" if logger
105
-
106
- result = catch(:halt){ self.send(params['action']) }
107
-
108
- case result
109
- when Array
110
- result
111
- when Rack::Response
112
- result.finish
113
- when String
114
- out = if use_layout
115
- layout.content = result
116
- layout
117
- else
118
- result
119
- end
120
- Rack::Response.new(out, status, headers).finish
121
- else
122
- Rack::Response.new((result || ""), status, headers).finish
123
- end
124
-
125
- rescue Errors::HttpError => e
126
- if logger && log_http_error?(e)
127
- logger.error "Exception: #{e.message}"
128
- logger.error e.backtrace.join("\n")
129
- end
130
- handle_request_exception(e)
131
- rescue Exception => e
132
- if Pancake.handle_errors?
133
- server_error = Errors::Server.new(e.message)
134
- server_error.exceptions << e
135
- server_error.set_backtrace e.backtrace
136
- else
137
- server_error = e
138
- end
139
- handle_request_exception(server_error)
140
- end
141
-
142
- def log_http_error?(error)
143
- true
144
- end
145
-
146
- def self.handle_exception(&block)
147
- if block_given?
148
- self._handle_exception = block
149
- else
150
- self._handle_exception || DEFAULT_EXCEPTION_HANDLER
151
- end
152
- end
153
-
154
- def handle_request_exception(error)
155
- raise(error.class, error.message, error.backtrace) unless Pancake.handle_errors?
156
- self.status = error.code
157
- result = instance_exec error, &self.class.handle_exception
158
- Rack::Response.new(result, status, headers).finish
159
- end
160
-
161
- private
162
- def allowed_action?(action)
163
- self.class.actions.include?(action.to_s)
164
- end
165
-
166
- public
167
- def self.roots
168
- stack_class.roots
169
- end
170
-
171
- def self._template_name_for(name, opts)
172
- opts[:format] ||= :html
173
- "#{name}.#{opts[:format]}"
174
- end
175
-
176
- def _tempate_name_for(name, opts = {})
177
- opts[:format] ||= content_type
178
- self.class._template_name_for(name, opts)
179
- end
180
- end # Controller
181
-
182
- end # Short
183
- end # Stacks
184
- end # Pancake
@@ -1,5 +0,0 @@
1
- !!! 5
2
- %html
3
- %body
4
- -content_block :content do
5
- %h1 Welcome to Pancake!
@@ -1,12 +0,0 @@
1
- - content_block :error do
2
- .error
3
- %h1
4
- Error:
5
- = error.class
6
- .description
7
- = error.respond_to?(:description) ? error.description : error.message
8
-
9
- %ul.backtrace
10
- - error.backtrace.each do |line|
11
- %li= line
12
-
@@ -1,207 +0,0 @@
1
- module Pancake
2
- module Stacks
3
- class Short < Pancake::Stack
4
- add_root(__FILE__, "default")
5
-
6
- push_paths(:models,"models", "**/*.rb")
7
-
8
- def self.new_app_instance
9
- self::Controller
10
- end
11
-
12
- # Marks a method as published.
13
- # This is done implicitly when using the get, post, put, delete methods on a Stacks::Short
14
- # But can be done explicitly
15
- #
16
- # @see Pancake::Mixins::Publish#publish
17
- # @api public
18
- def self.publish(*args)
19
- @published = true
20
- self::Controller.publish(*args)
21
- end
22
-
23
- # @see Pancake::Mixins::Publish#as
24
- def self.as(*args)
25
- self::Controller.as(*args)
26
- end
27
-
28
- # @see Pancake::Mixins::Publish#provides
29
- def self.provides(*formats)
30
- self::Controller.provides(*formats)
31
- end
32
-
33
- def self.handle_exception(*args, &block)
34
- self::Controller.handle_exception(*args, &block)
35
- end
36
-
37
- def self.helpers(&blk)
38
- m = Module.new(&blk)
39
- self::Controller.class_eval{ include m }
40
- end
41
-
42
- def self.template(*args)
43
- self::Controller.template(*args)
44
- end
45
-
46
- def self.base_template_name
47
- self::Controller.base_template_name
48
- end
49
-
50
-
51
- # Gets a resource at a given path
52
- #
53
- # The block should finish with the final result of the action
54
- #
55
- # @param [String] path - a url path that conforms to Usher match path.
56
- # @param block - the contents of the block are executed when the path is matched.
57
- #
58
- # @example
59
- # get "/posts(/:year(/:month(/:date))" do
60
- # # do stuff to get posts and render them
61
- # end
62
- #
63
- # @see Usher
64
- # @api public
65
- # @author Daniel Neighman
66
- def self.get(path, opts = {}, &block)
67
- define_published_action(:get, path, opts, block)
68
- end
69
-
70
- # Posts a resource to a given path
71
- #
72
- # The block should finish with the final result of the action
73
- #
74
- # @param [String] path - a url path that conforms to Usher match path.
75
- # @param block - the contents of the block are executed when the path is matched.
76
- #
77
- # @example
78
- # post "/posts" do
79
- # # do stuff to post /posts and render them
80
- # end
81
- #
82
- # @see Usher
83
- # @api public
84
- # @author Daniel Neighman
85
- def self.post(path, opts = {}, &block)
86
- define_published_action(:post, path, opts, block)
87
- end
88
-
89
- # Puts a resource to a given path
90
- #
91
- # The block should finish with the final result of the action
92
- #
93
- # @param [String] path - a url path that conforms to Usher match path.
94
- # @param block - the contents of the block are executed when the path is matched.
95
- #
96
- # @example
97
- # put "/posts" do
98
- # # do stuff to post /posts and render them
99
- # end
100
- #
101
- # @see Usher
102
- # @api public
103
- # @author Daniel Neighman
104
- def self.put(path, opts = {}, &block)
105
- define_published_action(:put, path, opts, block)
106
- end
107
-
108
- # Deletes the resource at a given path
109
- #
110
- # The block should finish with the final result of the action
111
- #
112
- # @param [String] path - a url path that conforms to Usher match path.
113
- # @param block - the contents of the block are executed when the path is matched.
114
- #
115
- # @example
116
- # delete "/posts/foo-is-post" do
117
- # # do stuff to post foo-is-post and render the result
118
- # end
119
- #
120
- # @see Usher
121
- # @api public
122
- # @author Daniel Neighman
123
- def self.delete(path, opts = {}, &block)
124
- define_published_action(:delete, path, opts, block)
125
- end
126
-
127
- # Matches any method to the route
128
- # @api public
129
- def self.any(path, opts={}, &block)
130
- define_published_action(:any, path, opts, block)
131
- end
132
-
133
- private
134
- # Defines an action on the inner Controller class of this stack.
135
- # Also sets it as published if it's not already published.
136
- #
137
- # @param [Symbol] method - a smbol specifying the HTTP method
138
- # @param [String] path - a string specifying the path to map the url to
139
- # @api private
140
- # @author Daniel Neighman
141
- def self.define_published_action(method, path, opts, block)
142
- self::Controller.publish unless @published
143
- @published = nil
144
-
145
- action_name = controller_method_name(method,path)
146
- attach_action(action_name, block)
147
- attach_route(method, path, action_name, opts)
148
- end
149
-
150
- # Does the work of actually defining the action on the Controller Class
151
- #
152
- # @param [String] - the name of the method to create on the Controller class
153
- # @api private
154
- # @author Daniel Neighman
155
- def self.attach_action(method_name, block)
156
- self::Controller.class_eval do
157
- define_method(method_name, &block)
158
- end
159
- end
160
-
161
- # Supplies the path as a route to the stack router
162
- #
163
- # @param method [Symbol]
164
- #
165
- # @example
166
- # attach_route(:get, "/foo/bar", "get__foo_bar")
167
- #
168
- # @api private
169
- # @author Daniel Neighman
170
- def self.attach_route(method, path, action_name, options)
171
- name = options.delete(:_name)
172
- options[:conditions] ||= {}
173
- options[:conditions][:request_method] = method.to_s.upcase unless method == :any
174
- r = router.add(path, options)
175
- r.to(:action => action_name)
176
- r.name(name) if name
177
- r
178
- end
179
-
180
- # provides for methods of the following form on Controller
181
- # :<method>_<sanitized_path>
182
- #
183
- # @param [Symbol] method - the HTTP method to look for
184
- # @param [String] path - the url path expression to encode into the method name
185
- #
186
- # @return [String] - The actual controller method name to use for the action
187
- #
188
- # @api private
189
- # @author Daniel Neighman
190
- def self.controller_method_name(method, path)
191
- "#{method}_#{sanitize_path(path)}"
192
- end
193
-
194
- # sanitizes a path so it's able to be used as a method name
195
- #
196
- # @param [String] path - the path to sanitize
197
- #
198
- # @return [String] the sanitized version of the path safe to use as a method name
199
- # @api private
200
- # @author Daniel Neighman
201
- def self.sanitize_path(path)
202
- path.gsub(/\W/, "_")
203
- end
204
-
205
- end # Short
206
- end # Stacks
207
- end # Pancake