sinatra-contrib 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 20a1e473bbc0246851a1a86b2e442c28a18b55a3
4
- data.tar.gz: 295208b6345310d88a8776955a0fc43d5305fd3f
2
+ SHA256:
3
+ metadata.gz: 875fcac85ec3549476fa9363e6d74a93169d9bff6a285afa085dd9927e377b8f
4
+ data.tar.gz: a6f37d1271320146ef8a988b236276bb9b5385a44839f26ccc9740e5bd1fba85
5
5
  SHA512:
6
- metadata.gz: 016d33f9ff45a86a64c76b63adb6bddf59cfe99742223172091cc748b0fa7cab05a8f031c4566b15c8ef0facc944593eeb8d97c3e8d5bce45bf89db046d7be3e
7
- data.tar.gz: 50dba04560023eed92a8e6d4190d8032d771f56aaa237ceec781d6b859bf23eb423f1dedf1591fbda8d4267f97bcf04de9529c7d05e6d4571a1e1519e3ad6e1e
6
+ metadata.gz: 129dad2460c8a80bca9db661361479bf78a8c1369c053056414df493fc37a4b4135dd155c7bc0660b37a5ab03acc68da5dacea9fe35bf48e7493aab833ae5fde
7
+ data.tar.gz: ee1bccd800b4636a48a74e31c0371ed3be754e5037c1bf9afe95d782cb3ce8ddabced908fbe1a32cc9841dce16729513cd5c61baf1c0853ca30eb27b8404e60e
data/README.md CHANGED
@@ -22,7 +22,7 @@ Currently included:
22
22
 
23
23
  * [`sinatra/config_file`][sinatra-config-file]: Allows loading configuration from yaml files.
24
24
 
25
- * [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb,
25
+ * [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb, Erubi,
26
26
  Erubis and Slim.
27
27
 
28
28
  * [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies.
@@ -1,6 +1,5 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/engine_tracking'
3
- require 'active_support/core_ext/object/try.rb'
4
3
 
5
4
  module Sinatra
6
5
  #
@@ -85,38 +84,26 @@ module Sinatra
85
84
  module Capture
86
85
  include Sinatra::EngineTracking
87
86
 
88
- DUMMIES = {
89
- :haml => "!= capture_haml(*args, &block)",
90
- :erubis => "<% @capture = yield(*args) %>",
91
- :slim => "== yield(*args)"
92
- }
93
-
94
87
  def capture(*args, &block)
95
- @capture = nil
96
- if current_engine == :ruby
97
- result = block[*args]
98
- elsif current_engine == :erb || current_engine == :slim
99
- @_out_buf, _buf_was = '', @_out_buf
100
- block[*args]
101
- result = eval('@_out_buf', block.binding)
102
- @_out_buf = _buf_was
88
+ return block[*args] if ruby?
89
+ if haml?
90
+ buffer = Haml::Buffer.new(nil, Haml::Options.new.for_buffer)
91
+ with_haml_buffer(buffer) { capture_haml(*args, &block) }
103
92
  else
104
- buffer = eval '_buf if defined?(_buf)', block.binding
105
- old_buffer = buffer.dup if buffer
106
- dummy = DUMMIES.fetch(current_engine)
107
- options = { :layout => false, :locals => {:args => args, :block => block }}
108
-
109
- buffer.try :clear
110
- result = render(current_engine, dummy, options, &block)
93
+ @_out_buf, _buf_was = '', @_out_buf
94
+ begin
95
+ raw = block[*args]
96
+ captured = block.binding.eval('@_out_buf')
97
+ captured.empty? ? raw : captured
98
+ ensure
99
+ @_out_buf = _buf_was
100
+ end
111
101
  end
112
- result.strip.empty? && @capture ? @capture : result
113
- ensure
114
- buffer.try :replace, old_buffer
115
102
  end
116
103
 
117
104
  def capture_later(&block)
118
105
  engine = current_engine
119
- proc { |*a| with_engine(engine) { @capture = capture(*a, &block) }}
106
+ proc { |*a| with_engine(engine) { @capture = capture(*a, &block) } }
120
107
  end
121
108
  end
122
109
 
@@ -9,7 +9,7 @@ module Sinatra
9
9
  # blocks inside views to be rendered later during the request. The most
10
10
  # common use is to populate different parts of your layout from your view.
11
11
  #
12
- # The currently supported engines are: Erb, Erubis, Haml and Slim.
12
+ # The currently supported engines are: Erb, Erubi, Erubis, Haml and Slim.
13
13
  #
14
14
  # == Usage
15
15
  #
@@ -32,7 +32,7 @@ module Sinatra
32
32
  # to yield_content.
33
33
  #
34
34
  # # layout.erb
35
- # <%= yield_content :some_key_with_no_content do %>
35
+ # <% yield_content :some_key_with_no_content do %>
36
36
  # <chunk of="default html">...</chunk>
37
37
  # <% end %>
38
38
  #
@@ -128,8 +128,9 @@ module Sinatra
128
128
  #
129
129
  # Your blocks can also receive values, which are passed to them
130
130
  # by <tt>yield_content</tt>
131
- def content_for(key, value = nil, &block)
131
+ def content_for(key, value = nil, options = {}, &block)
132
132
  block ||= proc { |*| value }
133
+ clear_content_for(key) if options[:flush]
133
134
  content_blocks[key.to_sym] << capture_later(&block)
134
135
  end
135
136
 
@@ -171,9 +172,17 @@ module Sinatra
171
172
  #
172
173
  # Would pass <tt>1</tt> and <tt>2</tt> to all the blocks registered
173
174
  # for <tt>:head</tt>.
174
- def yield_content(key, *args)
175
- return yield(*args) if block_given? && content_blocks[key.to_sym].empty?
176
- content_blocks[key.to_sym].map { |b| capture(*args, &b) }.join
175
+ def yield_content(key, *args, &block)
176
+ if block_given? && !content_for?(key)
177
+ haml? ? capture_haml(*args, &block) : yield(*args)
178
+ else
179
+ content = content_blocks[key.to_sym].map { |b| capture(*args, &b) }
180
+ content.join.tap do |c|
181
+ if block_given? && (erb? || erubi? || erubis?)
182
+ @_out_buf << c
183
+ end
184
+ end
185
+ end
177
186
  end
178
187
 
179
188
  private
@@ -1,6 +1,6 @@
1
1
  module Sinatra
2
2
  module Contrib
3
- VERSION = '2.0.4'
3
+ VERSION = '2.0.5'
4
4
  end
5
5
  end
6
6
 
@@ -11,6 +11,15 @@ module Sinatra
11
11
  @current_engine == :erb
12
12
  end
13
13
 
14
+ # Returns true if the current engine is `:erubi`, or `Tilt[:erb]` is set
15
+ # to Tilt::ErubisTemplate.
16
+ #
17
+ # @return [Boolean] Returns true if current engine is `:erubi`.
18
+ def erubi?
19
+ @current_engine == :erubi or
20
+ erb? && Tilt[:erb] == Tilt::ErubiTemplate
21
+ end
22
+
14
23
  # Returns true if the current engine is `:erubis`, or `Tilt[:erb]` is set
15
24
  # to Tilt::ErubisTemplate.
16
25
  #
@@ -95,6 +104,11 @@ module Sinatra
95
104
  @current_engine == :creole
96
105
  end
97
106
 
107
+ # @return [Boolean] Returns true if current engine is `:ruby`.
108
+ def ruby?
109
+ @current_engine == :ruby
110
+ end
111
+
98
112
  def initialize(*)
99
113
  @current_engine = :ruby
100
114
  super
@@ -146,7 +146,7 @@ module Sinatra
146
146
  # module Zomg # Keep everything under "Zomg" namespace for sanity
147
147
  # module Routes # Define a new "Routes" module
148
148
  #
149
- # self.registered(app)
149
+ # def self.registered(app)
150
150
  # # First, register the Namespace extension
151
151
  # app.register Sinatra::Namespace
152
152
  #
@@ -245,7 +245,7 @@ module Sinatra
245
245
  :css => [:less, :sass, :scss],
246
246
  :xml => [:builder, :nokogiri],
247
247
  :js => [:coffee],
248
- :html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab,
248
+ :html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius, :mab,
249
249
  :markdown, :textile, :rdoc],
250
250
  :all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
251
251
  [:mab] - [:find_template, :markaby]),
@@ -39,13 +39,13 @@ EOF
39
39
  s.add_dependency "sinatra", version
40
40
  s.add_dependency "mustermann", "~> 1.0"
41
41
  s.add_dependency "backports", ">= 2.8.2"
42
- s.add_dependency "activesupport", ">= 4.0.0"
43
42
  s.add_dependency "tilt", ">= 1.3", "< 3"
44
43
  s.add_dependency "rack-protection", version
45
44
  s.add_dependency "multi_json"
46
45
 
47
46
  s.add_development_dependency "rspec", "~> 3.4"
48
47
  s.add_development_dependency "haml"
48
+ s.add_development_dependency "erubi"
49
49
  s.add_development_dependency "erubis"
50
50
  s.add_development_dependency "slim"
51
51
  s.add_development_dependency "less"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/sinatra/sinatra/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-15 00:00:00.000000000 Z
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.4
19
+ version: 2.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.4
26
+ version: 2.0.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mustermann
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.8.2
55
- - !ruby/object:Gem::Dependency
56
- name: activesupport
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 4.0.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 4.0.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: tilt
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +78,14 @@ dependencies:
92
78
  requirements:
93
79
  - - '='
94
80
  - !ruby/object:Gem::Version
95
- version: 2.0.4
81
+ version: 2.0.5
96
82
  type: :runtime
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - '='
101
87
  - !ruby/object:Gem::Version
102
- version: 2.0.4
88
+ version: 2.0.5
103
89
  - !ruby/object:Gem::Dependency
104
90
  name: multi_json
105
91
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +128,20 @@ dependencies:
142
128
  - - ">="
143
129
  - !ruby/object:Gem::Version
144
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: erubi
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: erubis
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -437,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
437
  version: '0'
438
438
  requirements: []
439
439
  rubyforge_project:
440
- rubygems_version: 2.6.8
440
+ rubygems_version: 2.7.6
441
441
  signing_key:
442
442
  specification_version: 4
443
443
  summary: Collection of useful Sinatra extensions