Commit 6639c037dd077df006edfac211a195605c1ff251
Committed by
Joenio Costa
1 parent
ba4a9c7a
Exists in
send_email_to_admins
and in
5 other branches
Refactor ContextContentBlock#foorter
It now relies on the BoxesHelper rendering structures which improve MVC compliance by decoupling HTML generation from the model.
Showing
4 changed files
with
41 additions
and
27 deletions
Show diff stats
plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb
@@ -7,9 +7,11 @@ class ContextContentPluginProfileController < ProfileController | @@ -7,9 +7,11 @@ class ContextContentPluginProfileController < ProfileController | ||
7 | contents = block.contents(profile.articles.find(params[:article_id]), p) | 7 | contents = block.contents(profile.articles.find(params[:article_id]), p) |
8 | 8 | ||
9 | if contents | 9 | if contents |
10 | + @page = Article.find(params[:article_id]) | ||
11 | + | ||
10 | render :update do |page| | 12 | render :update do |page| |
11 | - page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents} | ||
12 | - page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] } | 13 | + page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block} |
14 | + page.replace_html "context_content_more_#{block.id}", :file => 'blocks/footers/context_content', :locals => {:block => block} | ||
13 | end | 15 | end |
14 | else | 16 | else |
15 | render :text => "invalid page", :status => 500 | 17 | render :text => "invalid page", :status => 500 |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -123,26 +123,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -123,26 +123,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
123 | assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types | 123 | assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types |
124 | end | 124 | end |
125 | 125 | ||
126 | - should 'do not display pagination links if page is nil' do | ||
127 | - @page = nil | ||
128 | - assert_equal '', instance_eval(&@block.footer) | ||
129 | - end | ||
130 | - | ||
131 | - should 'do not display pagination links if it has until one page' do | ||
132 | - assert_equal '', instance_eval(&@block.footer) | ||
133 | - end | ||
134 | - | ||
135 | - should 'display pagination links if it has more than one page' do | ||
136 | - @block.limit = 2 | ||
137 | - @page = fast_create(Folder) | ||
138 | - article1 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
139 | - article2 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
140 | - article3 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
141 | - expects(:content_tag).once | ||
142 | - expects(:render).with(has_entry(:partial => 'blocks/more')) | ||
143 | - instance_eval(&@block.footer) | ||
144 | - end | ||
145 | - | ||
146 | should 'return box owner on profile method call' do | 126 | should 'return box owner on profile method call' do |
147 | profile = fast_create(Community) | 127 | profile = fast_create(Community) |
148 | box = Box.create!(:owner => profile) | 128 | box = Box.create!(:owner => profile) |
@@ -180,7 +160,34 @@ class ContextContentBlockViewTest < ActionView::TestCase | @@ -180,7 +160,34 @@ class ContextContentBlockViewTest < ActionView::TestCase | ||
180 | article.expects(:view_url).returns('http://test.noosfero.plugins') | 160 | article.expects(:view_url).returns('http://test.noosfero.plugins') |
181 | @block.expects(:contents).with(@page).returns(contents) | 161 | @block.expects(:contents).with(@page).returns(contents) |
182 | @block.expects(:parent_title).with(contents).returns(@page.name) | 162 | @block.expects(:parent_title).with(contents).returns(@page.name) |
183 | - ActionView::Base.any_instance.expects(:block_title).returns(@page.name, @block.subtitle) | 163 | + ActionView::Base.any_instance.expects(:block_title).with(@page.name, @block.subtitle).returns("") |
164 | + | ||
165 | + render_block_content(@block) | ||
166 | + end | ||
167 | + | ||
168 | + should 'do not display pagination links if page is nil' do | ||
169 | + @page = nil | ||
170 | + | ||
171 | + assert_equal "\n", render_block_content(@block) | ||
172 | + end | ||
173 | + | ||
174 | + should 'do not display pagination links if it has until one page' do | ||
175 | + assert_equal "\n", render_block_content(@block) | ||
176 | + end | ||
177 | + | ||
178 | + should 'display pagination links if it has more than one page' do | ||
179 | + @block.limit = 2 | ||
180 | + @page = fast_create(Folder) | ||
181 | + article1 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
182 | + article2 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
183 | + article3 = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
184 | + contents = [article1, article2, article3] | ||
185 | + contents.each do |article| | ||
186 | + article.expects(:view_url).returns('http://test.noosfero.plugins') | ||
187 | + end | ||
188 | + | ||
189 | + ActionView::Base.any_instance.expects(:block_title).returns("") | ||
190 | + @block.expects(:contents).with(@page).returns(contents) | ||
184 | 191 | ||
185 | render_block_content(@block) | 192 | render_block_content(@block) |
186 | end | 193 | end |
plugins/context_content/views/blocks/_more.html.erb
@@ -1,4 +0,0 @@ | @@ -1,4 +0,0 @@ | ||
1 | -<% if contents.total_pages > 1 %> | ||
2 | - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%> | ||
3 | - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%> | ||
4 | -<% end %> |
plugins/context_content/views/blocks/footers/context_content.html.erb
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +<% contents = block.contents(@page) | ||
2 | + unless contents.blank? %> | ||
3 | + <div id="context_content_more_<%= block.id %>" class="more_button"> | ||
4 | + <% if contents.total_pages > 1 %> | ||
5 | + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => @page.id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%> | ||
6 | + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => @page.id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%> | ||
7 | + <% end %> | ||
8 | + </div> | ||
9 | +<% end %> |