Commit 5ead2c2fdaf9043fa5043737c90d4276c95da6a5

Authored by Rodrigo Souto
Committed by Victor Costa
1 parent 4b0c7f1f

context_content: adapt to new file presenter

app/models/article.rb
... ... @@ -288,6 +288,11 @@ class Article < ActiveRecord::Base
288 288 'text-html'
289 289 end
290 290  
  291 + # TODO Migrate the class method icon_name to instance methods.
  292 + def icon_name
  293 + self.class.icon_name(self)
  294 + end
  295 +
291 296 def mime_type
292 297 'text/html'
293 298 end
... ... @@ -350,22 +355,6 @@ class Article < ActiveRecord::Base
350 355 true
351 356 end
352 357  
353   - def folder?
354   - false
355   - end
356   -
357   - def blog?
358   - false
359   - end
360   -
361   - def forum?
362   - false
363   - end
364   -
365   - def uploaded_file?
366   - false
367   - end
368   -
369 358 def has_posts?
370 359 false
371 360 end
... ... @@ -597,6 +586,22 @@ class Article < ActiveRecord::Base
597 586 false
598 587 end
599 588  
  589 + def folder?
  590 + false
  591 + end
  592 +
  593 + def blog?
  594 + false
  595 + end
  596 +
  597 + def forum?
  598 + false
  599 + end
  600 +
  601 + def uploaded_file?
  602 + false
  603 + end
  604 +
600 605 def author
601 606 if versions.empty?
602 607 last_changed_by
... ...
plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb
... ... @@ -5,7 +5,7 @@ class ContextContentPluginProfileController < ProfileController
5 5 block = Block.find(params[:id])
6 6 p = params[:page].to_i
7 7 contents = block.contents(profile.articles.find(params[:article_id]), p)
8   -
  8 +
9 9 if contents
10 10 render :update do |page|
11 11 page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents}
... ...
plugins/context_content/lib/context_content_block.rb
... ... @@ -46,8 +46,9 @@ class ContextContentBlock < Block
46 46 if content.image?
47 47 image_tag(content.public_filename(:thumb))
48 48 else
49   - extra_class = content.kind_of?(UploadedFile) ? "extension-#{content.extension}" : ''
50   - content_tag 'div', '', :class => "context-icon icon-#{content.class.icon_name(content)} #{extra_class}"
  49 + extra_class = content.uploaded_file? ? "extension-#{content.extension}" : ''
  50 + klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ')
  51 + content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}"
51 52 end
52 53 end
53 54 end
... ...
plugins/context_content/test/unit/context_content_block_test.rb
... ... @@ -128,19 +128,22 @@ class ContextContentBlockTest < ActiveSupport::TestCase
128 128  
129 129 should 'display thumbnail for image content' do
130 130 content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
  131 + content = FilePresenter.for(content)
131 132 expects(:image_tag).once
132 133 instance_eval(&@block.content_image(content))
133 134 end
134 135  
135 136 should 'display div as content image for content that is not a image' do
136 137 content = fast_create(Folder)
  138 + content = FilePresenter.for(content)
137 139 expects(:content_tag).once
138 140 instance_eval(&@block.content_image(content))
139 141 end
140 142  
141 143 should 'display div with extension class for uploaded file that is not a image' do
142 144 content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
143   - expects(:content_tag).with('div', '', :class => "context-icon icon-text-plain extension-txt").once
  145 + content = FilePresenter.for(content)
  146 + expects(:content_tag).with('div', '', :class => "context-icon icon-text icon-text-plain extension-txt").once
144 147 instance_eval(&@block.content_image(content))
145 148 end
146 149  
... ...
plugins/context_content/views/blocks/context_content.rhtml
1 1 <% contents.each do |content| %>
  2 + <% content = FilePresenter.for(content) %>
2 3 <span class="item">
3 4 <a href="<%= url_for(content.view_url) %>">
4 5 <div class="image">
... ...