Commit c511a9f9298d2a3aa79e0bc7780e8401ea061477
1 parent
5ead2c2f
Exists in
master
and in
28 other branches
Add plugin namespace in context_content_block
Showing
12 changed files
with
132 additions
and
132 deletions
Show diff stats
plugins/context_content/lib/context_content_block.rb
| ... | ... | @@ -1,96 +0,0 @@ |
| 1 | -class ContextContentBlock < Block | |
| 2 | - | |
| 3 | - settings_items :show_name, :type => :boolean, :default => true | |
| 4 | - settings_items :show_image, :type => :boolean, :default => true | |
| 5 | - settings_items :show_parent_content, :type => :boolean, :default => true | |
| 6 | - settings_items :types, :type => Array, :default => ['UploadedFile'] | |
| 7 | - settings_items :limit, :type => :integer, :default => 6 | |
| 8 | - | |
| 9 | - alias :profile :owner | |
| 10 | - | |
| 11 | - include Noosfero::Plugin::HotSpot | |
| 12 | - | |
| 13 | - def self.description | |
| 14 | - _('Display context content') | |
| 15 | - end | |
| 16 | - | |
| 17 | - def help | |
| 18 | - _('This block displays content based on context.') | |
| 19 | - end | |
| 20 | - | |
| 21 | - def available_content_types | |
| 22 | - @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) | |
| 23 | - checked_types = types.map {|t| t.constantize} | |
| 24 | - checked_types + (@available_content_types - checked_types) | |
| 25 | - end | |
| 26 | - | |
| 27 | - def first_content_types | |
| 28 | - available_content_types.first(first_types_count) | |
| 29 | - end | |
| 30 | - | |
| 31 | - def more_content_types | |
| 32 | - available_content_types.drop(first_types_count) | |
| 33 | - end | |
| 34 | - | |
| 35 | - def first_types_count | |
| 36 | - [2, types.length].max | |
| 37 | - end | |
| 38 | - | |
| 39 | - def types=(new_types) | |
| 40 | - settings[:types] = new_types.reject(&:blank?) | |
| 41 | - end | |
| 42 | - | |
| 43 | - def content_image(content) | |
| 44 | - block = self | |
| 45 | - lambda do | |
| 46 | - if content.image? | |
| 47 | - image_tag(content.public_filename(:thumb)) | |
| 48 | - else | |
| 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}" | |
| 52 | - end | |
| 53 | - end | |
| 54 | - end | |
| 55 | - | |
| 56 | - def contents(page, p=1) | |
| 57 | - return @children unless @children.blank? | |
| 58 | - if page | |
| 59 | - @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) | |
| 60 | - (@children.blank? && show_parent_content) ? contents(page.parent, p) : @children | |
| 61 | - else | |
| 62 | - nil | |
| 63 | - end | |
| 64 | - end | |
| 65 | - | |
| 66 | - def footer | |
| 67 | - block = self | |
| 68 | - lambda do | |
| 69 | - contents = block.contents(@page) | |
| 70 | - if contents | |
| 71 | - content_tag('div', | |
| 72 | - render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") | |
| 73 | - else | |
| 74 | - '' | |
| 75 | - end | |
| 76 | - end | |
| 77 | - end | |
| 78 | - | |
| 79 | - def content(args={}) | |
| 80 | - block = self | |
| 81 | - lambda do | |
| 82 | - contents = block.contents(@page) | |
| 83 | - if !contents.blank? | |
| 84 | - block_title(block.title) + content_tag('div', | |
| 85 | - render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") | |
| 86 | - else | |
| 87 | - '' | |
| 88 | - end | |
| 89 | - end | |
| 90 | - end | |
| 91 | - | |
| 92 | - def cacheable? | |
| 93 | - false | |
| 94 | - end | |
| 95 | - | |
| 96 | -end |
plugins/context_content/lib/context_content_plugin.rb
| ... | ... | @@ -9,8 +9,8 @@ class ContextContentPlugin < Noosfero::Plugin |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def self.extra_blocks |
| 12 | - { | |
| 13 | - ContextContentBlock => { :type => [Person, Community, Enterprise] } | |
| 12 | + { | |
| 13 | + ContextContentPlugin::ContextContentBlock => { :type => [Person, Community, Enterprise] } | |
| 14 | 14 | } |
| 15 | 15 | end |
| 16 | 16 | ... | ... |
plugins/context_content/lib/context_content_plugin/context_content_block.rb
0 → 100644
| ... | ... | @@ -0,0 +1,96 @@ |
| 1 | +class ContextContentPlugin::ContextContentBlock < Block | |
| 2 | + | |
| 3 | + settings_items :show_name, :type => :boolean, :default => true | |
| 4 | + settings_items :show_image, :type => :boolean, :default => true | |
| 5 | + settings_items :show_parent_content, :type => :boolean, :default => true | |
| 6 | + settings_items :types, :type => Array, :default => ['UploadedFile'] | |
| 7 | + settings_items :limit, :type => :integer, :default => 6 | |
| 8 | + | |
| 9 | + alias :profile :owner | |
| 10 | + | |
| 11 | + include Noosfero::Plugin::HotSpot | |
| 12 | + | |
| 13 | + def self.description | |
| 14 | + _('Display context content') | |
| 15 | + end | |
| 16 | + | |
| 17 | + def help | |
| 18 | + _('This block displays content based on context.') | |
| 19 | + end | |
| 20 | + | |
| 21 | + def available_content_types | |
| 22 | + @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) | |
| 23 | + checked_types = types.map {|t| t.constantize} | |
| 24 | + checked_types + (@available_content_types - checked_types) | |
| 25 | + end | |
| 26 | + | |
| 27 | + def first_content_types | |
| 28 | + available_content_types.first(first_types_count) | |
| 29 | + end | |
| 30 | + | |
| 31 | + def more_content_types | |
| 32 | + available_content_types.drop(first_types_count) | |
| 33 | + end | |
| 34 | + | |
| 35 | + def first_types_count | |
| 36 | + [2, types.length].max | |
| 37 | + end | |
| 38 | + | |
| 39 | + def types=(new_types) | |
| 40 | + settings[:types] = new_types.reject(&:blank?) | |
| 41 | + end | |
| 42 | + | |
| 43 | + def content_image(content) | |
| 44 | + block = self | |
| 45 | + lambda do | |
| 46 | + if content.image? | |
| 47 | + image_tag(content.public_filename(:thumb)) | |
| 48 | + else | |
| 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}" | |
| 52 | + end | |
| 53 | + end | |
| 54 | + end | |
| 55 | + | |
| 56 | + def contents(page, p=1) | |
| 57 | + return @children unless @children.blank? | |
| 58 | + if page | |
| 59 | + @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) | |
| 60 | + (@children.blank? && show_parent_content) ? contents(page.parent, p) : @children | |
| 61 | + else | |
| 62 | + nil | |
| 63 | + end | |
| 64 | + end | |
| 65 | + | |
| 66 | + def footer | |
| 67 | + block = self | |
| 68 | + lambda do | |
| 69 | + contents = block.contents(@page) | |
| 70 | + if contents | |
| 71 | + content_tag('div', | |
| 72 | + render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") | |
| 73 | + else | |
| 74 | + '' | |
| 75 | + end | |
| 76 | + end | |
| 77 | + end | |
| 78 | + | |
| 79 | + def content(args={}) | |
| 80 | + block = self | |
| 81 | + lambda do | |
| 82 | + contents = block.contents(@page) | |
| 83 | + if !contents.blank? | |
| 84 | + block_title(block.title) + content_tag('div', | |
| 85 | + render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") | |
| 86 | + else | |
| 87 | + '' | |
| 88 | + end | |
| 89 | + end | |
| 90 | + end | |
| 91 | + | |
| 92 | + def cacheable? | |
| 93 | + false | |
| 94 | + end | |
| 95 | + | |
| 96 | +end | ... | ... |
plugins/context_content/test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -14,7 +14,7 @@ class ContentViewerControllerTest < ActionController::TestCase |
| 14 | 14 | @page = fast_create(Folder, :profile_id => @profile.id) |
| 15 | 15 | |
| 16 | 16 | box = Box.create!(:owner => @profile) |
| 17 | - @block = ContextContentBlock.new(:box => box) | |
| 17 | + @block = ContextContentPlugin::ContextContentBlock.new(:box => box) | |
| 18 | 18 | @block.types = ['TinyMceArticle'] |
| 19 | 19 | @block.limit = 1 |
| 20 | 20 | @block.save! | ... | ... |
plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb
| ... | ... | @@ -6,7 +6,7 @@ class ContextContentPluginProfileControllerTest < ActionController::TestCase |
| 6 | 6 | |
| 7 | 7 | def setup |
| 8 | 8 | @profile = fast_create(Community) |
| 9 | - @block = ContextContentBlock.new | |
| 9 | + @block = ContextContentPlugin::ContextContentBlock.new | |
| 10 | 10 | @block.types = ['TinyMceArticle'] |
| 11 | 11 | @block.limit = 1 |
| 12 | 12 | @block.save! | ... | ... |
plugins/context_content/test/functional/profile_design_controller_test.rb
| ... | ... | @@ -19,7 +19,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 19 | 19 | @page = fast_create(Folder, :profile_id => @profile.id) |
| 20 | 20 | |
| 21 | 21 | box = Box.create!(:owner => @profile) |
| 22 | - @block = ContextContentBlock.new(:box => box) | |
| 22 | + @block = ContextContentPlugin::ContextContentBlock.new(:box => box) | |
| 23 | 23 | @block.types = ['TinyMceArticle'] |
| 24 | 24 | @block.limit = 1 |
| 25 | 25 | @block.save! | ... | ... |
plugins/context_content/test/unit/context_content_block_test.rb
| ... | ... | @@ -4,12 +4,12 @@ class ContextContentBlockTest < ActiveSupport::TestCase |
| 4 | 4 | |
| 5 | 5 | def setup |
| 6 | 6 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) |
| 7 | - @block = ContextContentBlock.create! | |
| 7 | + @block = ContextContentPlugin::ContextContentBlock.create! | |
| 8 | 8 | @block.types = ['TinyMceArticle'] |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | should 'describe itself' do |
| 12 | - assert_not_equal Block.description, ContextContentBlock.description | |
| 12 | + assert_not_equal Block.description, ContextContentPlugin::ContextContentBlock.description | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | should 'has a help' do |
| ... | ... | @@ -170,7 +170,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase |
| 170 | 170 | should 'return box owner on profile method call' do |
| 171 | 171 | profile = fast_create(Community) |
| 172 | 172 | box = Box.create(:owner_type => 'Profile', :owner_id => profile.id) |
| 173 | - block = ContextContentBlock.create!(:box => box) | |
| 173 | + block = ContextContentPlugin::ContextContentBlock.create!(:box => box) | |
| 174 | 174 | assert_equal profile, block.profile |
| 175 | 175 | end |
| 176 | 176 | ... | ... |
plugins/context_content/test/unit/context_content_plugin_test.rb
| ... | ... | @@ -20,7 +20,7 @@ class ContextContentPluginTest < ActiveSupport::TestCase |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | should 'return ContextContentBlock in extra_blocks class method' do |
| 23 | - assert ContextContentPlugin.extra_blocks.keys.include?(ContextContentBlock) | |
| 23 | + assert ContextContentPlugin.extra_blocks.keys.include?(ContextContentPlugin::ContextContentBlock) | |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 26 | should 'return false for class method has_admin_url?' do |
| ... | ... | @@ -28,11 +28,11 @@ class ContextContentPluginTest < ActiveSupport::TestCase |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | should 'ContextContentBlock not available for environment' do |
| 31 | - assert_not_includes plugins.dispatch(:extra_blocks, :type => Environment), ContextContentBlock | |
| 31 | + assert_not_includes plugins.dispatch(:extra_blocks, :type => Environment), ContextContentPlugin::ContextContentBlock | |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | should 'ContextContentBlock available for community' do |
| 35 | - assert_includes plugins.dispatch(:extra_blocks, :type => Community), ContextContentBlock | |
| 35 | + assert_includes plugins.dispatch(:extra_blocks, :type => Community), ContextContentPlugin::ContextContentBlock | |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 38 | should 'has stylesheet' do |
| ... | ... | @@ -41,7 +41,7 @@ class ContextContentPluginTest < ActiveSupport::TestCase |
| 41 | 41 | |
| 42 | 42 | [Person, Community, Enterprise].each do |klass| |
| 43 | 43 | should "ContextContentBlock be available for #{klass.name}" do |
| 44 | - assert_includes plugins.dispatch(:extra_blocks, :type => klass), ContextContentBlock | |
| 44 | + assert_includes plugins.dispatch(:extra_blocks, :type => klass), ContextContentPlugin::ContextContentBlock | |
| 45 | 45 | end |
| 46 | 46 | end |
| 47 | 47 | ... | ... |
plugins/context_content/views/box_organizer/_context_content_block.rhtml
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -<div id='edit-context-content-block'> | |
| 2 | - <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> | |
| 3 | - <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> | |
| 4 | - <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> | |
| 5 | - <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> | |
| 6 | - | |
| 7 | - <br/> | |
| 8 | - <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> | |
| 9 | - <div class="content_types"> | |
| 10 | - <% @block.first_content_types.each do |type| %> | |
| 11 | - <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 12 | - <% end %> | |
| 13 | - <% if !@block.more_content_types.empty? %> | |
| 14 | - <a href="#" onclick="jQuery('.content_types .more').toggle(); return false;"><%= _('more') %></a> | |
| 15 | - <% end %> | |
| 16 | - <div class="more" style="display: none"> | |
| 17 | - <% @block.more_content_types.each do |type| %> | |
| 18 | - <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 19 | - <% end %> | |
| 20 | - </div> | |
| 21 | - </div> | |
| 22 | - <br/> | |
| 23 | -</div> |
plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +<div id='edit-context-content-block'> | |
| 2 | + <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> | |
| 3 | + <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> | |
| 4 | + <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> | |
| 5 | + <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> | |
| 6 | + | |
| 7 | + <br/> | |
| 8 | + <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> | |
| 9 | + <div class="content_types"> | |
| 10 | + <% @block.first_content_types.each do |type| %> | |
| 11 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 12 | + <% end %> | |
| 13 | + <% if !@block.more_content_types.empty? %> | |
| 14 | + <a href="#" onclick="jQuery('.content_types .more').toggle(); return false;"><%= _('more') %></a> | |
| 15 | + <% end %> | |
| 16 | + <div class="more" style="display: none"> | |
| 17 | + <% @block.more_content_types.each do |type| %> | |
| 18 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 19 | + <% end %> | |
| 20 | + </div> | |
| 21 | + </div> | |
| 22 | + <br/> | |
| 23 | +</div> | ... | ... |
plugins/context_content/views/profile_design
plugins/context_content/views/profile_design/context_content_plugin
0 → 120000