Commit 929235dd9375de3b2a7fc33b210abcca2bcb3c8e
1 parent
35feaa05
Exists in
master
and in
29 other branches
ActionItem296: adding custom headerr and footer for profiles and
environments git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2345 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
110 additions
and
6 deletions
Show diff stats
app/helpers/boxes_helper.rb
@@ -22,7 +22,18 @@ module BoxesHelper | @@ -22,7 +22,18 @@ module BoxesHelper | ||
22 | boxes = holder.boxes.first(holder.boxes_limit) | 22 | boxes = holder.boxes.first(holder.boxes_limit) |
23 | content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") | 23 | content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") |
24 | content = main_content if (content.blank?) | 24 | content = main_content if (content.blank?) |
25 | - content_tag('div', content, :class => 'boxes', :id => 'boxes' ) | 25 | + |
26 | + maybe_display_custom_element(holder, :custom_header, :id => 'profile-header') + | ||
27 | + content_tag('div', content, :class => 'boxes', :id => 'boxes' ) + | ||
28 | + maybe_display_custom_element(holder, :custom_footer, :id => 'profile-footer') | ||
29 | + end | ||
30 | + | ||
31 | + def maybe_display_custom_element(holder, element, options = {}) | ||
32 | + if holder.respond_to?(element) | ||
33 | + content_tag('div', holder.send(element), options) | ||
34 | + else | ||
35 | + '' | ||
36 | + end | ||
26 | end | 37 | end |
27 | 38 | ||
28 | def display_box(box, main_content) | 39 | def display_box(box, main_content) |
app/models/profile.rb
@@ -391,4 +391,12 @@ class Profile < ActiveRecord::Base | @@ -391,4 +391,12 @@ class Profile < ActiveRecord::Base | ||
391 | end | 391 | end |
392 | end | 392 | end |
393 | 393 | ||
394 | + def custom_header | ||
395 | + self[:custom_header] || environment.custom_header | ||
396 | + end | ||
397 | + | ||
398 | + def custom_footer | ||
399 | + self[:custom_footer] || environment.custom_footer | ||
400 | + end | ||
401 | + | ||
394 | end | 402 | end |
db/migrate/048_add_custom_header_and_footer_to_profile.rb
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +class AddCustomHeaderAndFooterToProfile < ActiveRecord::Migration | ||
2 | + | ||
3 | + TABLES = [ :profiles, :environments ] | ||
4 | + | ||
5 | + def self.up | ||
6 | + TABLES.each do |item| | ||
7 | + add_column item, :custom_header, :text | ||
8 | + add_column item, :custom_footer, :text | ||
9 | + end | ||
10 | + end | ||
11 | + | ||
12 | + def self.down | ||
13 | + TABLES.each do |item| | ||
14 | + remove_column item, :custom_header | ||
15 | + remove_column item, :custom_footer | ||
16 | + end | ||
17 | + end | ||
18 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 47) do | 12 | +ActiveRecord::Schema.define(:version => 48) do |
13 | 13 | ||
14 | create_table "article_versions", :force => true do |t| | 14 | create_table "article_versions", :force => true do |t| |
15 | t.integer "article_id" | 15 | t.integer "article_id" |
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
71 | t.boolean "virtual", :default => false | 71 | t.boolean "virtual", :default => false |
72 | end | 72 | end |
73 | 73 | ||
74 | - add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" | ||
75 | add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" | 74 | add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" |
75 | + add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" | ||
76 | 76 | ||
77 | create_table "blocks", :force => true do |t| | 77 | create_table "blocks", :force => true do |t| |
78 | t.string "title" | 78 | t.string "title" |
@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
112 | t.boolean "virtual", :default => false | 112 | t.boolean "virtual", :default => false |
113 | end | 113 | end |
114 | 114 | ||
115 | - add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" | ||
116 | add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" | 115 | add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" |
116 | + add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" | ||
117 | 117 | ||
118 | create_table "comments", :force => true do |t| | 118 | create_table "comments", :force => true do |t| |
119 | t.string "title" | 119 | t.string "title" |
@@ -143,6 +143,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -143,6 +143,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
143 | t.boolean "is_default" | 143 | t.boolean "is_default" |
144 | t.text "settings" | 144 | t.text "settings" |
145 | t.text "design_data" | 145 | t.text "design_data" |
146 | + t.text "custom_header" | ||
147 | + t.text "custom_footer" | ||
146 | end | 148 | end |
147 | 149 | ||
148 | create_table "favorite_enteprises_people", :id => false, :force => true do |t| | 150 | create_table "favorite_enteprises_people", :id => false, :force => true do |t| |
@@ -177,8 +179,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -177,8 +179,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
177 | t.datetime "updated_at" | 179 | t.datetime "updated_at" |
178 | end | 180 | end |
179 | 181 | ||
180 | - add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" | ||
181 | add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" | 182 | add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" |
183 | + add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" | ||
182 | 184 | ||
183 | create_table "products", :force => true do |t| | 185 | create_table "products", :force => true do |t| |
184 | t.integer "enterprise_id" | 186 | t.integer "enterprise_id" |
@@ -213,6 +215,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -213,6 +215,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
213 | t.integer "geocode_precision" | 215 | t.integer "geocode_precision" |
214 | t.boolean "enabled", :default => true | 216 | t.boolean "enabled", :default => true |
215 | t.string "nickname", :limit => 16 | 217 | t.string "nickname", :limit => 16 |
218 | + t.text "custom_header" | ||
219 | + t.text "custom_footer" | ||
216 | end | 220 | end |
217 | 221 | ||
218 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | 222 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" |
@@ -245,8 +249,8 @@ ActiveRecord::Schema.define(:version => 47) do | @@ -245,8 +249,8 @@ ActiveRecord::Schema.define(:version => 47) do | ||
245 | t.datetime "created_at" | 249 | t.datetime "created_at" |
246 | end | 250 | end |
247 | 251 | ||
248 | - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" | ||
249 | add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" | 252 | add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" |
253 | + add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" | ||
250 | 254 | ||
251 | create_table "tags", :force => true do |t| | 255 | create_table "tags", :force => true do |t| |
252 | t.string "name" | 256 | t.string "name" |
public/stylesheets/common.css
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class BoxesHelperTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + include BoxesHelper | ||
6 | + include ActionView::Helpers::TagHelper | ||
7 | + | ||
8 | + should 'include profile-specific header' do | ||
9 | + holder = mock | ||
10 | + holder.stubs(:boxes).returns([]) | ||
11 | + holder.stubs(:boxes_limit).returns(0) | ||
12 | + holder.stubs(:custom_header).returns('my custom header') | ||
13 | + | ||
14 | + assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-header' }, :content => 'my custom header' | ||
15 | + end | ||
16 | + | ||
17 | + should 'include profile-specific footer' do | ||
18 | + holder = mock | ||
19 | + holder.stubs(:boxes).returns([]) | ||
20 | + holder.stubs(:boxes_limit).returns(0) | ||
21 | + holder.stubs(:custom_footer).returns('my custom footer') | ||
22 | + | ||
23 | + assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' | ||
24 | + end | ||
25 | + | ||
26 | +end |
test/unit/environment_test.rb
@@ -347,4 +347,12 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -347,4 +347,12 @@ class EnvironmentTest < Test::Unit::TestCase | ||
347 | end | 347 | end |
348 | end | 348 | end |
349 | 349 | ||
350 | + should 'provide custom header' do | ||
351 | + assert_equal 'my header', Environment.new(:custom_header => 'my header').custom_header | ||
352 | + end | ||
353 | + | ||
354 | + should 'provide custom footer' do | ||
355 | + assert_equal 'my footer', Environment.new(:custom_footer => "my footer").custom_footer | ||
356 | + end | ||
357 | + | ||
350 | end | 358 | end |
test/unit/profile_test.rb
@@ -741,6 +741,32 @@ class ProfileTest < Test::Unit::TestCase | @@ -741,6 +741,32 @@ class ProfileTest < Test::Unit::TestCase | ||
741 | assert_equal 'a123456789ab...', p.short_name | 741 | assert_equal 'a123456789ab...', p.short_name |
742 | end | 742 | end |
743 | 743 | ||
744 | + should 'provide custom header' do | ||
745 | + assert_equal 'my custom header', Profile.new(:custom_header => 'my custom header').custom_header | ||
746 | + end | ||
747 | + | ||
748 | + should 'provide custom footer' do | ||
749 | + assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer | ||
750 | + end | ||
751 | + | ||
752 | + should 'provide environment header if profile header is blank' do | ||
753 | + profile = Profile.new | ||
754 | + env = mock | ||
755 | + env.expects(:custom_header).returns('environment header') | ||
756 | + profile.expects(:environment).returns(env) | ||
757 | + | ||
758 | + assert_equal 'environment header', profile.custom_header | ||
759 | + end | ||
760 | + | ||
761 | + should 'provide environment footer if profile footer is blank' do | ||
762 | + profile = Profile.new | ||
763 | + env = mock | ||
764 | + env.expects(:custom_footer).returns('environment footer') | ||
765 | + profile.expects(:environment).returns(env) | ||
766 | + | ||
767 | + assert_equal 'environment footer', profile.custom_footer | ||
768 | + end | ||
769 | + | ||
744 | private | 770 | private |
745 | 771 | ||
746 | def assert_invalid_identifier(id) | 772 | def assert_invalid_identifier(id) |