Skip to content

Commit

Permalink
Remove deprecated Hanami::View::Rendering::LayoutScope#content
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Mar 13, 2017
1 parent 953255f commit ad30022
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 85 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@
View layer for Hanami

## v1.0.0.beta2 (unreleased)
### Changed
- [Luca Guidi] Remove deprecated `Hanami::View::Rendering::LayoutScope#content`

## v1.0.0.beta1 - 2017-02-14
### Added
Expand Down
50 changes: 0 additions & 50 deletions lib/hanami/view/rendering/layout_scope.rb
@@ -1,6 +1,5 @@
require 'hanami/view/rendering/null_local'
require 'hanami/utils/escape'
require 'hanami/utils/deprecation'

module Hanami
module View
Expand Down Expand Up @@ -118,55 +117,6 @@ def locals
@locals || @scope.locals
end

# Returns a content for the given key, by trying to invoke on the current
# scope, a method with the same name.
#
# The scope is made of locals and concrete methods from view and layout.
#
# @param key [Symbol] a method to invoke within current scope
# @return [String,NilClass] returning content if scope respond to the
# requested method
#
# @deprecated Use {#local} instead
# @since 0.4.1
#
# @example
# # Given the following layout template
#
# <!doctype HTML>
# <html>
# <!-- ... -->
# <body>
# <!-- ... -->
# <%= content :footer %>
# </body>
# </html>
#
# # Case 1:
# # Products::Index doesn't respond to #footer, content will return nil
# #
# # Case 2:
# # Products::Show responds to #footer, content will send back
# # #footer returning value
#
# module Products
# class Index
# include Hanami::View
# end
#
# class Show
# include Hanami::View
#
# def footer
# "contents for footer"
# end
# end
# end
def content(key)
Utils::Deprecation.new("#content is deprecated, please use #local")
__send__(key) if respond_to?(key)
end

# It tries to invoke a method for the view or a local for the given key.
# If the lookup fails, it returns a null object.
#
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/templates/store/templates/store.html.erb
Expand Up @@ -4,7 +4,6 @@
<title>Store</title>
<%= javascript_tag 'application' %>
<%= local :head %>
<%= content :foo %>
</head>

<body>
Expand Down
45 changes: 11 additions & 34 deletions test/layout_test.rb
Expand Up @@ -26,54 +26,31 @@ class MissingLayout
end

it 'concrete methods are available in layout template' do
with_silenced_deprecation do
rendered = Store::Views::Home::Index.render(format: :html)
rendered.must_match %(script)
rendered.must_match %(yeah)
end
rendered = Store::Views::Home::Index.render(format: :html)
rendered.must_match %(script)
rendered.must_match %(yeah)
end

it 'methods defined in layout are available from the view' do
with_silenced_deprecation do
rendered = Store::Views::Home::Index.render(format: :html)
rendered.must_match %(Joe Blogs)
end
rendered = Store::Views::Home::Index.render(format: :html)
rendered.must_match %(Joe Blogs)
end

it 'renders content to return value from view' do
with_silenced_deprecation do
rendered = Store::Views::Products::Show.render(format: :html)
rendered.must_match %(Product)
rendered.must_match %(<script src="/javascripts/product-tracking.js"></script>)
end
rendered = Store::Views::Products::Show.render(format: :html)
rendered.must_match %(Product)
rendered.must_match %(<script src="/javascripts/product-tracking.js"></script>)
end

it 'renders content to return value from layout' do
with_silenced_deprecation do
rendered = Store::Views::Products::Show.render(format: :html)
rendered.must_match %(Product)
rendered.must_match %(<meta name="hanamirb-version" content="0.3.1">)
end
end

it 'deprecates #content' do
_, err = capture_io do
Store::Views::Products::Show.render(format: :html)
end

err.must_match "#content is deprecated, please use #local"
rendered = Store::Views::Products::Show.render(format: :html)
rendered.must_match %(Product)
rendered.must_match %(<meta name="hanamirb-version" content="0.3.1">)
end

describe 'disable layout in view' do
it 'return NullLayout' do
DisabledLayoutView.layout.must_equal Hanami::View::Rendering::NullLayout
end
end

private

require 'hanami/utils/io'
def with_silenced_deprecation(&blk)
Hanami::Utils::IO.silence_warnings(&blk)
end
end

0 comments on commit ad30022

Please sign in to comment.