wrapt 0.1.4 → 0.1.5

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.
@@ -93,6 +93,19 @@ You can also select the layout to use inside a request. The following sets the
93
93
  end
94
94
  </code></pre>
95
95
 
96
+ Ask the layout to check if a given layout is available. You can then decide if you want to use that, or leave it as is.
97
+
98
+ <pre><code>def call(env)
99
+ content = generate_content_somehow
100
+ layout = env['layout']
101
+ layout.template_name = 'error' if layout.template_name?('error')
102
+
103
+ layout.content = content
104
+ Rack::Response.new(layout).finish
105
+ end
106
+ </code></pre>
107
+
108
+
96
109
  h3. Format
97
110
 
98
111
  Layouts are associated with a format. By default the format is html. Tempaltes are selected by their name with <name>.<format>.<template_type>.
@@ -14,10 +14,20 @@ class Wrapt
14
14
 
15
15
  # Is the wrapt instance that created this layouter set as a master?
16
16
  # @see Wrapt#master?
17
+ # @api public
17
18
  def master?
18
19
  @wrapt.master?
19
20
  end
20
21
 
22
+ # Check to see if there is a template of a given name and options
23
+ # for this layouter.
24
+ #
25
+ # @see Wrapt#template
26
+ # @api public
27
+ def template_name?(name, opts = {})
28
+ !!@wrapt.template(name, opts)
29
+ end
30
+
21
31
  # Gets the format that this layouter has been set to.
22
32
  # Defaults to the default_format of the wrapt instance
23
33
  #
@@ -142,7 +152,7 @@ class Wrapt
142
152
  template = @wrapt.template(template, opts)
143
153
 
144
154
  output = if template
145
- template.render(LayoutContext.new) do |*args|
155
+ template.render(LayoutContext.new(env)) do |*args|
146
156
  label = args.first || :content
147
157
  content_for[label]
148
158
  end
@@ -3,7 +3,16 @@ class Wrapt
3
3
  # Anything that is required to be avaible in the view context should be included into the Helpers module, or the LayoutContext
4
4
  # @see Wrapt::Helpers
5
5
  class LayoutContext
6
+ attr_reader :env
6
7
  include Tilt::CompileSite
7
8
  include Helpers
9
+
10
+ def initialize(env)
11
+ @env = env
12
+ end
13
+
14
+ def request
15
+ @request = Rack::Request.new(env)
16
+ end
8
17
  end
9
18
  end
@@ -322,5 +322,19 @@ describe Wrapt do
322
322
  $wrapped_content.should include("Other Template")
323
323
  end
324
324
  end
325
+
326
+ it "should respond true to a question for a template when there is one defined" do
327
+ env = Rack::MockRequest.env_for("/")
328
+ @wrapt.call(env)
329
+ layout = env['layout']
330
+ layout.template_name?(:wrapper).should be_true
331
+ end
332
+
333
+ it "Shoudl respond false to a question for a template when there is one defined" do
334
+ env = Rack::MockRequest.env_for("/")
335
+ @wrapt.call(env)
336
+ layout = env['layout']
337
+ layout.template_name?(:not_a_template).should be_false
338
+ end
325
339
  end
326
340
  end
@@ -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.4"
6
+ s.version = "0.1.5"
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"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
  s.rubygems_version = %q{1.3.6}
18
18
 
19
- s.files = Dir[File.join('.', "**/*")]
19
+ s.files = Dir["**/*"]
20
20
 
21
21
  s.add_dependency 'tilt'
22
22
  s.add_dependency 'hashie'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Neighman
@@ -50,29 +50,28 @@ extensions: []
50
50
  extra_rdoc_files: []
51
51
 
52
52
  files:
53
- - ./Gemfile
54
- - ./Gemfile.lock
55
- - ./lib/wrapt/helpers.rb
56
- - ./lib/wrapt/layout.rb
57
- - ./lib/wrapt/layout_context.rb
58
- - ./lib/wrapt/wrapt.rb
59
- - ./lib/wrapt.rb
60
- - ./LICENSE
61
- - ./Rakefile
62
- - ./README.textile
63
- - ./spec/alt_layouts/second.html.haml
64
- - ./spec/layouts/first.html.haml
65
- - ./spec/layouts/multiple.html.haml
66
- - ./spec/layouts/other.html.haml
67
- - ./spec/layouts/wrapper.html.haml
68
- - ./spec/layouts/wrapper.jsonp.erb
69
- - ./spec/layouts/wrapper.xml.haml
70
- - ./spec/spec.opts
71
- - ./spec/spec_helper.rb
72
- - ./spec/wrapt_spec.rb
73
- - ./VERSION
74
- - ./wrapt-0.1.3.gem
75
- - ./wrapt.gemspec
53
+ - Gemfile
54
+ - lib/wrapt/helpers.rb
55
+ - lib/wrapt/layout.rb
56
+ - lib/wrapt/layout_context.rb
57
+ - lib/wrapt/wrapt.rb
58
+ - lib/wrapt.rb
59
+ - LICENSE
60
+ - Rakefile
61
+ - README.textile
62
+ - spec/alt_layouts/second.html.haml
63
+ - spec/layouts/first.html.haml
64
+ - spec/layouts/multiple.html.haml
65
+ - spec/layouts/other.html.haml
66
+ - spec/layouts/wrapper.html.haml
67
+ - spec/layouts/wrapper.jsonp.erb
68
+ - spec/layouts/wrapper.xml.haml
69
+ - spec/spec.opts
70
+ - spec/spec_helper.rb
71
+ - spec/wrapt_spec.rb
72
+ - VERSION
73
+ - wrapt-0.1.3.gem
74
+ - wrapt.gemspec
76
75
  has_rdoc: true
77
76
  homepage: http://github.com/hassox/wrapt
78
77
  licenses: []
@@ -1,72 +0,0 @@
1
- ---
2
- dependencies:
3
- ZenTest:
4
- group:
5
- - :test
6
- version: ">= 0"
7
- haml:
8
- group:
9
- - :test
10
- version: ">= 0"
11
- any_view:
12
- group:
13
- - :default
14
- version: ">= 0"
15
- rake:
16
- group:
17
- - :test
18
- version: ">= 0"
19
- hashie:
20
- group:
21
- - :default
22
- version: ">= 0"
23
- rspec:
24
- group:
25
- - :test
26
- version: ">= 0"
27
- rack:
28
- group:
29
- - :test
30
- version: ">= 0"
31
- rack-test:
32
- group:
33
- - :test
34
- version: ">= 0"
35
- tilt:
36
- group:
37
- - :default
38
- version: ">= 0"
39
- specs:
40
- - rake:
41
- version: 0.8.7
42
- - ZenTest:
43
- version: 4.3.1
44
- - tilt:
45
- version: "0.9"
46
- source: 1
47
- - any_view:
48
- version: 0.2.0pre
49
- source: 0
50
- - haml:
51
- version: 2.2.24
52
- - hashie:
53
- version: 0.2.0
54
- - rack:
55
- version: 1.1.0
56
- - rack-test:
57
- version: 0.5.3
58
- - rspec:
59
- version: 1.3.0
60
- hash: 418544cd843b148c4469663f63faf3628ffce373
61
- sources:
62
- - Git:
63
- uri: git://github.com/hassox/any_view.git
64
- git: git://github.com/hassox/any_view.git
65
- ref: e1db4990883427eb634ae824ef95928f4ca51415
66
- - Git:
67
- uri: git://github.com/hassox/tilt.git
68
- branch: :hassox
69
- git: git://github.com/hassox/tilt.git
70
- ref: 8c652c803c1a62ec9854e1c320bee58c40546349
71
- - Rubygems:
72
- uri: http://gemcutter.org