Commit 5b613fa4bbb8612e292be4ee99eccb643e28c8dd
Committed by
Joenio Costa
1 parent
d2149070
Exists in
send_email_to_admins
and in
5 other branches
Refactor ContextContentBlock#content_image
This method generates HTML and belongs into a Helper improving MVC compliance.
Showing
5 changed files
with
41 additions
and
35 deletions
Show diff stats
plugins/context_content/lib/context_content_block_helper.rb
0 → 100644
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +module ContextContentBlockHelper | ||
2 | + def content_image(content) | ||
3 | + if content.image? | ||
4 | + image_tag(content.public_filename(:thumb)) | ||
5 | + else | ||
6 | + extra_class = content.uploaded_file? ? "extension-#{content.extension}" : '' | ||
7 | + klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ') | ||
8 | + content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}" | ||
9 | + end | ||
10 | + end | ||
11 | +end |
plugins/context_content/lib/context_content_plugin/context_content_block.rb
@@ -43,19 +43,6 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -43,19 +43,6 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
43 | settings[:types] = new_types.reject(&:blank?) | 43 | settings[:types] = new_types.reject(&:blank?) |
44 | end | 44 | end |
45 | 45 | ||
46 | - def content_image(content) | ||
47 | - block = self | ||
48 | - proc do | ||
49 | - if content.image? | ||
50 | - image_tag(content.public_filename(:thumb)) | ||
51 | - else | ||
52 | - extra_class = content.uploaded_file? ? "extension-#{content.extension}" : '' | ||
53 | - klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ') | ||
54 | - content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}" | ||
55 | - end | ||
56 | - end | ||
57 | - end | ||
58 | - | ||
59 | def contents(page, p=1) | 46 | def contents(page, p=1) |
60 | return @children unless @children.blank? | 47 | return @children unless @children.blank? |
61 | if page | 48 | if page |
plugins/context_content/test/unit/context_content_block_helper_test.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +require 'test_helper' | ||
2 | + | ||
3 | +class ContextContentBlockHelperTest < ActionView::TestCase | ||
4 | + include ContextContentBlockHelper | ||
5 | + | ||
6 | + should 'display thumbnail for image content' do | ||
7 | + content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
8 | + content = FilePresenter.for(content) | ||
9 | + expects(:image_tag).once | ||
10 | + content_image(content) | ||
11 | + end | ||
12 | + | ||
13 | + should 'display div as content image for content that is not a image' do | ||
14 | + content = fast_create(Folder) | ||
15 | + content = FilePresenter.for(content) | ||
16 | + expects(:content_tag).once | ||
17 | + content_image(content) | ||
18 | + end | ||
19 | + | ||
20 | + should 'display div with extension class for uploaded file that is not an image' do | ||
21 | + content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
22 | + content = FilePresenter.for(content) | ||
23 | + expects(:content_tag).with('div', '', :class => "context-icon icon-text icon-text-plain extension-txt").once | ||
24 | + content_image(content) | ||
25 | + end | ||
26 | + | ||
27 | +end |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -134,27 +134,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -134,27 +134,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
134 | assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types | 134 | assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types |
135 | end | 135 | end |
136 | 136 | ||
137 | - should 'display thumbnail for image content' do | ||
138 | - content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
139 | - content = FilePresenter.for(content) | ||
140 | - expects(:image_tag).once | ||
141 | - instance_eval(&@block.content_image(content)) | ||
142 | - end | ||
143 | - | ||
144 | - should 'display div as content image for content that is not a image' do | ||
145 | - content = fast_create(Folder) | ||
146 | - content = FilePresenter.for(content) | ||
147 | - expects(:content_tag).once | ||
148 | - instance_eval(&@block.content_image(content)) | ||
149 | - end | ||
150 | - | ||
151 | - should 'display div with extension class for uploaded file that is not a image' do | ||
152 | - content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
153 | - content = FilePresenter.for(content) | ||
154 | - expects(:content_tag).with('div', '', :class => "context-icon icon-text icon-text-plain extension-txt").once | ||
155 | - instance_eval(&@block.content_image(content)) | ||
156 | - end | ||
157 | - | ||
158 | should 'do not display pagination links if page is nil' do | 137 | should 'do not display pagination links if page is nil' do |
159 | @page = nil | 138 | @page = nil |
160 | assert_equal '', instance_eval(&@block.footer) | 139 | assert_equal '', instance_eval(&@block.footer) |
plugins/context_content/views/blocks/context_content.html.erb
1 | +<% extend ContextContentBlockHelper %> | ||
2 | + | ||
1 | <% if block.use_parent_title %> | 3 | <% if block.use_parent_title %> |
2 | <%= block_title(parent_title, block.subtitle) %> | 4 | <%= block_title(parent_title, block.subtitle) %> |
3 | <% else %> | 5 | <% else %> |
@@ -10,7 +12,7 @@ | @@ -10,7 +12,7 @@ | ||
10 | <span class="item"> | 12 | <span class="item"> |
11 | <a href="<%= url_for(content.view_url) %>"> | 13 | <a href="<%= url_for(content.view_url) %>"> |
12 | <div class="image"> | 14 | <div class="image"> |
13 | - <%= instance_eval(&block.content_image(content)) if block.show_image %> | 15 | + <%= content_image(content) if block.show_image %> |
14 | </div> | 16 | </div> |
15 | <% if block.show_name %> | 17 | <% if block.show_name %> |
16 | <div class="name"><%= content.name %></div> | 18 | <div class="name"><%= content.name %></div> |