Skip to content

Commit

Permalink
Remove deprecation warnings #196
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed May 18, 2013
1 parent 7acf101 commit e453e26
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
1 change: 0 additions & 1 deletion lib/tilt.rb
Expand Up @@ -29,7 +29,6 @@ def self.register_lazy(class_name, file, *extensions)

# @deprecated Use {register} instead.
def self.prefer(template_class, *extensions)
warn "Tilt.prefer has no longer any effect; use Tilt.register"
register(template_class, *extensions)
end

Expand Down
22 changes: 2 additions & 20 deletions lib/tilt/template.rb
Expand Up @@ -34,7 +34,6 @@ def metadata

# @deprecated Use `.metadata[:mime_type]` instead.
def default_mime_type
warn ".default_mime_type has been replaced with .metadata[:mime_type]"
metadata[:mime_type]
end

Expand Down Expand Up @@ -116,30 +115,13 @@ def eval_file
# An empty Hash that the template engine can populate with various
# metadata.
def metadata
if respond_to?(:real_allows_script?)
self.class.metadata.merge(:allows_script => real_allows_script?)
if respond_to?(:allows_script?)
self.class.metadata.merge(:allows_script => allows_script?)
else
self.class.metadata
end
end

# Depricate the usage of allows_script?. Still allow template classes to define it, but
# allows_script? will now warn, and #metadata will include it.
#
# @private
def self.method_added(name)
if name == :allows_script?
return if @defining_allows_script
@defining_allows_script = true
alias_method :real_allows_script?, :allows_script?
define_method(:allows_script?) do
warn ".allows_script? has been replaced with .metadata[:allows_script]"
real_allows_script?
end
@defining_allows_script = false
end
end

protected

# @!group For template implementations
Expand Down
13 changes: 2 additions & 11 deletions test/tilt_metadata.rb → test/tilt_metadata_test.rb
Expand Up @@ -29,23 +29,14 @@ def allows_script?
assert_equal 'text/html', MyTemplate.metadata[:mime_type]
end

test "warns when accessing default_mime_type" do
assert_output '', /default_mime_type has been replaced/ do
assert_equal 'text/html', MyTemplate.default_mime_type
end
test "still allows .default_mime_type" do
assert_equal 'text/html', MyTemplate.default_mime_type
end

test "gracefully handles allows_script?" do
tmpl = MyTemplate.new { '' }
assert_equal true, tmpl.metadata[:allows_script]
end

test "warns when accessing allows_script?" do
tmpl = MyTemplate.new { '' }
assert_output '', /allows_script\? has been replaced/ do
assert_equal true, tmpl.allows_script?
end
end
end
end

0 comments on commit e453e26

Please sign in to comment.