wrapt 0.1.6 → 0.1.7

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.
@@ -35,12 +35,14 @@ class Wrapt
35
35
  # Default format, default layout or declare the layouter as the "master"
36
36
  #
37
37
  # @see Wrapt#master!
38
+ # @see Wrapt#defer!
38
39
  # @see Wrapt#layout_dirs
39
40
  # @see Wrapt#default_format
40
41
  # @see Wrapt#default_template
41
42
  def initialize(app)
42
- @app = app
43
+ @app = app
43
44
  @master = false
45
+ @defer = false
44
46
  yield self if block_given?
45
47
  end
46
48
 
@@ -54,11 +56,24 @@ class Wrapt
54
56
  end
55
57
 
56
58
  # Checks to see if this layouter is a master
57
- # @api private
59
+ # @api public
58
60
  def master?
59
61
  !!@master
60
62
  end
61
63
 
64
+ # Defers this layout. Meaning that if there is another layout already in the environment
65
+ # That should be used and this one should do nothing.
66
+ # @api public
67
+ def defer!
68
+ @defer = true
69
+ end
70
+
71
+ # Checks to see if this mdidleware should be defered
72
+ # @api public
73
+ def defered?
74
+ !!@defer
75
+ end
76
+
62
77
  # Wrapt allows you to ignore layouts from the client side.
63
78
  #
64
79
  # This may be useful for esi, or ajax, where you want the content, but not the layout
@@ -95,7 +110,7 @@ class Wrapt
95
110
  def call(env)
96
111
  env['request.variables'] ||= Hashie::Mash.new
97
112
  layout = env['layout']
98
- if !layout || (layout && !layout.master?)
113
+ if !layout || (!self.defered? && !layout.master?)
99
114
  env['layout'] = Layout.new(self, env)
100
115
  end
101
116
  r = @app.call(env) # just return what the app returns… If it wants a layout, it will return it.
@@ -120,7 +120,10 @@ describe Wrapt do
120
120
 
121
121
  describe "injecting into the environment" do
122
122
  before do
123
- @wrapt = Wrapt.new(SpecWraptApp){|w| w.default_template = :wrapper}
123
+ @wrapt = Wrapt.new(SpecWraptApp){|w|
124
+ w.default_template = :wrapper
125
+ w.layout_dirs = layouts_dirs
126
+ }
124
127
  @env = Rack::MockRequest.env_for("/")
125
128
  end
126
129
 
@@ -173,6 +176,24 @@ describe Wrapt do
173
176
  layout = env['layout']
174
177
  layout.wrapt.should == @wrapt
175
178
  end
179
+
180
+ it "should allow me to add a default layout that is not used when there is an upstream layout" do
181
+ env = Rack::MockRequest.env_for("/foo.html")
182
+
183
+ wrapt2 = Wrapt.new(SpecWraptApp) do |wrapt|
184
+ wrapt.defer!
185
+ wrapt.default_template = :other
186
+ wrapt.layout_dirs = layouts_dirs
187
+ end
188
+
189
+ s = @wrapt.call(env)
190
+ env['layout'].should_not be_nil
191
+ r = wrapt2.call(env)
192
+
193
+ result = r[2].body.to_s
194
+ result.should include("Wrapper Template")
195
+ result.should_not include("Other template")
196
+ end
176
197
  end
177
198
 
178
199
  describe Wrapt::Layout do
@@ -3,7 +3,7 @@ require 'bundler'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{wrapt}
6
- s.version = "0.1.6"
6
+ s.version = "0.1.7"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Daniel Neighman"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrapt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Neighman
@@ -75,9 +75,6 @@ files:
75
75
  - spec/spec.opts
76
76
  - spec/spec_helper.rb
77
77
  - spec/wrapt_spec.rb
78
- - VERSION
79
- - wrapt-0.1.3.gem
80
- - wrapt-0.1.5.gem
81
78
  - wrapt.gemspec
82
79
  has_rdoc: true
83
80
  homepage: http://github.com/hassox/wrapt
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
Binary file
Binary file