diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 818832d..2c9c767 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -87,41 +87,38 @@ module BoxesHelper box_decorator == DontMoveBlocks end - def render_block_content(block) - template_name = block.class.name.underscore.gsub('_block', '') - template_filename = "#{template_name}.html.erb" - if File.exists? Rails.root.join('app', 'views', 'blocks', template_filename) - render :file => "blocks/#{template_name}", :locals => { :block => block } - else - nil + def render_block block, prefix = nil, klass = block.class + template_name = klass.name.underscore.sub '_block', '' + begin + render template: "blocks/#{prefix}#{template_name}", locals: { block: block } + rescue ActionView::MissingTemplate + return if klass.superclass === Block + render_block block, prefix, klass.superclass end end - def render_block_footer(block) - template_name = block.class.name.underscore.gsub('_block', '') - template_filename = "#{template_name}.html.erb" - if File.exists? Rails.root.join('app', 'views', 'blocks', 'footers', template_filename) - render :file => "blocks/footers/#{template_name}", :locals => { :block => block } - else - nil - end + def render_block_content block + # FIXME: this conditional should be removed after all + # block footer from plugins methods get refactored into helpers and views. + # They are a failsafe until all of them are done. + return block.content if block.method(:content).owner != Block + render_block block + end + + def render_block_footer block + return block.footer if block.method(:footer).owner != Block + render_block block, 'footers/' end def display_block_content(block, main_content = nil) - # FIXME: these conditionals should be removed after all block footer from plugins methods get refactored into helpers and views. They are a failsafe until all of them are done. content = nil if block.main? content = wrap_main_content(main_content) else - if(block.method(:content).owner != Block) - content = block.content() - else - content = render_block_content(block) - end + content = render_block_content block end result = extract_block_content(content) - # FIXME: this ternary conditional should be removed after all block footer from plugins methods get refactored into helpers and views - footer_content = extract_block_content(block.method(:footer).owner != Block ? block.footer : render_block_footer(block)) + footer_content = extract_block_content(render_block_footer block) unless footer_content.blank? footer_content = content_tag('div', footer_content, :class => 'block-footer-content' ) end diff --git a/test/unit/categories_block_test.rb b/test/unit/categories_block_test.rb index 79d02d1..3a9faca 100644 --- a/test/unit/categories_block_test.rb +++ b/test/unit/categories_block_test.rb @@ -22,7 +22,7 @@ class CategoriesBlockTest < ActiveSupport::TestCase should 'display category block' do block = CategoriesBlock.new - self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block}) + self.expects(:render).with(template: 'blocks/categories', locals: {block: block}) render_block_content(block) end diff --git a/test/unit/featured_products_block_test.rb b/test/unit/featured_products_block_test.rb index 99422be..015cd0d 100644 --- a/test/unit/featured_products_block_test.rb +++ b/test/unit/featured_products_block_test.rb @@ -109,7 +109,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase should 'display feature products block' do block = FeaturedProductsBlock.new - self.expects(:render).with(:file => 'blocks/featured_products', :locals => { :block => block}) + self.expects(:render).with(template: 'blocks/featured_products', locals: {block: block}) render_block_content(block) end diff --git a/test/unit/highlights_block_test.rb b/test/unit/highlights_block_test.rb index 747dc34..9007837 100644 --- a/test/unit/highlights_block_test.rb +++ b/test/unit/highlights_block_test.rb @@ -84,7 +84,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase should 'display highlights block' do block = HighlightsBlock.new - self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block}) + self.expects(:render).with(template: 'blocks/highlights', locals: {block: block}) render_block_content(block) end diff --git a/test/unit/profile_image_block_test.rb b/test/unit/profile_image_block_test.rb index 338031d..19d5e10 100644 --- a/test/unit/profile_image_block_test.rb +++ b/test/unit/profile_image_block_test.rb @@ -11,7 +11,7 @@ class ProfileImageBlockTest < ActiveSupport::TestCase should 'display profile image' do block = ProfileImageBlock.new - self.expects(:render).with(:file => 'blocks/profile_image', :locals => { :block => block }) + self.expects(:render).with(template: 'blocks/profile_image', locals: { block: block }) render_block_content(block) end diff --git a/test/unit/profile_info_block_test.rb b/test/unit/profile_info_block_test.rb index 71c0600..456821b 100644 --- a/test/unit/profile_info_block_test.rb +++ b/test/unit/profile_info_block_test.rb @@ -19,7 +19,7 @@ class ProfileInfoBlockTest < ActiveSupport::TestCase include BoxesHelper should 'display profile information' do - self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block }) + self.expects(:render).with(template: 'blocks/profile_info', locals: { block: block }) render_block_content(block) end diff --git a/test/unit/profile_search_block_test.rb b/test/unit/profile_search_block_test.rb index a43e3d9..76ed7dd 100644 --- a/test/unit/profile_search_block_test.rb +++ b/test/unit/profile_search_block_test.rb @@ -18,14 +18,14 @@ class ProfileSearchBlockTest < ActiveSupport::TestCase block = ProfileSearchBlock.new block.stubs(:owner).returns(person) - self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :block => block }) + self.expects(:render).with(template: 'blocks/profile_search', locals: { block: block }) render_block_content(block) end should 'provide view_title' do person = fast_create(Person) person.boxes << Box.new - block = ProfileSearchBlock.new(:title => 'Title from block') + block = ProfileSearchBlock.new(title: 'Title from block') person.boxes.first.blocks << block block.save! assert_equal 'Title from block', block.view_title -- libgit2 0.21.2