From 5ead2c2fdaf9043fa5043737c90d4276c95da6a5 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 12 Dec 2013 17:48:26 -0300 Subject: [PATCH] context_content: adapt to new file presenter --- app/models/article.rb | 37 +++++++++++++++++++++---------------- plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb | 2 +- plugins/context_content/lib/context_content_block.rb | 5 +++-- plugins/context_content/test/unit/context_content_block_test.rb | 5 ++++- plugins/context_content/views/blocks/context_content.rhtml | 1 + 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 8650f8a..cde42c6 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -288,6 +288,11 @@ class Article < ActiveRecord::Base 'text-html' end + # TODO Migrate the class method icon_name to instance methods. + def icon_name + self.class.icon_name(self) + end + def mime_type 'text/html' end @@ -350,22 +355,6 @@ class Article < ActiveRecord::Base true end - def folder? - false - end - - def blog? - false - end - - def forum? - false - end - - def uploaded_file? - false - end - def has_posts? false end @@ -597,6 +586,22 @@ class Article < ActiveRecord::Base false end + def folder? + false + end + + def blog? + false + end + + def forum? + false + end + + def uploaded_file? + false + end + def author if versions.empty? last_changed_by diff --git a/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb index b7bedd5..80b897e 100644 --- a/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb +++ b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb @@ -5,7 +5,7 @@ class ContextContentPluginProfileController < ProfileController block = Block.find(params[:id]) p = params[:page].to_i contents = block.contents(profile.articles.find(params[:article_id]), p) - + if contents render :update do |page| page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents} diff --git a/plugins/context_content/lib/context_content_block.rb b/plugins/context_content/lib/context_content_block.rb index 9b35a64..6a37366 100644 --- a/plugins/context_content/lib/context_content_block.rb +++ b/plugins/context_content/lib/context_content_block.rb @@ -46,8 +46,9 @@ class ContextContentBlock < Block if content.image? image_tag(content.public_filename(:thumb)) else - extra_class = content.kind_of?(UploadedFile) ? "extension-#{content.extension}" : '' - content_tag 'div', '', :class => "context-icon icon-#{content.class.icon_name(content)} #{extra_class}" + extra_class = content.uploaded_file? ? "extension-#{content.extension}" : '' + klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ') + content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}" end end end diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb index f43d031..2d3cb06 100644 --- a/plugins/context_content/test/unit/context_content_block_test.rb +++ b/plugins/context_content/test/unit/context_content_block_test.rb @@ -128,19 +128,22 @@ class ContextContentBlockTest < ActiveSupport::TestCase should 'display thumbnail for image content' do content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + content = FilePresenter.for(content) expects(:image_tag).once instance_eval(&@block.content_image(content)) end should 'display div as content image for content that is not a image' do content = fast_create(Folder) + content = FilePresenter.for(content) expects(:content_tag).once instance_eval(&@block.content_image(content)) end should 'display div with extension class for uploaded file that is not a image' do content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) - expects(:content_tag).with('div', '', :class => "context-icon icon-text-plain extension-txt").once + content = FilePresenter.for(content) + expects(:content_tag).with('div', '', :class => "context-icon icon-text icon-text-plain extension-txt").once instance_eval(&@block.content_image(content)) end diff --git a/plugins/context_content/views/blocks/context_content.rhtml b/plugins/context_content/views/blocks/context_content.rhtml index 60c7c9b..88c8f60 100644 --- a/plugins/context_content/views/blocks/context_content.rhtml +++ b/plugins/context_content/views/blocks/context_content.rhtml @@ -1,4 +1,5 @@ <% contents.each do |content| %> + <% content = FilePresenter.for(content) %>
-- libgit2 0.21.2