pancake 0.1.8 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pancake.rb +2 -0
- data/lib/pancake/mixins/render.rb +5 -2
- data/lib/pancake/mixins/render/view_context.rb +2 -2
- data/lib/pancake/mixins/request_helper.rb +22 -22
- data/lib/pancake/mixins/response_helper.rb +17 -0
- data/lib/pancake/stack/router.rb +14 -0
- data/lib/pancake/stacks/short/controller.rb +1 -0
- data/spec/pancake/fixtures/stacks/short/foobar/views/template.html.haml +3 -0
- data/spec/pancake/fixtures/stacks/short/foobar/views/vault.html.haml +3 -0
- data/spec/pancake/mixins/render/view_context_spec.rb +17 -9
- data/spec/pancake/mixins/request_helper_spec.rb +9 -0
- data/spec/pancake/stack/router_spec.rb +13 -0
- data/spec/pancake/stacks/short/controller_spec.rb +51 -2
- metadata +5 -2
data/lib/pancake.rb
CHANGED
@@ -24,9 +24,11 @@ module Pancake
|
|
24
24
|
end
|
25
25
|
|
26
26
|
module Mixins
|
27
|
+
autoload :RequestHelper,"pancake/mixins/request_helper"
|
27
28
|
autoload :Publish, "pancake/mixins/publish"
|
28
29
|
autoload :Render, "pancake/mixins/render"
|
29
30
|
autoload :StackHelper, "pancake/mixins/stack_helper"
|
31
|
+
autoload :ResponseHelper, "pancake/mixins/response_helper"
|
30
32
|
end
|
31
33
|
|
32
34
|
module Middlewares
|
@@ -10,8 +10,11 @@ module Pancake
|
|
10
10
|
base.class_eval do
|
11
11
|
extend Pancake::Mixins::Render::ClassMethods
|
12
12
|
include Pancake::Mixins::Render::InstanceMethods
|
13
|
+
include Pancake::Mixins::RequestHelper
|
13
14
|
|
14
|
-
class self::ViewContext < Pancake::Mixins::Render::ViewContext
|
15
|
+
class self::ViewContext < Pancake::Mixins::Render::ViewContext
|
16
|
+
include Pancake::Mixins::RequestHelper
|
17
|
+
end
|
15
18
|
inheritable_inner_classes :ViewContext
|
16
19
|
|
17
20
|
unless ancestors.include?(Pancake::Paths)
|
@@ -74,7 +77,7 @@ module Pancake
|
|
74
77
|
# Get the view context for the tempalte
|
75
78
|
template, vc_class = self.class._renderer_and_view_context_class_for(template)
|
76
79
|
|
77
|
-
view_context = vc_class.new(self)
|
80
|
+
view_context = vc_class.new(env, self)
|
78
81
|
view_context_before_render(view_context)
|
79
82
|
view_context.render(template, opts)
|
80
83
|
end
|
@@ -8,10 +8,10 @@ module Pancake
|
|
8
8
|
include Renderer
|
9
9
|
include ContentInheritance
|
10
10
|
|
11
|
-
|
12
11
|
attr_reader :_view_context_for
|
13
|
-
def initialize(renderer_for = nil)
|
12
|
+
def initialize(env, renderer_for = nil )
|
14
13
|
super
|
14
|
+
@env = env
|
15
15
|
@_view_context_for = renderer_for
|
16
16
|
end
|
17
17
|
|
@@ -3,29 +3,17 @@ module Pancake
|
|
3
3
|
# Some helpers for requests that come in handy for applications that
|
4
4
|
# are part of stacks
|
5
5
|
module RequestHelper
|
6
|
+
VAULT_KEY = 'pancake.request.vault'
|
6
7
|
|
7
|
-
# A
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@env
|
17
|
-
end
|
18
|
-
|
19
|
-
def headers
|
20
|
-
@headers ||= {}
|
21
|
-
end
|
22
|
-
|
23
|
-
def status
|
24
|
-
@status ||= 200
|
25
|
-
end
|
26
|
-
|
27
|
-
def status=(st)
|
28
|
-
@status = st
|
8
|
+
# A data vault that allows you to carry data accross middlewares, controller / views etc.
|
9
|
+
# Stores the data in session for the length of the request.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# v[:user] = @user
|
13
|
+
# # This is now stored in the environment and is available later
|
14
|
+
def v
|
15
|
+
env[VAULT_KEY] ||= {}
|
16
|
+
env[VAULT_KEY]
|
29
17
|
end
|
30
18
|
|
31
19
|
# Generate a url for the current stacks router.
|
@@ -75,6 +63,18 @@ module Pancake
|
|
75
63
|
end
|
76
64
|
end
|
77
65
|
|
66
|
+
# A setter for the rack environment
|
67
|
+
# @api public
|
68
|
+
def env=(env)
|
69
|
+
@env = env
|
70
|
+
end
|
71
|
+
|
72
|
+
# An accessor for the rack environment variable
|
73
|
+
# @api public
|
74
|
+
def env
|
75
|
+
@env
|
76
|
+
end
|
77
|
+
|
78
78
|
# A handy request method that gets hold of the current request
|
79
79
|
# object for the current rack request.
|
80
80
|
# Any including class _must_ provide an +env+ method that exposes
|
data/lib/pancake/stack/router.rb
CHANGED
@@ -4,8 +4,22 @@ module Pancake
|
|
4
4
|
inheritable_inner_classes :Router
|
5
5
|
|
6
6
|
class_inheritable_accessor :_router
|
7
|
+
|
7
8
|
@_router = self::Router.new
|
8
9
|
|
10
|
+
# Resets the router to use the stacks namespaced router.
|
11
|
+
# This allows a router to mixin a module, and have that module
|
12
|
+
# mixed in to child stacks/routers. Effectively, this will reset the scope of inheritance so that a stack type can have particular route helpers
|
13
|
+
#
|
14
|
+
# When the router is rest, any routes declared in parent stacks will be lost.
|
15
|
+
# @example
|
16
|
+
# MyStack.reset_router! # => Replaces the current router with MyStack::Router (instance)
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def self.reset_router!
|
20
|
+
self._router = self::Router.new
|
21
|
+
end
|
22
|
+
|
9
23
|
def self.router
|
10
24
|
yield _router if block_given?
|
11
25
|
_router
|
@@ -8,6 +8,10 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
8
8
|
include Pancake::Mixins::Render
|
9
9
|
attr_accessor :params, :data
|
10
10
|
|
11
|
+
def initialize(env)
|
12
|
+
@env = env
|
13
|
+
end
|
14
|
+
|
11
15
|
def _template_name_for(name, opts)
|
12
16
|
"#{name}"
|
13
17
|
end
|
@@ -33,6 +37,10 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
33
37
|
FooBar::ViewContext.should inherit_from(Pancake::Mixins::Render::ViewContext)
|
34
38
|
end
|
35
39
|
|
40
|
+
it "should include the Pancake::Mixins::RequestHelper helper" do
|
41
|
+
(Pancake::Mixins::RequestHelper > FooBar::ViewContext).should be_true
|
42
|
+
end
|
43
|
+
|
36
44
|
#it "should allow me to setup the view context before the view is run" do
|
37
45
|
# FooBar.class_eval do
|
38
46
|
# def view_context_before_render(context)
|
@@ -86,12 +94,12 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
86
94
|
end
|
87
95
|
|
88
96
|
it "should provide access to the object the view context is rendering for" do
|
89
|
-
context = FooBar::ViewContext.new(@renderer)
|
97
|
+
context = FooBar::ViewContext.new({}, @renderer)
|
90
98
|
context._view_context_for.should == @renderer
|
91
99
|
end
|
92
100
|
|
93
101
|
it "should grab the template from the view context when rendering" do
|
94
|
-
context = FooBar::ViewContext.new(@renderer)
|
102
|
+
context = FooBar::ViewContext.new({}, @renderer)
|
95
103
|
@renderer.should_receive(:template).with(:foo).and_return(@renderer)
|
96
104
|
context.render(:foo, :some => :opts)
|
97
105
|
end
|
@@ -102,7 +110,7 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
102
110
|
end
|
103
111
|
|
104
112
|
it "should render the haml template with a capture" do
|
105
|
-
result = FooBar.new.render(:capture_haml)
|
113
|
+
result = FooBar.new({}).render(:capture_haml)
|
106
114
|
result.should_not include("captured haml")
|
107
115
|
|
108
116
|
context = $captures.first
|
@@ -111,7 +119,7 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
111
119
|
end
|
112
120
|
|
113
121
|
it "should capture in erb" do
|
114
|
-
result = FooBar.new.render(:capture_erb)
|
122
|
+
result = FooBar.new({}).render(:capture_erb)
|
115
123
|
result.should_not include("captured erb")
|
116
124
|
context = $captures.first
|
117
125
|
context.should_not be_nil
|
@@ -119,19 +127,19 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
119
127
|
end
|
120
128
|
|
121
129
|
it "should concat in haml" do
|
122
|
-
result = FooBar.new.render(:concat_haml)
|
130
|
+
result = FooBar.new({}).render(:concat_haml)
|
123
131
|
result.should include("concatenated")
|
124
132
|
end
|
125
133
|
|
126
134
|
it "should concat in erb" do
|
127
|
-
result = FooBar.new.render(:concat_erb)
|
135
|
+
result = FooBar.new({}).render(:concat_erb)
|
128
136
|
result.should include("concatenated")
|
129
137
|
end
|
130
138
|
end
|
131
139
|
|
132
140
|
describe "content_block" do
|
133
141
|
before do
|
134
|
-
@foo = FooBar.new
|
142
|
+
@foo = FooBar.new({})
|
135
143
|
end
|
136
144
|
|
137
145
|
it "should include the default text" do
|
@@ -174,7 +182,7 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
174
182
|
|
175
183
|
describe "super blocks" do
|
176
184
|
before do
|
177
|
-
@foo = FooBar.new
|
185
|
+
@foo = FooBar.new({})
|
178
186
|
end
|
179
187
|
|
180
188
|
it "should render the super text" do
|
@@ -224,7 +232,7 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
224
232
|
|
225
233
|
describe "multiple context blocks" do
|
226
234
|
before do
|
227
|
-
@foo = FooBar.new
|
235
|
+
@foo = FooBar.new({})
|
228
236
|
end
|
229
237
|
|
230
238
|
it "should allow nested default captures" do
|
@@ -24,4 +24,13 @@ describe Pancake::Mixins::RequestHelper do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
describe "v" do
|
28
|
+
it "should store the data put into v into the env" do
|
29
|
+
env = {}
|
30
|
+
foo = FooBar.new
|
31
|
+
foo.env = env
|
32
|
+
foo.v[:data] = :some_data
|
33
|
+
env[Pancake::Mixins::RequestHelper::VAULT_KEY][:data].should == :some_data
|
34
|
+
end
|
35
|
+
end
|
27
36
|
end
|
@@ -215,6 +215,19 @@ describe "stack router" do
|
|
215
215
|
BarApp::Router.should inherit_from(FooApp::Router)
|
216
216
|
end
|
217
217
|
|
218
|
+
it "should grab a new copy of the router rather than instantiate an inherited one" do
|
219
|
+
class ::BarApp < FooApp; end
|
220
|
+
FooApp.router.class.should == Pancake::Stack::Router
|
221
|
+
BarApp.router.class.should == Pancake::Stack::Router
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should reset the router to the namespaced router" do
|
225
|
+
class ::BarApp < FooApp; end
|
226
|
+
BarApp.reset_router!
|
227
|
+
BarApp.router.class.should == BarApp::Router
|
228
|
+
end
|
229
|
+
|
230
|
+
|
218
231
|
describe "generating urls inside an application" do
|
219
232
|
before do
|
220
233
|
class ::BarApp < FooApp; end
|
@@ -107,6 +107,57 @@ describe Pancake::Stacks::Short::Controller do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
describe "request helper methods" do
|
111
|
+
before do
|
112
|
+
class ::RequestFoo < Pancake::Stacks::Short
|
113
|
+
add_root(__FILE__, "..", "..", "fixtures", "stacks", "short", "foobar")
|
114
|
+
get "/foobar", :_name => :foobar do
|
115
|
+
url(:foobar)
|
116
|
+
end
|
117
|
+
|
118
|
+
get "/template", :_name => :template do
|
119
|
+
render :template
|
120
|
+
end
|
121
|
+
|
122
|
+
get "/vault" do
|
123
|
+
v[:my_data] = "some data"
|
124
|
+
render :vault
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
after do
|
130
|
+
clear_constants :RequestFoo
|
131
|
+
end
|
132
|
+
|
133
|
+
def app
|
134
|
+
RequestFoo.stackup
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should include the request helper methods" do
|
138
|
+
(Pancake::Mixins::RequestHelper > ShortFoo::Controller).should be_true
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should provide access to the request methods in the controller" do
|
142
|
+
result = get "/foobar"
|
143
|
+
result.body.should == "/foobar"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should provide access to the helper methods in the views" do
|
147
|
+
result = get "/template"
|
148
|
+
result.status.should == 200
|
149
|
+
result.body.should include("/foobar")
|
150
|
+
result.body.should include("In Template")
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should allow me to get information between the view and the controller" do
|
154
|
+
result = get "/vault"
|
155
|
+
result.status.should == 200
|
156
|
+
result.body.should include("some data")
|
157
|
+
result.body.should include("In Vault")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
110
161
|
describe "accept type negotiations" do
|
111
162
|
before do
|
112
163
|
class ::ShortBar < Pancake::Stacks::Short
|
@@ -247,8 +298,6 @@ describe Pancake::Stacks::Short::Controller do
|
|
247
298
|
r = get "/foo.svg"
|
248
299
|
r.status.should == 406
|
249
300
|
end
|
250
|
-
|
251
|
-
|
252
301
|
end
|
253
302
|
|
254
303
|
describe "custom error handling" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pancake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
@@ -9,7 +9,7 @@ autorequire: pancake
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-13 00:00:00 +11:00
|
13
13
|
default_executable: pancake-gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/pancake/mixins/render/template.rb
|
128
128
|
- lib/pancake/mixins/render/view_context.rb
|
129
129
|
- lib/pancake/mixins/request_helper.rb
|
130
|
+
- lib/pancake/mixins/response_helper.rb
|
130
131
|
- lib/pancake/mixins/stack_helper.rb
|
131
132
|
- lib/pancake/mixins/url.rb
|
132
133
|
- lib/pancake/paths.rb
|
@@ -198,6 +199,8 @@ files:
|
|
198
199
|
- spec/pancake/fixtures/stacks/short/foobar/other_root/views/base.html.haml
|
199
200
|
- spec/pancake/fixtures/stacks/short/foobar/views/basic.html.haml
|
200
201
|
- spec/pancake/fixtures/stacks/short/foobar/views/inherited_from_base.html.haml
|
202
|
+
- spec/pancake/fixtures/stacks/short/foobar/views/template.html.haml
|
203
|
+
- spec/pancake/fixtures/stacks/short/foobar/views/vault.html.haml
|
201
204
|
- spec/pancake/hooks/on_inherit_spec.rb
|
202
205
|
- spec/pancake/inheritance_spec.rb
|
203
206
|
- spec/pancake/middleware_spec.rb
|