Commit ba4a9c7af0b1a1032bd29a8b66c21d65284ab12d
Committed by
Joenio Costa
1 parent
5b613fa4
Exists in
staging
and in
31 other branches
Refactor ContextContentBlock#content
It now relies on the BoxesHelper rendering structures which improve MVC compliance by decoupling HTML generation from the model.
Showing
3 changed files
with
53 additions
and
58 deletions
Show diff stats
plugins/context_content/lib/context_content_plugin/context_content_block.rb
@@ -58,33 +58,6 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -58,33 +58,6 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
58 | contents.first.parent.name | 58 | contents.first.parent.name |
59 | end | 59 | end |
60 | 60 | ||
61 | - def footer | ||
62 | - block = self | ||
63 | - proc do | ||
64 | - contents = block.contents(@page) | ||
65 | - if contents | ||
66 | - content_tag('div', | ||
67 | - render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") | ||
68 | - else | ||
69 | - '' | ||
70 | - end | ||
71 | - end | ||
72 | - end | ||
73 | - | ||
74 | - def content(args={}) | ||
75 | - block = self | ||
76 | - ret = proc do | ||
77 | - contents = block.contents(@page) | ||
78 | - parent_title = block.parent_title(contents) | ||
79 | - if contents.present? | ||
80 | - render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents, :parent_title => parent_title}) | ||
81 | - else | ||
82 | - '' | ||
83 | - end | ||
84 | - end | ||
85 | - ret | ||
86 | - end | ||
87 | - | ||
88 | def cacheable? | 61 | def cacheable? |
89 | false | 62 | false |
90 | end | 63 | end |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -20,17 +20,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -20,17 +20,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
20 | assert_equal nil, @block.contents(nil) | 20 | assert_equal nil, @block.contents(nil) |
21 | end | 21 | end |
22 | 22 | ||
23 | - should 'render nothing if it has no content to show' do | ||
24 | - assert_equal '', instance_eval(&@block.content) | ||
25 | - end | ||
26 | - | ||
27 | - should 'render context content block view' do | ||
28 | - @page = fast_create(Folder) | ||
29 | - article = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
30 | - expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article], :parent_title => @page.name}) | ||
31 | - instance_eval(&@block.content) | ||
32 | - end | ||
33 | - | ||
34 | should 'return children of page' do | 23 | should 'return children of page' do |
35 | folder = fast_create(Folder) | 24 | folder = fast_create(Folder) |
36 | article = fast_create(TinyMceArticle, :parent_id => folder.id) | 25 | article = fast_create(TinyMceArticle, :parent_id => folder.id) |
@@ -166,3 +155,33 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -166,3 +155,33 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
166 | end | 155 | end |
167 | 156 | ||
168 | end | 157 | end |
158 | + | ||
159 | +require 'boxes_helper' | ||
160 | + | ||
161 | +class ContextContentBlockViewTest < ActionView::TestCase | ||
162 | + include BoxesHelper | ||
163 | + | ||
164 | + def setup | ||
165 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
166 | + @block = ContextContentPlugin::ContextContentBlock.create! | ||
167 | + @block.types = ['TinyMceArticle'] | ||
168 | + end | ||
169 | + | ||
170 | + should 'render nothing if it has no content to show' do | ||
171 | + assert_equal "\n", render_block_content(@block) | ||
172 | + end | ||
173 | + | ||
174 | + should 'render context content block view' do | ||
175 | + @page = fast_create(Folder) | ||
176 | + article = fast_create(TinyMceArticle, :parent_id => @page.id) | ||
177 | + contents = [article] | ||
178 | + @block.use_parent_title = true | ||
179 | + | ||
180 | + article.expects(:view_url).returns('http://test.noosfero.plugins') | ||
181 | + @block.expects(:contents).with(@page).returns(contents) | ||
182 | + @block.expects(:parent_title).with(contents).returns(@page.name) | ||
183 | + ActionView::Base.any_instance.expects(:block_title).returns(@page.name, @block.subtitle) | ||
184 | + | ||
185 | + render_block_content(@block) | ||
186 | + end | ||
187 | +end |
plugins/context_content/views/blocks/context_content.html.erb
1 | <% extend ContextContentBlockHelper %> | 1 | <% extend ContextContentBlockHelper %> |
2 | 2 | ||
3 | -<% if block.use_parent_title %> | ||
4 | - <%= block_title(parent_title, block.subtitle) %> | ||
5 | -<% else %> | ||
6 | - <%= block_title(block.title, block.subtitle) %> | ||
7 | -<% end %> | ||
8 | - | ||
9 | -<div class='contents' id='<%="context_content_#{block.id}"%>'> | ||
10 | - <% contents.each do |content| %> | ||
11 | - <% content = FilePresenter.for(content) %> | ||
12 | - <span class="item"> | ||
13 | - <a href="<%= url_for(content.view_url) %>"> | ||
14 | - <div class="image"> | ||
15 | - <%= content_image(content) if block.show_image %> | ||
16 | - </div> | ||
17 | - <% if block.show_name %> | ||
18 | - <div class="name"><%= content.name %></div> | ||
19 | - <% end %> | ||
20 | - </a> | ||
21 | - </span> | 3 | +<% contents = block.contents(@page) |
4 | + unless contents.blank? %> | ||
5 | + <% if block.use_parent_title %> | ||
6 | + <%= block_title(block.parent_title(contents), block.subtitle) %> | ||
7 | + <% else %> | ||
8 | + <%= block_title(block.title, block.subtitle) %> | ||
22 | <% end %> | 9 | <% end %> |
23 | -</div> | 10 | + |
11 | + <div class='contents' id='<%="context_content_#{block.id}"%>'> | ||
12 | + <% contents.each do |content| %> | ||
13 | + <% content = FilePresenter.for(content) %> | ||
14 | + <span class="item"> | ||
15 | + <a href="<%= url_for(content.view_url) %>"> | ||
16 | + <div class="image"> | ||
17 | + <%= content_image(content) if block.show_image %> | ||
18 | + </div> | ||
19 | + <% if block.show_name %> | ||
20 | + <div class="name"><%= content.name %></div> | ||
21 | + <% end %> | ||
22 | + </a> | ||
23 | + </span> | ||
24 | + <% end %> | ||
25 | + </div> | ||
26 | +<% end %> |