pancake 0.1.25 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pancake/generators/templates/micro/%stack_name%/pancake_init.rb.tt +1 -1
- data/lib/pancake/generators/templates/short/%stack_name%/pancake_init.rb.tt +1 -1
- data/lib/pancake/master.rb +38 -0
- data/lib/pancake/mixins/render.rb +61 -11
- data/lib/pancake/mixins/render/render.rb +26 -3
- data/lib/pancake/mixins/render/template.rb +3 -3
- data/lib/pancake/mixins/request_helper.rb +1 -1
- data/lib/pancake/stack/stack.rb +9 -0
- data/lib/pancake/stacks/short/controller.rb +8 -15
- data/lib/pancake/stacks/short/stack.rb +8 -0
- data/spec/helpers/helpers.rb +3 -3
- data/spec/pancake/fixtures/render_templates/inherit/bar/base.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/inherit/bar/implicit_scope.html.haml +5 -0
- data/spec/pancake/fixtures/render_templates/inherit/bar/layout.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/base.html.haml +5 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/defaults.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/explicit.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/from_explicit.html.haml +6 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/from_implicit_scope.html.haml +5 -0
- data/spec/pancake/fixtures/render_templates/inherit/foo/simple.html.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_2.haml +5 -0
- data/spec/pancake/mixins/render/template_spec.rb +5 -5
- data/spec/pancake/mixins/render/view_context_spec.rb +77 -29
- data/spec/pancake/mixins/render_spec.rb +11 -0
- data/spec/pancake/pancake_spec.rb +52 -0
- data/spec/pancake/stack/stack_spec.rb +21 -3
- data/spec/pancake/stacks/short/controller_spec.rb +1 -0
- data/spec/pancake/stacks/short/stack_spec.rb +8 -0
- metadata +12 -2
@@ -1 +1 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__), "<%= stack_name %>")
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "<%= stack_name %>")
|
@@ -1 +1 @@
|
|
1
|
-
require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "lib", "<%= stack_name %>")
|
1
|
+
require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "lib", "<%= stack_name %>")
|
data/lib/pancake/master.rb
CHANGED
@@ -119,5 +119,43 @@ module Pancake
|
|
119
119
|
def logger=(logr)
|
120
120
|
@logger = logr
|
121
121
|
end
|
122
|
+
|
123
|
+
# The stack to use as the master stack. Can be nil!
|
124
|
+
# The master stack is assumed to be the stack that is the controlling stack for the group of pancake stacks
|
125
|
+
# @api public
|
126
|
+
def master_stack
|
127
|
+
@master_stack
|
128
|
+
end
|
129
|
+
|
130
|
+
# set the master stack. This also sets the master_templates as this stack if that hasn't yet been set.
|
131
|
+
# @see Pancake.master_templates
|
132
|
+
# @api public
|
133
|
+
def master_stack=(stack)
|
134
|
+
self.master_templates ||= stack
|
135
|
+
@master_stack = stack
|
136
|
+
end
|
137
|
+
|
138
|
+
# Used as the definitive source of shared templates for the whole pancake graph.
|
139
|
+
# Allows different stacks to share the same templates
|
140
|
+
# @see Pancake.master_templates=
|
141
|
+
# @api public
|
142
|
+
def master_templates
|
143
|
+
@master_templates
|
144
|
+
end
|
145
|
+
|
146
|
+
# Set the master templates to control the default templates for the stack
|
147
|
+
# @see Pancake.master_templates
|
148
|
+
# @api public
|
149
|
+
def master_templates=(stack)
|
150
|
+
@master_templates = stack
|
151
|
+
end
|
152
|
+
|
153
|
+
# provides access to the default base template via the Pancake.master_templates object
|
154
|
+
# @see Pancake.master_templates
|
155
|
+
# @api public
|
156
|
+
def default_base_template(opts = {})
|
157
|
+
raise "Master Templates not set" unless master_templates
|
158
|
+
master_templates.template(master_templates.base_template_name)
|
159
|
+
end
|
122
160
|
end # self
|
123
161
|
end # Pancake
|
@@ -42,7 +42,7 @@ module Pancake
|
|
42
42
|
end
|
43
43
|
|
44
44
|
raise TemplateNotFound unless renderer_path
|
45
|
-
_template_cache[name] = Template.new(name, renderer_path.join)
|
45
|
+
_template_cache[name] = Template.new(name, self, renderer_path.join)
|
46
46
|
end
|
47
47
|
|
48
48
|
def _view_context_cache
|
@@ -61,6 +61,25 @@ module Pancake
|
|
61
61
|
[_find_template(template), _find_view_context_class_for(template)]
|
62
62
|
end
|
63
63
|
|
64
|
+
def _template_name_for(name, opts = {})
|
65
|
+
opts[:format] ||= :html
|
66
|
+
"#{name}.#{opts[:format]}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def template(name_or_template, opts = {})
|
70
|
+
case name_or_template
|
71
|
+
when String, Symbol
|
72
|
+
_find_template(_template_name_for(name_or_template, opts))
|
73
|
+
when Template
|
74
|
+
name_or_template
|
75
|
+
else
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def base_template_name
|
81
|
+
:base
|
82
|
+
end
|
64
83
|
|
65
84
|
end # ClassMethods
|
66
85
|
|
@@ -109,18 +128,49 @@ module Pancake
|
|
109
128
|
out
|
110
129
|
end
|
111
130
|
|
112
|
-
def template(name_or_template)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
131
|
+
def template(name_or_template, opts = {})
|
132
|
+
opts[:format] ||= content_type
|
133
|
+
self.class.template(name_or_template, opts)
|
134
|
+
end
|
135
|
+
|
136
|
+
def negotiate_content_type!(*allowed_types)
|
137
|
+
return content_type if content_type
|
138
|
+
|
139
|
+
allowed_types = allowed_types.flatten
|
140
|
+
opts = allowed_types.pop if allowed_types.last.kind_of?(Hash)
|
141
|
+
if opts[:format]
|
142
|
+
cont, ct, mt = Pancake::MimeTypes.negotiate_by_extension(opts[:format].to_s, allowed_types)
|
118
143
|
else
|
119
|
-
|
144
|
+
env["HTTP_ACCEPT"] ||= "*/*"
|
145
|
+
cont, ct, mt = Pancake::MimeTypes.negotiate_accept_type(env["HTTP_ACCEPT"], allowed_types)
|
120
146
|
end
|
147
|
+
|
148
|
+
raise Errors::NotAcceptable unless cont
|
149
|
+
|
150
|
+
headers["Content-Type"] = ct
|
151
|
+
self.mime_type = mt
|
152
|
+
self.content_type = cont
|
153
|
+
cont
|
154
|
+
end
|
155
|
+
|
156
|
+
def content_type
|
157
|
+
env['pancake.request.format']
|
158
|
+
end
|
159
|
+
|
160
|
+
def content_type=(format)
|
161
|
+
env['pancake.request.format'] = format
|
162
|
+
end
|
163
|
+
|
164
|
+
def mime_type
|
165
|
+
env['pancake.request.mime']
|
166
|
+
end
|
167
|
+
|
168
|
+
def mime_type=(mime)
|
169
|
+
env['pancake.request.mime'] = mime
|
121
170
|
end
|
122
171
|
|
123
172
|
|
173
|
+
|
124
174
|
# A place holder method for any implementor that wants
|
125
175
|
# to configure the view context prior to rendering occuring
|
126
176
|
# any time this method is overwritten, it should call super!
|
@@ -130,9 +180,9 @@ module Pancake
|
|
130
180
|
end
|
131
181
|
|
132
182
|
private
|
133
|
-
def _template_name_for(name, opts)
|
134
|
-
opts[:format] ||=
|
135
|
-
|
183
|
+
def _template_name_for(name, opts = {})
|
184
|
+
opts[:format] ||= content_type
|
185
|
+
self.class._template_name_for(name, opts)
|
136
186
|
end
|
137
187
|
|
138
188
|
def _partial_template_name_for(name, opts)
|
@@ -48,10 +48,10 @@ module Pancake
|
|
48
48
|
end
|
49
49
|
|
50
50
|
if @_inherit_helper.inherits_from
|
51
|
-
next_template =
|
51
|
+
next_template = template.owner.template(@_inherit_helper.inherits_from)
|
52
52
|
@_inherit_helper.inherits_from = nil
|
53
53
|
result = _with_renderer next_template do
|
54
|
-
|
54
|
+
render(next_template, opts)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
result
|
@@ -72,6 +72,10 @@ module Pancake
|
|
72
72
|
def _current_renderer
|
73
73
|
@_current_renderer
|
74
74
|
end
|
75
|
+
|
76
|
+
def content_type
|
77
|
+
@_view_context_for.content_type
|
78
|
+
end
|
75
79
|
end # Renderer
|
76
80
|
|
77
81
|
module Capture
|
@@ -116,7 +120,26 @@ module Pancake
|
|
116
120
|
@_inherit_helper = Helper.new
|
117
121
|
end
|
118
122
|
|
119
|
-
def inherits_from(
|
123
|
+
def inherits_from(ntos, name_or_opts = nil, opts = {})
|
124
|
+
name_or_template = case ntos
|
125
|
+
when String, Symbol
|
126
|
+
if ntos == :default!
|
127
|
+
begin
|
128
|
+
Pancake.default_base_template(:format => content_type)
|
129
|
+
rescue
|
130
|
+
:base
|
131
|
+
end
|
132
|
+
else
|
133
|
+
ntos
|
134
|
+
end
|
135
|
+
else
|
136
|
+
if name_or_opts.kind_of?(Hash)
|
137
|
+
opts = name_or_opts
|
138
|
+
name_or_opts = nil
|
139
|
+
end
|
140
|
+
name_or_opts ||= ntos.base_template_name
|
141
|
+
ntos.template(name_or_opts, opts)
|
142
|
+
end
|
120
143
|
@_inherit_helper.inherits_from = name_or_template
|
121
144
|
end
|
122
145
|
|
@@ -5,10 +5,10 @@ module Pancake
|
|
5
5
|
class UnamedTemplate < Pancake::Errors::NotFound; end
|
6
6
|
class NotFound < Pancake::Errors::NotFound; end
|
7
7
|
|
8
|
-
attr_reader :name, :path, :renderer
|
8
|
+
attr_reader :name, :path, :renderer, :owner
|
9
9
|
|
10
|
-
def initialize(name, path)
|
11
|
-
@name, @path = name, path
|
10
|
+
def initialize(name, owner, path)
|
11
|
+
@name, @owner, @path = name, owner, path
|
12
12
|
raise UnamedTemplate unless name
|
13
13
|
raise NotFound unless File.exists?(path)
|
14
14
|
@renderer = Tilt.new(path)
|
data/lib/pancake/stack/stack.rb
CHANGED
@@ -136,6 +136,7 @@ module Pancake
|
|
136
136
|
|
137
137
|
# Sets this as a master stack. This means that the "master" directory will be added to all existing stack roots
|
138
138
|
def self.set_as_master!
|
139
|
+
Pancake.master_stack ||= self
|
139
140
|
# Want to add master to the roots for this stack only
|
140
141
|
roots.dup.each do |root|
|
141
142
|
unless root =~ /master\/?$/
|
@@ -144,6 +145,14 @@ module Pancake
|
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
148
|
+
def self.template(name,opts ={})
|
149
|
+
raise Errors::NotImplemented, "Stack may not be used for templates until it implements a template method"
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.base_template_name
|
153
|
+
raise Errors::NotImplemented, "Stack may not be used for templates until it implements a base_template_name method"
|
154
|
+
end
|
155
|
+
|
147
156
|
# Creates a bootloader hook(s) of the given name. That are inheritable
|
148
157
|
# This will create hooks for use in a bootloader (but will not create the bootloader itself!)
|
149
158
|
#
|
@@ -52,19 +52,11 @@ module Pancake
|
|
52
52
|
raise Errors::NotFound, "No Action Found" unless allowed_action?(params["action"])
|
53
53
|
|
54
54
|
@action_opts = actions[params["action"]]
|
55
|
-
if params[:format]
|
56
|
-
@content_type, ct, @mime_type = Pancake::MimeTypes.negotiate_by_extension(params[:format].to_s, @action_opts.formats)
|
57
|
-
else
|
58
|
-
@content_type, ct, @mime_type = Pancake::MimeTypes.negotiate_accept_type(env["HTTP_ACCEPT"], @action_opts.formats)
|
59
|
-
end
|
60
55
|
|
61
|
-
|
56
|
+
negotiate_content_type!(@action_opts.formats, params)
|
62
57
|
|
63
58
|
logger.info "Dispatching to #{params["action"].inspect}" if logger
|
64
59
|
|
65
|
-
# set the response header
|
66
|
-
headers["Content-Type"] = ct
|
67
|
-
|
68
60
|
result = catch(:halt){ self.send(params['action']) }
|
69
61
|
case result
|
70
62
|
when Array
|
@@ -92,10 +84,6 @@ module Pancake
|
|
92
84
|
handle_request_exception(server_error)
|
93
85
|
end
|
94
86
|
|
95
|
-
def content_type
|
96
|
-
@content_type
|
97
|
-
end
|
98
|
-
|
99
87
|
def log_http_error?(error)
|
100
88
|
true
|
101
89
|
end
|
@@ -125,10 +113,15 @@ module Pancake
|
|
125
113
|
stack_class.roots
|
126
114
|
end
|
127
115
|
|
128
|
-
def
|
129
|
-
opts[:format] ||=
|
116
|
+
def self._template_name_for(name, opts)
|
117
|
+
opts[:format] ||= :html
|
130
118
|
"#{name}.#{opts[:format]}"
|
131
119
|
end
|
120
|
+
|
121
|
+
def _tempate_name_for(name, opts = {})
|
122
|
+
opts[:format] ||= content_type
|
123
|
+
self.class._template_name_for(name, opts)
|
124
|
+
end
|
132
125
|
end # Controller
|
133
126
|
|
134
127
|
end # Short
|
@@ -39,6 +39,14 @@ module Pancake
|
|
39
39
|
self::Controller.class_eval{ include m }
|
40
40
|
end
|
41
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
|
+
|
42
50
|
# Gets a resource at a given path
|
43
51
|
#
|
44
52
|
# The block should finish with the final result of the action
|
data/spec/helpers/helpers.rb
CHANGED
@@ -3,7 +3,7 @@ module Pancake
|
|
3
3
|
module Helpers
|
4
4
|
def clear_constants(*classes)
|
5
5
|
classes.flatten.each do |klass|
|
6
|
-
begin
|
6
|
+
begin
|
7
7
|
Object.class_eval do
|
8
8
|
remove_const klass
|
9
9
|
end
|
@@ -11,10 +11,10 @@ module Pancake
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end # clear_constnat3
|
14
|
-
|
14
|
+
|
15
15
|
def env_for(path = "/", opts = {})
|
16
16
|
Rack::MockRequest.env_for(path, opts)
|
17
17
|
end
|
18
18
|
end # Helpers
|
19
19
|
end # Spec
|
20
|
-
end # Pancake
|
20
|
+
end # Pancake
|
@@ -14,31 +14,31 @@ describe Pancake::Mixins::Render::Template do
|
|
14
14
|
|
15
15
|
describe "Creation" do
|
16
16
|
it "should create a template with a name and a path" do
|
17
|
-
result = FooBar::Template.new(:context, File.join(@templates_path, "context.erb"))
|
17
|
+
result = FooBar::Template.new(:context, FooBar, File.join(@templates_path, "context.erb"))
|
18
18
|
result.should_not be_nil
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should raise an error when creating a template without a name" do
|
22
22
|
lambda do
|
23
|
-
FooBar::Template.new(nil, File.join(@templates_path, "context.erb"))
|
23
|
+
FooBar::Template.new(nil, FooBar, File.join(@templates_path, "context.erb"))
|
24
24
|
end.should raise_error(Pancake::Mixins::Render::Template::UnamedTemplate)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should raise an error when createing a template withouth a valid file name" do
|
28
28
|
lambda do
|
29
|
-
FooBar::Template.new(:foo, "/not/a/real/file.erb")
|
29
|
+
FooBar::Template.new(:foo, FooBar, "/not/a/real/file.erb")
|
30
30
|
end.should raise_error(Pancake::Mixins::Render::Template::NotFound)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should raise an error when it cannot create a rendering object for the file" do
|
34
34
|
lambda do
|
35
|
-
FooBar::Template.new(:foo, "/not/registed")
|
35
|
+
FooBar::Template.new(:foo, FooBar, "/not/registed")
|
36
36
|
end.should raise_error
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "accessing information" do
|
40
40
|
before do
|
41
|
-
@template = FooBar::Template.new(:context, File.join(@templates_path, "context.erb"))
|
41
|
+
@template = FooBar::Template.new(:context, FooBar, File.join(@templates_path, "context.erb"))
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should provide access to it's name" do
|
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper")
|
|
3
3
|
describe Pancake::Mixins::Render::ViewContext do
|
4
4
|
|
5
5
|
before do
|
6
|
+
@masters = [Pancake.master_stack, Pancake.master_templates]
|
6
7
|
$captures = []
|
7
8
|
class ::FooBar
|
8
9
|
include Pancake::Mixins::Render
|
@@ -12,16 +13,20 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
12
13
|
@env = env
|
13
14
|
end
|
14
15
|
|
15
|
-
def _template_name_for(name, opts)
|
16
|
+
def self._template_name_for(name, opts)
|
16
17
|
"#{name}"
|
17
18
|
end
|
19
|
+
|
18
20
|
push_paths :views, "", "**/*"
|
19
21
|
|
20
22
|
roots << File.join(File.expand_path(File.dirname(__FILE__)),"..","..", "fixtures", "render_templates", "view_context")
|
21
23
|
end
|
24
|
+
Pancake.master_stack = FooBar
|
25
|
+
Pancake.master_templates = FooBar
|
22
26
|
end
|
23
27
|
|
24
28
|
after do
|
29
|
+
Pancake.master_stack, Pancake.master_templates = @masters
|
25
30
|
clear_constants :FooBar, :BarFoo
|
26
31
|
end
|
27
32
|
|
@@ -40,34 +45,6 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
40
45
|
it "should include the Pancake::Mixins::RequestHelper helper" do
|
41
46
|
(Pancake::Mixins::RequestHelper > FooBar::ViewContext).should be_true
|
42
47
|
end
|
43
|
-
|
44
|
-
#it "should allow me to setup the view context before the view is run" do
|
45
|
-
# FooBar.class_eval do
|
46
|
-
# def view_context_before_render(context)
|
47
|
-
# super
|
48
|
-
# $captures << :here
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
# $captures.should be_blank
|
52
|
-
# FooBar.new.render(:context)
|
53
|
-
# $captures.should include(:here)
|
54
|
-
#end
|
55
|
-
|
56
|
-
#it "should execute the before render block in the instance" do
|
57
|
-
# FooBar.class_eval do
|
58
|
-
# def view_context_before_render(context)
|
59
|
-
# super
|
60
|
-
# $captures << data
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
# foobar = FooBar.new
|
64
|
-
# foobar.data = {:some => :data}
|
65
|
-
# foobar.render(:context)
|
66
|
-
# $captures.should include(:some => :data)
|
67
|
-
# $captures.clear
|
68
|
-
# FooBar.new.render(:context)
|
69
|
-
# $captures.should_not include(:some => :data)
|
70
|
-
#end
|
71
48
|
end
|
72
49
|
|
73
50
|
describe "inheriting classes" do
|
@@ -178,6 +155,13 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
178
155
|
result.should include("inherited haml content")
|
179
156
|
end
|
180
157
|
|
158
|
+
it "should inherit a template multiple times" do
|
159
|
+
result = @foo.render(:inherited_haml_level_2)
|
160
|
+
result.should include("inherited haml level 0")
|
161
|
+
result.should include("inherited haml level 1 content")
|
162
|
+
result.should include("inherited haml level 2 content")
|
163
|
+
end
|
164
|
+
|
181
165
|
end
|
182
166
|
|
183
167
|
describe "super blocks" do
|
@@ -250,6 +234,70 @@ describe Pancake::Mixins::Render::ViewContext do
|
|
250
234
|
end
|
251
235
|
end
|
252
236
|
|
237
|
+
describe "inheriting from a template object" do
|
238
|
+
before do
|
239
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "fixtures", "render_templates", "inherit"))
|
240
|
+
|
241
|
+
class ::BarFoo
|
242
|
+
include Pancake::Mixins::Render
|
243
|
+
push_paths :views, "", "**/*"
|
244
|
+
end
|
245
|
+
|
246
|
+
class ::FooBar
|
247
|
+
def self._template_name_for(name, opts = {})
|
248
|
+
opts[:format] ||= :html
|
249
|
+
r = "#{name}.#{opts[:format]}"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
FooBar.roots << File.join(path, "foo")
|
254
|
+
BarFoo.roots << File.join(path, "bar")
|
255
|
+
@app = FooBar.new({})
|
256
|
+
@bar = BarFoo.new
|
257
|
+
Pancake.master_templates = BarFoo
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should inherit from it's own stack with a name" do
|
261
|
+
result = @app.render(:simple)
|
262
|
+
result.should include("Foo Base")
|
263
|
+
result.should include("Simple Foo Content")
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should inherit from a stack, name pair" do
|
267
|
+
result = @app.render(:explicit)
|
268
|
+
result.should include("Bar Layout")
|
269
|
+
result.should include("Explicit Content")
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should inherit from the pancake default using :defaults!" do
|
273
|
+
result = @app.render(:defaults)
|
274
|
+
result.should include("Bar Base")
|
275
|
+
result.should include("Defaults Content")
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should use it's own base template when pancake does not have one set" do
|
279
|
+
Pancake.master_templates = nil
|
280
|
+
result = @app.render(:defaults)
|
281
|
+
result.should include("Foo Base")
|
282
|
+
result.should include("Defaults Content")
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should inherit multiple levels to an explicit base template" do
|
286
|
+
result = @app.render(:from_explicit)
|
287
|
+
result.should include("Bar Layout")
|
288
|
+
result.should include("Explicit Content")
|
289
|
+
result.should include("From Explicit Content")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should inherit to an explicit layout that inherits to a scoped template" do
|
293
|
+
result = @app.render(:from_implicit_scope)
|
294
|
+
result.should include("Bar Base")
|
295
|
+
result.should include("Bar Implicit Scope Content")
|
296
|
+
result.should include("From Implicit Scope Content")
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
253
301
|
describe "partials" do
|
254
302
|
before do
|
255
303
|
@foo = FooBar.new({})
|
@@ -36,6 +36,17 @@ describe Pancake::Mixins::Render do
|
|
36
36
|
@render.render(:haml_template).chomp.should == "IN HAML"
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should provide me with a template from the class" do
|
40
|
+
template = RenderSpecClass.template(:haml_template)
|
41
|
+
template.should be_a_kind_of(Pancake::Mixins::Render::Template)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow me to set the format for a given template" do
|
45
|
+
template = RenderSpecClass.template(:erb_template, :format => :json)
|
46
|
+
template.should be_a_kind_of(Pancake::Mixins::Render::Template)
|
47
|
+
template.name.should == "erb_template.json"
|
48
|
+
end
|
49
|
+
|
39
50
|
it "should render erb" do
|
40
51
|
@render.render(:erb_template).should == "IN ERB"
|
41
52
|
end
|
@@ -87,4 +87,56 @@ describe "pancake" do
|
|
87
87
|
Pancake.default_error_handling!
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
describe "master stack" do
|
92
|
+
before do
|
93
|
+
@b4 = Pancake.master_stack
|
94
|
+
@tb4 = Pancake.master_templates
|
95
|
+
end
|
96
|
+
|
97
|
+
after do
|
98
|
+
Pancake.master_stack = @b4
|
99
|
+
Pancake.master_templates = @tb4
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should have a master stack" do
|
103
|
+
Pancake.should respond_to(:master_stack)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should let me set a master stack" do
|
107
|
+
mock_stack = mock("stack", :null_object => true)
|
108
|
+
Pancake.master_stack = mock_stack
|
109
|
+
Pancake.master_stack.should == mock_stack
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should provide master templates stack as the master stack" do
|
113
|
+
mock_stack = mock("stack", :null_object => true)
|
114
|
+
Pancake.master_stack = mock_stack
|
115
|
+
Pancake.master_templates.should == mock_stack
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should let me overwrite the master_templates independantly of the master" do
|
119
|
+
mock_stack = mock("stack", :null_object => true)
|
120
|
+
mock_ui = mock("ui stack", :null_object => true)
|
121
|
+
Pancake.master_stack = mock_stack
|
122
|
+
Pancake.master_templates = mock_ui
|
123
|
+
Pancake.master_templates.should == mock_ui
|
124
|
+
Pancake.master_stack.should == mock_stack
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should not change the master templates when updating the master" do
|
128
|
+
stack1 = mock("stack1", :null_object => true)
|
129
|
+
ui = mock("ui", :null_object => true)
|
130
|
+
Pancake.master_templates = ui
|
131
|
+
Pancake.master_stack = stack1
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should provide me with the default template from the master_templates" do
|
135
|
+
ui = mock("ui")
|
136
|
+
ui.should_receive(:base_template_name).and_return(:fred)
|
137
|
+
ui.should_receive(:template).with(:fred).and_return(:template_fred)
|
138
|
+
Pancake.master_templates = ui
|
139
|
+
Pancake.default_base_template.should == :template_fred
|
140
|
+
end
|
141
|
+
end
|
90
142
|
end
|
@@ -2,13 +2,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
2
|
|
3
3
|
describe "Pancake::Stack" do
|
4
4
|
before(:each) do
|
5
|
-
class ::StackSpecStack < Pancake::Stack
|
6
|
-
end
|
5
|
+
class ::StackSpecStack < Pancake::Stack; end
|
6
|
+
class ::OtherSpecStack < Pancake::Stack; end
|
7
7
|
StackSpecStack.roots.clear
|
8
8
|
end
|
9
9
|
|
10
10
|
after(:each) do
|
11
|
-
clear_constants(:StackSpecStack, :FooSpecStack)
|
11
|
+
clear_constants(:StackSpecStack, :FooSpecStack, :OtherSpecStack)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "roots" do
|
@@ -59,6 +59,14 @@ describe "Pancake::Stack" do
|
|
59
59
|
end
|
60
60
|
# end
|
61
61
|
describe "master stack" do
|
62
|
+
before do
|
63
|
+
@b4 = Pancake.master_stack
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
Pancake.master_stack = @b4
|
68
|
+
end
|
69
|
+
|
62
70
|
it "should set the stack to be master, and include the master dir in each root" do
|
63
71
|
StackSpecStack.add_root(__FILE__)
|
64
72
|
before_roots = StackSpecStack.roots.dup
|
@@ -66,6 +74,16 @@ describe "Pancake::Stack" do
|
|
66
74
|
before_roots.each do |r|
|
67
75
|
StackSpecStack.roots.should include(File.join(r, "master"))
|
68
76
|
end
|
77
|
+
Pancake.master_stack.should == StackSpecStack
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not set a master stack when one has already been set" do
|
81
|
+
StackSpecStack.add_root(__FILE__)
|
82
|
+
OtherSpecStack.add_root(__FILE__)
|
83
|
+
StackSpecStack.stackup(:master => true)
|
84
|
+
Pancake.master_stack.should == StackSpecStack
|
85
|
+
OtherSpecStack.stackup(:master => true)
|
86
|
+
Pancake.master_stack.should == StackSpecStack
|
69
87
|
end
|
70
88
|
end
|
71
89
|
|
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
3
3
|
describe Pancake::Stacks::Short do
|
4
4
|
|
5
5
|
before do
|
6
|
+
@master_before = [Pancake.master_stack, Pancake.master_templates]
|
6
7
|
$captures = []
|
7
8
|
class ::ShortMiddle
|
8
9
|
attr_accessor :app
|
@@ -34,16 +35,23 @@ describe Pancake::Stacks::Short do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
@app = ShortFoo
|
38
|
+
Pancake.master_stack = ShortFoo
|
39
|
+
Pancake.master_templates = ShortFoo
|
37
40
|
end
|
38
41
|
|
39
42
|
after do
|
40
43
|
clear_constants :ShortFoo, :ShortMiddle, :OtherFoo, "ShortFoo::Router"
|
44
|
+
Pancake.master_stack, Pancake.master_templates = @master_before
|
41
45
|
end
|
42
46
|
|
43
47
|
def app
|
44
48
|
@app.stackup
|
45
49
|
end
|
46
50
|
|
51
|
+
it "should provide access through the stack interface to the templates" do
|
52
|
+
ShortFoo.template(:inherited_from_base).should be_an_instance_of(Pancake::Mixins::Render::Template)
|
53
|
+
end
|
54
|
+
|
47
55
|
it "should go through the middleware to get to the actions" do
|
48
56
|
get "/foo"
|
49
57
|
$captures.should == [ShortMiddle]
|
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.26
|
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-11-
|
12
|
+
date: 2009-11-28 00:00:00 +11:00
|
13
13
|
default_executable: pancake-gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -213,6 +213,15 @@ files:
|
|
213
213
|
- spec/pancake/fixtures/render_templates/erb_template.json.erb
|
214
214
|
- spec/pancake/fixtures/render_templates/haml_template.html.haml
|
215
215
|
- spec/pancake/fixtures/render_templates/haml_template.xml.haml
|
216
|
+
- spec/pancake/fixtures/render_templates/inherit/bar/base.html.haml
|
217
|
+
- spec/pancake/fixtures/render_templates/inherit/bar/implicit_scope.html.haml
|
218
|
+
- spec/pancake/fixtures/render_templates/inherit/bar/layout.html.haml
|
219
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/base.html.haml
|
220
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/defaults.html.haml
|
221
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/explicit.html.haml
|
222
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/from_explicit.html.haml
|
223
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/from_implicit_scope.html.haml
|
224
|
+
- spec/pancake/fixtures/render_templates/inherit/foo/simple.html.haml
|
216
225
|
- spec/pancake/fixtures/render_templates/templates/context.erb
|
217
226
|
- spec/pancake/fixtures/render_templates/view_context/_basic.haml
|
218
227
|
- spec/pancake/fixtures/render_templates/view_context/_basic.html.haml
|
@@ -234,6 +243,7 @@ files:
|
|
234
243
|
- spec/pancake/fixtures/render_templates/view_context/inherited_haml_from_erb.haml
|
235
244
|
- spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_0.haml
|
236
245
|
- spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_1.haml
|
246
|
+
- spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_2.haml
|
237
247
|
- spec/pancake/fixtures/render_templates/view_context/nested_content_level_0.haml
|
238
248
|
- spec/pancake/fixtures/render_templates/view_context/nested_content_level_1.haml
|
239
249
|
- spec/pancake/fixtures/render_templates/view_context/nested_inner.erb
|