Commit 5ead2c2fdaf9043fa5043737c90d4276c95da6a5
Committed by
Victor Costa
1 parent
4b0c7f1f
Exists in
master
and in
22 other branches
context_content: adapt to new file presenter
Showing
5 changed files
with
30 additions
and
20 deletions
Show diff stats
app/models/article.rb
| @@ -288,6 +288,11 @@ class Article < ActiveRecord::Base | @@ -288,6 +288,11 @@ class Article < ActiveRecord::Base | ||
| 288 | 'text-html' | 288 | 'text-html' |
| 289 | end | 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 | def mime_type | 296 | def mime_type |
| 292 | 'text/html' | 297 | 'text/html' |
| 293 | end | 298 | end |
| @@ -350,22 +355,6 @@ class Article < ActiveRecord::Base | @@ -350,22 +355,6 @@ class Article < ActiveRecord::Base | ||
| 350 | true | 355 | true |
| 351 | end | 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 | def has_posts? | 358 | def has_posts? |
| 370 | false | 359 | false |
| 371 | end | 360 | end |
| @@ -597,6 +586,22 @@ class Article < ActiveRecord::Base | @@ -597,6 +586,22 @@ class Article < ActiveRecord::Base | ||
| 597 | false | 586 | false |
| 598 | end | 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 | def author | 605 | def author |
| 601 | if versions.empty? | 606 | if versions.empty? |
| 602 | last_changed_by | 607 | last_changed_by |
plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb
| @@ -5,7 +5,7 @@ class ContextContentPluginProfileController < ProfileController | @@ -5,7 +5,7 @@ class ContextContentPluginProfileController < ProfileController | ||
| 5 | block = Block.find(params[:id]) | 5 | block = Block.find(params[:id]) |
| 6 | p = params[:page].to_i | 6 | p = params[:page].to_i |
| 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 | render :update do |page| | 10 | render :update do |page| |
| 11 | page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents} | 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,8 +46,9 @@ class ContextContentBlock < Block | ||
| 46 | if content.image? | 46 | if content.image? |
| 47 | image_tag(content.public_filename(:thumb)) | 47 | image_tag(content.public_filename(:thumb)) |
| 48 | else | 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 | end | 52 | end |
| 52 | end | 53 | end |
| 53 | end | 54 | end |
plugins/context_content/test/unit/context_content_block_test.rb
| @@ -128,19 +128,22 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -128,19 +128,22 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
| 128 | 128 | ||
| 129 | should 'display thumbnail for image content' do | 129 | should 'display thumbnail for image content' do |
| 130 | content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 130 | content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
| 131 | + content = FilePresenter.for(content) | ||
| 131 | expects(:image_tag).once | 132 | expects(:image_tag).once |
| 132 | instance_eval(&@block.content_image(content)) | 133 | instance_eval(&@block.content_image(content)) |
| 133 | end | 134 | end |
| 134 | 135 | ||
| 135 | should 'display div as content image for content that is not a image' do | 136 | should 'display div as content image for content that is not a image' do |
| 136 | content = fast_create(Folder) | 137 | content = fast_create(Folder) |
| 138 | + content = FilePresenter.for(content) | ||
| 137 | expects(:content_tag).once | 139 | expects(:content_tag).once |
| 138 | instance_eval(&@block.content_image(content)) | 140 | instance_eval(&@block.content_image(content)) |
| 139 | end | 141 | end |
| 140 | 142 | ||
| 141 | should 'display div with extension class for uploaded file that is not a image' do | 143 | should 'display div with extension class for uploaded file that is not a image' do |
| 142 | content = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | 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 | instance_eval(&@block.content_image(content)) | 147 | instance_eval(&@block.content_image(content)) |
| 145 | end | 148 | end |
| 146 | 149 |
plugins/context_content/views/blocks/context_content.rhtml