diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 7dfe5b3..2261329 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -23,9 +23,9 @@ module BoxesHelper content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") content = main_content if (content.blank?) - maybe_display_custom_element(holder, :custom_header, :id => 'profile-header') + + maybe_display_custom_element(holder, :custom_header_expanded, :id => 'profile-header') + content_tag('div', content, :class => 'boxes', :id => 'boxes' ) + - maybe_display_custom_element(holder, :custom_footer, :id => 'profile-footer') + maybe_display_custom_element(holder, :custom_footer_expanded, :id => 'profile-footer') end def maybe_display_custom_element(holder, element, options = {}) diff --git a/app/models/profile.rb b/app/models/profile.rb index e9ef9b3..060564d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -461,6 +461,10 @@ class Profile < ActiveRecord::Base end def custom_header + self[:custom_header] || environment.custom_header + end + + def custom_header_expanded header = self[:custom_header] || environment.custom_header if header if self.respond_to?(:name) && header.include?('{name}') @@ -472,6 +476,10 @@ class Profile < ActiveRecord::Base end def custom_footer + self[:custom_footer] || environment.custom_footer + end + + def custom_footer_expanded footer = self[:custom_footer] || environment.custom_footer if footer %w[contact_person contact_email contact_phone location address economic_activity city state country zip_code].each do |att| diff --git a/test/unit/boxes_helper_test.rb b/test/unit/boxes_helper_test.rb index 8bdf073..1aece36 100644 --- a/test/unit/boxes_helper_test.rb +++ b/test/unit/boxes_helper_test.rb @@ -9,7 +9,7 @@ class BoxesHelperTest < Test::Unit::TestCase holder = mock holder.stubs(:boxes).returns([]) holder.stubs(:boxes_limit).returns(0) - holder.stubs(:custom_header).returns('my custom header') + holder.stubs(:custom_header_expanded).returns('my custom header') assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-header' }, :content => 'my custom header' end @@ -18,7 +18,7 @@ class BoxesHelperTest < Test::Unit::TestCase holder = mock holder.stubs(:boxes).returns([]) holder.stubs(:boxes_limit).returns(0) - holder.stubs(:custom_footer).returns('my custom footer') + holder.stubs(:custom_footer_expanded).returns('my custom footer') assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 8bd87b6..54a3b03 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -768,7 +768,8 @@ class ProfileTest < Test::Unit::TestCase end should 'provide custom header with variables' do - assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header + assert_equal 'Custom header of {name}', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header + assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header_expanded end should 'provide custom footer' do @@ -780,27 +781,33 @@ class ProfileTest < Test::Unit::TestCase end should 'replace variables on custom_footer' do - assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer + assert_equal '{address}', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer + assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer_expanded end should 'replace variables on custom_footer with title' do - assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer + assert_equal '{Address: address}', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer + assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer_expanded end should 'replace variables on custom_footer when it is nil' do - assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer + assert_equal '{address}', Profile.new(:custom_footer => '{address}').custom_footer + assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer_expanded end should 'replace variables on custom_footer when it is blank' do - assert_equal '', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer + assert_equal '{ZIP Code: zip_code}', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer + assert_equal '', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer_expanded end should 'replace variables in custom_footer when more than one' do - assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer + assert_equal '{Address: address}{Phone: contact_phone}', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer + assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer_expanded end should 'replace variables on custom_footer with title when it is nil' do - assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer + assert_equal '{Address: address}', Profile.new(:custom_footer => '{Address: address}').custom_footer + assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer_expanded end should 'provide environment header if profile header is blank' do @@ -991,7 +998,8 @@ class ProfileTest < Test::Unit::TestCase p.apply_template(template) assert_equal '{name}', p[:custom_header] - assert_equal 'test prof', p.custom_header + assert_equal '{name}', p.custom_header + assert_equal 'test prof', p.custom_header_expanded end should 'copy footer when applying template' do @@ -1003,7 +1011,8 @@ class ProfileTest < Test::Unit::TestCase p.apply_template(template) assert_equal '{address}', p[:custom_footer] - assert_equal 'Profile address', p.custom_footer + assert_equal '{address}', p.custom_footer + assert_equal 'Profile address', p.custom_footer_expanded end should 'copy homepage when applying template' do -- libgit2 0.21.2