pancake 0.1.10 → 0.1.12
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.
- data/Rakefile +5 -1
- data/lib/pancake/bootloaders.rb +27 -27
- data/lib/pancake/defaults/configuration.rb +2 -1
- data/lib/pancake/errors.rb +8 -7
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +1 -0
- data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +4 -0
- data/lib/pancake/generators/templates/short/%stack_name%/spec/spec_helper.rb.tt +5 -1
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +1 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/spec/%stack_name%_spec.rb.tt +4 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/spec/spec_helper.rb.tt +5 -1
- data/lib/pancake/mixins/render/render.rb +10 -4
- data/lib/pancake/mixins/render.rb +37 -7
- data/lib/pancake/mixins/request_helper.rb +25 -0
- data/lib/pancake/mixins/response_helper.rb +6 -0
- data/lib/pancake/router.rb +81 -7
- data/lib/pancake/stack/bootloader.rb +40 -10
- data/lib/pancake/stack/router.rb +10 -2
- data/lib/pancake/stack/stack.rb +34 -1
- data/lib/pancake/stacks/short/bootloaders.rb +2 -2
- data/lib/pancake/stacks/short/controller.rb +17 -4
- data/lib/pancake/test/matchers.rb +39 -0
- data/lib/pancake.rb +5 -0
- data/spec/pancake/bootloaders_spec.rb +29 -28
- data/spec/pancake/defaults/configuration_spec.rb +1 -1
- data/spec/pancake/fixtures/render_templates/view_context/_basic.haml +3 -0
- data/spec/pancake/fixtures/render_templates/view_context/_basic.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/_foo_as_name.haml +1 -0
- data/spec/pancake/fixtures/render_templates/view_context/_local_as_name.haml +1 -0
- data/spec/pancake/fixtures/render_templates/view_context/_with_locals.haml +2 -0
- data/spec/pancake/fixtures/render_templates/view_context/collection_with_partial_name.haml +1 -0
- data/spec/pancake/fixtures/render_templates/view_context/contains_partial.haml +5 -0
- data/spec/pancake/middleware_spec.rb +5 -5
- data/spec/pancake/mixins/render/view_context_spec.rb +60 -0
- data/spec/pancake/stack/router_spec.rb +52 -13
- data/spec/pancake/stacks/short/controller_spec.rb +35 -0
- data/spec/pancake/stacks/short/router_spec.rb +4 -2
- data/spec/pancake/stacks/short/stack_spec.rb +4 -3
- metadata +51 -3
data/Rakefile
CHANGED
@@ -11,7 +11,11 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/hassox/pancake"
|
12
12
|
gem.authors = ["Daniel Neighman"]
|
13
13
|
gem.add_development_dependency "rspec"
|
14
|
-
gem.add_dependency "usher", ">=0.5.
|
14
|
+
gem.add_dependency "usher", ">=0.5.10"
|
15
|
+
gem.add_dependency "extlib"
|
16
|
+
gem.add_dependency "thor"
|
17
|
+
gem.add_dependency "rack"
|
18
|
+
gem.add_dependency "tilt", ">=0.3"
|
15
19
|
gem.add_dependency "mynyml-rack-accept-media-types"
|
16
20
|
gem.require_path = 'lib'
|
17
21
|
gem.autorequire = 'pancake'
|
data/lib/pancake/bootloaders.rb
CHANGED
@@ -5,7 +5,7 @@ module Pancake
|
|
5
5
|
class Base
|
6
6
|
# :api: :public
|
7
7
|
attr_accessor :config
|
8
|
-
|
8
|
+
|
9
9
|
# Sets options for the bootloder
|
10
10
|
# By including conditions in the bootloader when you declare it
|
11
11
|
# You can selectively run bootloaders later
|
@@ -14,38 +14,38 @@ module Pancake
|
|
14
14
|
@options = opts
|
15
15
|
@options[:level] ||= :default
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Provides access to the bootloader options
|
19
19
|
# :api: private
|
20
20
|
def self.options # :nodoc:
|
21
21
|
@options ||= {}
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def stack
|
25
25
|
raise "No Stack Configured" unless @config[:stack]
|
26
26
|
@config[:stack]
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def stack_class
|
30
30
|
raise "No Stack Class Configured" unless @config[:stack_class]
|
31
31
|
@config[:stack_class]
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def initialize(config)
|
35
35
|
@config = config
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Creates a new instance and runs it
|
39
39
|
# :api: private
|
40
40
|
def self.call(config)
|
41
41
|
new(config).run!
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# Checks the conditions with the options of the bootloader
|
45
45
|
# To see if this one should be run
|
46
46
|
# Only the central bootloaders with the conditions will be checked
|
47
47
|
# :api: private
|
48
|
-
def self.run?(conditions = {})
|
48
|
+
def self.run?(conditions = {})
|
49
49
|
opts = options
|
50
50
|
if conditions.keys.include?(:only)
|
51
51
|
return conditions[:only].all?{|k,v| opts[k] == v}
|
@@ -56,7 +56,7 @@ module Pancake
|
|
56
56
|
true
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def self.extended(base)
|
61
61
|
base.class_eval do
|
62
62
|
class_inheritable_reader :_bootloaders, :_central_bootloaders, :_bootloader_map
|
@@ -64,14 +64,14 @@ module Pancake
|
|
64
64
|
@_bootloader_map = Hash.new{|h,k| h[k] = {:before => [], :after => []}}
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# Provides access to an individual bootloader
|
69
69
|
# :api: public
|
70
70
|
def [](name)
|
71
71
|
_bootloaders[name]
|
72
72
|
end
|
73
|
-
|
74
|
-
# Add a bootloader. Inside the block we're inside a class definition.
|
73
|
+
|
74
|
+
# Add a bootloader. Inside the block we're inside a class definition.
|
75
75
|
# Requirements: define a +run!+ method
|
76
76
|
#
|
77
77
|
# Example
|
@@ -80,19 +80,19 @@ module Pancake
|
|
80
80
|
# # stuff
|
81
81
|
# end
|
82
82
|
# end
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# :api: public
|
85
85
|
def add(name, opts = {}, &block)
|
86
86
|
_bootloaders[name] = Class.new(Pancake::BootLoaderMixin::Base, &block)
|
87
87
|
raise "You must declare a #run! method on your bootloader" unless _bootloaders[name].method_defined?(:run!)
|
88
88
|
before = opts[:before]
|
89
89
|
after = opts[:after]
|
90
|
-
|
90
|
+
|
91
91
|
if opts[:level]
|
92
92
|
levels << opts[:level]
|
93
93
|
levels.uniq!
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# If there are no before or after keys, add it to the central bootloaders
|
97
97
|
if before
|
98
98
|
_bootloader_map[before][:before] << name
|
@@ -103,10 +103,10 @@ module Pancake
|
|
103
103
|
end
|
104
104
|
_bootloaders[name].options = opts
|
105
105
|
_bootloaders[name]
|
106
|
-
end
|
107
|
-
|
106
|
+
end
|
107
|
+
|
108
108
|
# Runs the bootloaders in order
|
109
|
-
# :api: private
|
109
|
+
# :api: private
|
110
110
|
def run!(options = {}) # :nodoc:
|
111
111
|
unless options.keys.include?(:only) || options.keys.include?(:except)
|
112
112
|
options[:only] = {:level => :default}
|
@@ -122,19 +122,19 @@ module Pancake
|
|
122
122
|
bl.call(options)
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
# Set the stack that this bootloader is responsible for.
|
127
127
|
# :api: private
|
128
128
|
def stack=(stack) # :nodoc:
|
129
129
|
@stack = stack
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
# Access to the stack that this bootloader is responsible for
|
133
133
|
# :api: public
|
134
134
|
def stack
|
135
135
|
@stack ||= Object.full_const_get(self.name.split("::")[0..-2].join("::"))
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
# Resets the bootloaders on the stack
|
139
139
|
# :api: public
|
140
140
|
def reset!
|
@@ -142,21 +142,21 @@ module Pancake
|
|
142
142
|
_bootloaders.clear
|
143
143
|
_bootloader_map.clear
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
# Yields each bootloader in order along with it's name
|
147
|
-
#
|
147
|
+
#
|
148
148
|
# Example
|
149
149
|
# FooStack::BootLoader.each do |name, bootloader|
|
150
150
|
# # do stuff
|
151
151
|
# end
|
152
|
-
#
|
152
|
+
#
|
153
153
|
# :api: public
|
154
154
|
def each(conditions = {})
|
155
155
|
_map_bootloaders(_central_bootloaders, conditions).each do |n|
|
156
156
|
yield n, _bootloaders[n]
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
private
|
161
161
|
# Map out the bootloaders by name to run.
|
162
162
|
# :api: private
|
@@ -171,10 +171,10 @@ module Pancake
|
|
171
171
|
end
|
172
172
|
end.flatten.compact
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
def levels
|
176
176
|
@levels ||= [:default]
|
177
177
|
end
|
178
178
|
|
179
179
|
end # BootLoaders
|
180
|
-
end # Pancake
|
180
|
+
end # Pancake
|
@@ -10,7 +10,8 @@ class Pancake::PancakeConfig
|
|
10
10
|
if Pancake.configuration.log_to_file
|
11
11
|
log_dir = File.expand_path(File.join(Pancake.root, File.dirname(log_path)))
|
12
12
|
FileUtils.mkdir_p(log_dir)
|
13
|
-
File.join(log_dir, File.basename(log_path))
|
13
|
+
log = File.join(log_dir, File.basename(log_path))
|
14
|
+
File.open(log, (File::WRONLY | File::APPEND | File::CREAT))
|
14
15
|
else
|
15
16
|
STDOUT
|
16
17
|
end
|
data/lib/pancake/errors.rb
CHANGED
@@ -6,10 +6,11 @@ module Pancake
|
|
6
6
|
def name; self.class.name; end
|
7
7
|
|
8
8
|
def code; self.class.code; end
|
9
|
+
alias_method :status, :code
|
9
10
|
|
10
11
|
def description; self.class.description; end
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
class NotFound < HttpError
|
14
15
|
self.name = "Not Found"
|
15
16
|
self.code = 404
|
@@ -19,17 +20,17 @@ module Pancake
|
|
19
20
|
class UnknownRouter < NotFound
|
20
21
|
self.description = "The router could not be found"
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
class UnknownConfiguration < NotFound
|
24
25
|
self.description = "The configuration could not be found"
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
class Unauthorized < HttpError
|
28
29
|
self.name = "Unauthorized"
|
29
30
|
self.code = 401
|
30
31
|
self.description = "Authentication is required to access this resource."
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
class Forbidden < HttpError
|
34
35
|
self.name = "Forbidden"
|
35
36
|
self.code = 403
|
@@ -54,8 +55,8 @@ module Pancake
|
|
54
55
|
self.code = 406
|
55
56
|
self.description = "The requeseted format could not be provided"
|
56
57
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
|
60
|
+
|
60
61
|
end
|
61
62
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'spec'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'pancake'
|
4
|
+
|
2
5
|
|
3
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
8
|
require '<%= stack_name -%>'
|
6
9
|
|
7
10
|
Spec::Runner.configure do |config|
|
8
|
-
|
11
|
+
config.include(Rack::Test::Methods)
|
12
|
+
config.include(Pancake::Test::Matchers)
|
9
13
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'spec'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'pancake'
|
4
|
+
|
2
5
|
|
3
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
8
|
require '<%= stack_name -%>'
|
6
9
|
|
7
10
|
Spec::Runner.configure do |config|
|
8
|
-
|
11
|
+
config.include(Rack::Test::Methods)
|
12
|
+
config.include(Pancake::Test::Matchers)
|
9
13
|
end
|
@@ -32,10 +32,12 @@ module Pancake
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
_capture_methods[Tilt::HamlTemplate] = :_haml_capture
|
36
|
-
_capture_methods[Tilt::ERBTemplate
|
37
|
-
|
38
|
-
_concat_methods[ Tilt::
|
35
|
+
_capture_methods[Tilt::HamlTemplate ] = :_haml_capture
|
36
|
+
_capture_methods[Tilt::ERBTemplate ] = :_erb_capture
|
37
|
+
_capture_methods[Tilt::ErubisTemplate ] = :_erb_capture
|
38
|
+
_concat_methods[ Tilt::HamlTemplate ] = :_haml_concat
|
39
|
+
_concat_methods[ Tilt::ERBTemplate ] = :_erb_concat
|
40
|
+
_concat_methods[ Tilt::ErubisTemplate ] = :_erb_concat
|
39
41
|
|
40
42
|
module Renderer
|
41
43
|
def render(template, opts = {})
|
@@ -55,6 +57,10 @@ module Pancake
|
|
55
57
|
result
|
56
58
|
end
|
57
59
|
|
60
|
+
def partial(*args)
|
61
|
+
_view_context_for.partial(*args)
|
62
|
+
end
|
63
|
+
|
58
64
|
def _with_renderer(renderer)
|
59
65
|
orig_renderer = @_current_renderer
|
60
66
|
@_current_renderer = renderer
|
@@ -66,22 +66,47 @@ module Pancake
|
|
66
66
|
|
67
67
|
module InstanceMethods
|
68
68
|
def render(*args)
|
69
|
-
opts
|
70
|
-
name
|
71
|
-
|
69
|
+
opts = Hash === args.last ? args.pop : {}
|
70
|
+
name = args.shift
|
71
|
+
template_name = _template_name_for(name, opts)
|
72
72
|
return opts[:text] if opts[:text]
|
73
73
|
|
74
|
-
# Get the template name to use
|
75
|
-
template = _template_name_for(name, opts)
|
76
|
-
|
77
74
|
# Get the view context for the tempalte
|
78
|
-
template, vc_class = self.class._renderer_and_view_context_class_for(
|
75
|
+
template, vc_class = self.class._renderer_and_view_context_class_for(template_name)
|
79
76
|
|
80
77
|
view_context = vc_class.new(env, self)
|
81
78
|
view_context_before_render(view_context)
|
82
79
|
view_context.render(template, opts)
|
83
80
|
end
|
84
81
|
|
82
|
+
def partial(*args)
|
83
|
+
opts = Hash === args.last ? args.pop : {}
|
84
|
+
opts = opts.dup
|
85
|
+
name = args.shift
|
86
|
+
with = opts.delete(:with)
|
87
|
+
as = opts.delete(:as)
|
88
|
+
|
89
|
+
partial_name = _partial_template_name_for(name, opts)
|
90
|
+
# Get the view context for the tempalte
|
91
|
+
template, vc_class = self.class._renderer_and_view_context_class_for(partial_name)
|
92
|
+
|
93
|
+
view_context = vc_class.new(env, self)
|
94
|
+
view_context_before_render(view_context)
|
95
|
+
|
96
|
+
out = ""
|
97
|
+
case with
|
98
|
+
when Array
|
99
|
+
with.each do |item|
|
100
|
+
as.nil? ? (opts[name] = item) : (opts[as] = item)
|
101
|
+
out << view_context.render(template, opts)
|
102
|
+
end
|
103
|
+
else
|
104
|
+
as.nil? ? (opts[name] = with) : (opts[as] = with)
|
105
|
+
out << view_context.render(template, opts)
|
106
|
+
end
|
107
|
+
out
|
108
|
+
end
|
109
|
+
|
85
110
|
def template(name_or_template)
|
86
111
|
case name_or_template
|
87
112
|
when String, Symbol
|
@@ -93,6 +118,7 @@ module Pancake
|
|
93
118
|
end
|
94
119
|
end
|
95
120
|
|
121
|
+
|
96
122
|
# A place holder method for any implementor that wants
|
97
123
|
# to configure the view context prior to rendering occuring
|
98
124
|
# any time this method is overwritten, it should call super!
|
@@ -106,6 +132,10 @@ module Pancake
|
|
106
132
|
opts[:format] ||= params[:format] || :html
|
107
133
|
"#{name}.#{opts[:format]}"
|
108
134
|
end
|
135
|
+
|
136
|
+
def _partial_template_name_for(name, opts)
|
137
|
+
"_#{_template_name_for(name, opts)}"
|
138
|
+
end
|
109
139
|
end # InstanceMethods
|
110
140
|
end # Render
|
111
141
|
end # Mixins
|
@@ -41,6 +41,31 @@ module Pancake
|
|
41
41
|
konfig.router.generate(name, opts)
|
42
42
|
end
|
43
43
|
|
44
|
+
# Generate the base url for the router that got you to this point.
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# class MyApp
|
48
|
+
# router do |r|
|
49
|
+
# r.mount(SomeApp, "/some_app/:version")
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# include Pancake::RequestHelper
|
53
|
+
# def call(env)
|
54
|
+
# @env = env
|
55
|
+
# base_url(:version => "1.0" #=> "/some_app/1.0
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# @see Usher
|
60
|
+
# @see Pancake::Router.base_url_for
|
61
|
+
# @see Pancake::Router#base_url
|
62
|
+
# @api public
|
63
|
+
# @author Daniel Neighman
|
64
|
+
def base_url(opts={})
|
65
|
+
konfig = request.env[Pancake::Router::CONFIGURATION_KEY]
|
66
|
+
konfig.router.base_url(opts)
|
67
|
+
end
|
68
|
+
|
44
69
|
# Generate a url for any registered configuration with a router
|
45
70
|
#
|
46
71
|
# @example
|
data/lib/pancake/router.rb
CHANGED
@@ -21,6 +21,16 @@ module Pancake
|
|
21
21
|
the_router.url(name_or_opts, opts)
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.base_url_for(app_name, opts={})
|
25
|
+
config = Pancake.configuration.configs(app_name)
|
26
|
+
the_router = if config && config.router
|
27
|
+
config.router
|
28
|
+
elsif app_name.respond_to?(:router)
|
29
|
+
raise Pancake::Errors::UnknownRouter
|
30
|
+
end
|
31
|
+
the_router.base_url(opts)
|
32
|
+
end
|
33
|
+
|
24
34
|
# The pancake router is a customized version of the Usher router.
|
25
35
|
# Usher is a fast tree based router that can generate routes, have
|
26
36
|
# nested routers, and even generate from nested routers.
|
@@ -28,21 +38,78 @@ module Pancake
|
|
28
38
|
# @since 0.1.2
|
29
39
|
# @author Daniel Neighman
|
30
40
|
class Router < Usher::Interface::RackInterface
|
41
|
+
attr_writer :router
|
42
|
+
|
31
43
|
CONFIGURATION_KEY = "pancake.request.configuration".freeze
|
44
|
+
ROUTE_KEY = "pancake.request.matching_route".freeze
|
32
45
|
|
33
46
|
class RackApplicationExpected < ArgumentError; end
|
34
47
|
attr_accessor :configuration
|
48
|
+
class_inheritable_accessor :mounted_applications
|
49
|
+
self.mounted_applications = []
|
50
|
+
|
51
|
+
class MountedApplication
|
52
|
+
attr_accessor :mounted_app, :mount_path, :args, :stackup_with, :options,:mounted
|
53
|
+
def initialize(mounted_app, mount_path, opts = {})
|
54
|
+
@mounted_app, @mount_path = mounted_app, mount_path
|
55
|
+
@stackup_with = opts.delete(:_stackup) || :stackup
|
56
|
+
@args = opts.delete(:_args) || []
|
57
|
+
@exact_match = opts.delete(:_exact_match) || false
|
58
|
+
@options = opts
|
59
|
+
end
|
60
|
+
|
61
|
+
def name(name = nil)
|
62
|
+
unless name.nil?
|
63
|
+
@name = name
|
64
|
+
end
|
65
|
+
@name
|
66
|
+
end
|
67
|
+
|
68
|
+
def mounted?
|
69
|
+
!!@mounted
|
70
|
+
end
|
71
|
+
|
72
|
+
def exact_match?
|
73
|
+
!!@exact_match
|
74
|
+
end
|
75
|
+
|
76
|
+
def mount!(route)
|
77
|
+
app = nil
|
78
|
+
route.consuming = true
|
79
|
+
route.match_partially! unless exact_match?
|
80
|
+
if mounted_app.respond_to?(stackup_with)
|
81
|
+
app = mounted_app.send(stackup_with, *args)
|
82
|
+
else
|
83
|
+
app = mounted_app
|
84
|
+
end
|
85
|
+
route.to(app)
|
86
|
+
route.name(@name) if @name
|
87
|
+
route
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
35
91
|
|
36
92
|
# Mounts an application in the router as a sub application in the
|
37
93
|
# url space. This will route directly to the sub application and
|
38
|
-
# skip any middlewares etc
|
94
|
+
# skip any middlewares etc defined on a stack
|
39
95
|
def mount(mounted_app, path, options = {})
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
96
|
+
mounted_app = MountedApplication.new(mounted_app, path, options)
|
97
|
+
self.class.mounted_applications << mounted_app
|
98
|
+
mounted_app
|
99
|
+
end
|
100
|
+
|
101
|
+
def mount_applications!
|
102
|
+
# need to set them as mounted here before we actually to mount them.
|
103
|
+
# if we just mounted them, the inheritance of the routes would mean that only the first would be mounted on this class
|
104
|
+
# and the rest would be mounted on the child class
|
105
|
+
apps = self.class.mounted_applications.select do |a|
|
106
|
+
a.mounted? ? false : (a.mounted = true)
|
107
|
+
end
|
108
|
+
|
109
|
+
apps.each do |app|
|
110
|
+
route = add(app.mount_path, app.options)
|
111
|
+
app.mount!(route)
|
112
|
+
end
|
46
113
|
end
|
47
114
|
|
48
115
|
# Adds a route to the router.
|
@@ -67,12 +134,18 @@ module Pancake
|
|
67
134
|
generate(name, options)
|
68
135
|
end
|
69
136
|
|
137
|
+
def base_url(opts = {})
|
138
|
+
router.generator.generate_base_url(opts)
|
139
|
+
end
|
140
|
+
|
70
141
|
def call(env)
|
71
142
|
orig_config = env[CONFIGURATION_KEY]
|
143
|
+
orig_route = env[ROUTE_KEY]
|
72
144
|
env[CONFIGURATION_KEY] = configuration
|
73
145
|
super(env)
|
74
146
|
ensure
|
75
147
|
env[CONFIGURATION_KEY] = orig_config
|
148
|
+
env[ROUTE_KEY] = orig_route
|
76
149
|
end
|
77
150
|
|
78
151
|
private
|
@@ -94,6 +167,7 @@ module Pancake
|
|
94
167
|
super
|
95
168
|
consume_path!(request, response) if !response.partial_match? && response.path.route.consuming
|
96
169
|
request.params.merge!(request.env['usher.params']) unless request.env['usher.params'].empty?
|
170
|
+
request.env[ROUTE_KEY] = response.path.route
|
97
171
|
end
|
98
172
|
end
|
99
173
|
end
|
@@ -15,7 +15,7 @@ end # Pancake
|
|
15
15
|
# :level => :init bootloaders only have the stack class available
|
16
16
|
# They do not have :stack available
|
17
17
|
# These are not run directly, but are run from inherited stacks
|
18
|
-
Pancake::Stack::BootLoader.add(:
|
18
|
+
Pancake::Stack::BootLoader.add(:load_mounted_inits, :level => :init) do
|
19
19
|
def run!
|
20
20
|
# Mount any stacks this stack may have in it.
|
21
21
|
stack_class.roots.each do |root|
|
@@ -42,15 +42,6 @@ Pancake::Stack::BootLoader.add(:load_application, :level => :init) do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
Pancake::Stack::BootLoader.add(:load_routes, :level => :init) do
|
46
|
-
def run!
|
47
|
-
stack_class.roots.each do |root|
|
48
|
-
stack_class.paths_for(:router).each{|f| require f.join}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
###### -================== Stack Building BootLoaders
|
54
45
|
# Pancake stacks need to be built with the following options
|
55
46
|
# MyApp::BootLoader.run!({
|
56
47
|
# :stack_class => self.class,
|
@@ -61,12 +52,45 @@ end
|
|
61
52
|
#
|
62
53
|
#
|
63
54
|
|
55
|
+
|
56
|
+
Pancake::Stack::BootLoader.add(:load_routes) do
|
57
|
+
def run!
|
58
|
+
stack_class.roots.each do |root|
|
59
|
+
stack_class.paths_for(:router).each{|f| require f.join}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Pancake::Stack::BootLoader.add(:before_mount_applicaions) do
|
65
|
+
def run!
|
66
|
+
stack_class.before_mount_applications.each{|blk| blk.call}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Pancake::Stack::BootLoader.add(:mount_applications) do
|
71
|
+
def run!
|
72
|
+
stack_class.router.mount_applications!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
Pancake::Stack::BootLoader.add(:initialize_application) do
|
65
77
|
def run!
|
66
78
|
config[:app] ||= stack_class.new_app_instance
|
67
79
|
end
|
68
80
|
end
|
69
81
|
|
82
|
+
Pancake::Stack::BootLoader.add(:after_initialize_application) do
|
83
|
+
def run!
|
84
|
+
stack_class.after_initialize_application.each{|blk| blk.call}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
Pancake::Stack::BootLoader.add(:before_build_stack) do
|
89
|
+
def run!
|
90
|
+
stack_class.before_build_stack.each{|blk| blk.call}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
70
94
|
Pancake::Stack::BootLoader.add(:build_stack) do
|
71
95
|
def run!
|
72
96
|
mwares = stack_class.middlewares(Pancake.stack_labels)
|
@@ -77,3 +101,9 @@ Pancake::Stack::BootLoader.add(:build_stack) do
|
|
77
101
|
app_config.router.configuration = app_config
|
78
102
|
end
|
79
103
|
end
|
104
|
+
|
105
|
+
Pancake::Stack::BootLoader.add(:after_build_stack) do
|
106
|
+
def run!
|
107
|
+
stack_class.after_build_stack.each{|blk| blk.call}
|
108
|
+
end
|
109
|
+
end
|