diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 81efe1f..8a356d2 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -22,7 +22,18 @@ module BoxesHelper boxes = holder.boxes.first(holder.boxes_limit) content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") content = main_content if (content.blank?) - content_tag('div', content, :class => 'boxes', :id => 'boxes' ) + + maybe_display_custom_element(holder, :custom_header, :id => 'profile-header') + + content_tag('div', content, :class => 'boxes', :id => 'boxes' ) + + maybe_display_custom_element(holder, :custom_footer, :id => 'profile-footer') + end + + def maybe_display_custom_element(holder, element, options = {}) + if holder.respond_to?(element) + content_tag('div', holder.send(element), options) + else + '' + end end def display_box(box, main_content) diff --git a/app/models/profile.rb b/app/models/profile.rb index bbda4e8..ec137da 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -391,4 +391,12 @@ class Profile < ActiveRecord::Base end end + def custom_header + self[:custom_header] || environment.custom_header + end + + def custom_footer + self[:custom_footer] || environment.custom_footer + end + end diff --git a/db/migrate/048_add_custom_header_and_footer_to_profile.rb b/db/migrate/048_add_custom_header_and_footer_to_profile.rb new file mode 100644 index 0000000..779c8bb --- /dev/null +++ b/db/migrate/048_add_custom_header_and_footer_to_profile.rb @@ -0,0 +1,18 @@ +class AddCustomHeaderAndFooterToProfile < ActiveRecord::Migration + + TABLES = [ :profiles, :environments ] + + def self.up + TABLES.each do |item| + add_column item, :custom_header, :text + add_column item, :custom_footer, :text + end + end + + def self.down + TABLES.each do |item| + remove_column item, :custom_header + remove_column item, :custom_footer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e60c149..fa5a0a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 47) do +ActiveRecord::Schema.define(:version => 48) do create_table "article_versions", :force => true do |t| t.integer "article_id" @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 47) do t.boolean "virtual", :default => false end - add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" + add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" create_table "blocks", :force => true do |t| t.string "title" @@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 47) do t.boolean "virtual", :default => false end - add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" + add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" create_table "comments", :force => true do |t| t.string "title" @@ -143,6 +143,8 @@ ActiveRecord::Schema.define(:version => 47) do t.boolean "is_default" t.text "settings" t.text "design_data" + t.text "custom_header" + t.text "custom_footer" end create_table "favorite_enteprises_people", :id => false, :force => true do |t| @@ -177,8 +179,8 @@ ActiveRecord::Schema.define(:version => 47) do t.datetime "updated_at" end - add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" + add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" create_table "products", :force => true do |t| t.integer "enterprise_id" @@ -213,6 +215,8 @@ ActiveRecord::Schema.define(:version => 47) do t.integer "geocode_precision" t.boolean "enabled", :default => true t.string "nickname", :limit => 16 + t.text "custom_header" + t.text "custom_footer" end add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" @@ -245,8 +249,8 @@ ActiveRecord::Schema.define(:version => 47) do t.datetime "created_at" end - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" + add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" create_table "tags", :force => true do |t| t.string "name" diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index cac2f19..d687df7 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -373,3 +373,6 @@ div.sitemap-item a:hover { right: 25px; } +#profile-footer { + clear: both; +} diff --git a/test/unit/boxes_helper_test.rb b/test/unit/boxes_helper_test.rb new file mode 100644 index 0000000..8bdf073 --- /dev/null +++ b/test/unit/boxes_helper_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BoxesHelperTest < Test::Unit::TestCase + + include BoxesHelper + include ActionView::Helpers::TagHelper + + should 'include profile-specific header' do + holder = mock + holder.stubs(:boxes).returns([]) + holder.stubs(:boxes_limit).returns(0) + holder.stubs(:custom_header).returns('my custom header') + + assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-header' }, :content => 'my custom header' + end + + should 'include profile-specific footer' do + holder = mock + holder.stubs(:boxes).returns([]) + holder.stubs(:boxes_limit).returns(0) + holder.stubs(:custom_footer).returns('my custom footer') + + assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' + end + +end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 2800544..5336449 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -347,4 +347,12 @@ class EnvironmentTest < Test::Unit::TestCase end end + should 'provide custom header' do + assert_equal 'my header', Environment.new(:custom_header => 'my header').custom_header + end + + should 'provide custom footer' do + assert_equal 'my footer', Environment.new(:custom_footer => "my footer").custom_footer + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index f55a804..1273509 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -741,6 +741,32 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'a123456789ab...', p.short_name end + should 'provide custom header' do + assert_equal 'my custom header', Profile.new(:custom_header => 'my custom header').custom_header + end + + should 'provide custom footer' do + assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer + end + + should 'provide environment header if profile header is blank' do + profile = Profile.new + env = mock + env.expects(:custom_header).returns('environment header') + profile.expects(:environment).returns(env) + + assert_equal 'environment header', profile.custom_header + end + + should 'provide environment footer if profile footer is blank' do + profile = Profile.new + env = mock + env.expects(:custom_footer).returns('environment footer') + profile.expects(:environment).returns(env) + + assert_equal 'environment footer', profile.custom_footer + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2