Skip to content

Commit

Permalink
Remove deprecated support for {ERB,Erubis}Template#default_output_var…
Browse files Browse the repository at this point in the history
…iable{,=}
  • Loading branch information
jeremyevans committed Jun 5, 2023
1 parent 44fdfa8 commit 6dbfd43
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master

* Remove deprecated support for {ERB,Erubis}Template#default_output_variable{,=} (jeremyevans)
* Remove deprecated support for CoffeeScriptTemplate.default_no_wrap{,=} (jeremyevans)
* Remove deprecated support for RedCarpet 1.x (jeremyevans)
* Remove deprecated support for Tilt.current_template (jeremyevans)
Expand Down
16 changes: 1 addition & 15 deletions lib/tilt/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@ module Tilt
class ERBTemplate < Template
SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false

# Remove in Tilt 2.3
@default_output_variable = nil
def self._default_output_variable
@default_output_variable
end
def self.default_output_variable
warn "#{self}.default_output_variable is deprecated and will be removed in Tilt 2.3.", uplevel: 1
@default_output_variable
end
def self.default_output_variable=(name)
warn "#{self}.default_output_variable= is deprecated and will be removed in Tilt 2.3. Switch to using the :outvar option.", uplevel: 1
@default_output_variable = name
end

def prepare
@freeze_string_literals = !!@options[:freeze]
@outvar = @options[:outvar] || self.class._default_output_variable || '_erbout'
@outvar = @options[:outvar] || '_erbout'
trim = case @options[:trim]
when false
nil
Expand Down
5 changes: 1 addition & 4 deletions lib/tilt/erubis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ module Tilt
# the engine class instead of the default. All content
# within <%= %> blocks will be automatically html escaped.
class ErubisTemplate < ERBTemplate
# Remove in Tilt 2.3
@default_output_variable = nil

def prepare
@freeze_string_literals = !!@options.delete(:freeze)
@outvar = @options.delete(:outvar) || self.class._default_output_variable || '_erbout'
@outvar = @options.delete(:outvar) || '_erbout'
@options[:preamble] = false
@options[:postamble] = false
@options[:bufvar] = @outvar
Expand Down
19 changes: 5 additions & 14 deletions test/tilt_erbtemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,11 @@
end

it "exposing the buffer to the template by default" do
verbose = $VERBOSE
begin
$VERBOSE = nil
Tilt::ERBTemplate.default_output_variable = '@_out_buf'
assert_equal '@_out_buf', Tilt::ERBTemplate.default_output_variable
template = Tilt::ERBTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
scope = _MockOutputVariableScope.new
template.render(scope)
refute_nil scope.exposed_buffer
assert_equal scope.exposed_buffer, 'hey'
ensure
Tilt::ERBTemplate.default_output_variable = '_erbout'
$VERBOSE = verbose
end
template = Tilt::ERBTemplate.new(:outvar=>'@_out_buf') { '<% self.exposed_buffer = @_out_buf %>hey' }
scope = _MockOutputVariableScope.new
template.render(scope)
refute_nil scope.exposed_buffer
assert_equal scope.exposed_buffer, 'hey'
end

it "passing a block for yield" do
Expand Down
18 changes: 5 additions & 13 deletions test/tilt_erubistemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ class MockOutputVariableScope
end

it "exposing the buffer to the template by default" do
verbose = $VERBOSE
begin
$VERBOSE = nil
Tilt::ErubisTemplate.default_output_variable = '@_out_buf'
template = Tilt::ErubisTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
scope = MockOutputVariableScope.new
template.render(scope)
refute_nil scope.exposed_buffer
assert_equal scope.exposed_buffer, 'hey'
ensure
Tilt::ErubisTemplate.default_output_variable = '_erbout'
$VERBOSE = verbose
end
template = Tilt::ErubisTemplate.new(:outvar=>'@_out_buf') { '<% self.exposed_buffer = @_out_buf %>hey' }
scope = MockOutputVariableScope.new
template.render(scope)
refute_nil scope.exposed_buffer
assert_equal scope.exposed_buffer, 'hey'
end

it "passing a block for yield" do
Expand Down

0 comments on commit 6dbfd43

Please sign in to comment.