Commit dbd92aba770e45343a810430af0e5c29b45fb8a5

Authored by Rodrigo Souto
2 parents 9238c40c 784eed66

Merge branch 'container-block'

Conflicts:
	plugins/display_content/lib/display_content_block.rb
Showing 30 changed files with 809 additions and 30 deletions   Show diff stats
app/helpers/boxes_helper.rb
... ... @@ -102,14 +102,16 @@ module BoxesHelper
102 102  
103 103 result = filter_html(result, block)
104 104  
105   - box_decorator.block_target(block.box, block) +
106   - content_tag('div',
107   - content_tag('div',
  105 + content_tag('div',
  106 + box_decorator.block_target(block.box, block) +
  107 + content_tag('div',
108 108 content_tag('div',
109   - result + footer_content + box_decorator.block_edit_buttons(block),
110   - :class => 'block-inner-2'),
111   - :class => 'block-inner-1'),
112   - options) +
  109 + content_tag('div',
  110 + result + footer_content + box_decorator.block_edit_buttons(block),
  111 + :class => 'block-inner-2'),
  112 + :class => 'block-inner-1'),
  113 + options),
  114 + :class => 'block-outer') +
113 115 box_decorator.block_handle(block)
114 116 end
115 117  
... ... @@ -225,15 +227,11 @@ module BoxesHelper
225 227  
226 228 # DEPRECATED. Do not use this.
227 229 def import_blocks_stylesheets(options = {})
228   - @blocks_css_files ||= current_blocks.map{|b|'blocks/' + block_css_class_name(b)}.uniq
  230 + @blocks_css_files ||= current_blocks.map{|b|'blocks/' + block.class.name.to_css_class}.uniq
229 231 stylesheet_import(@blocks_css_files, options)
230 232 end
231   -
232   - def block_css_class_name(block)
233   - block.class.name.underscore.gsub('_', '-')
234   - end
235 233 def block_css_classes(block)
236   - classes = block_css_class_name(block)
  234 + classes = block.class.name.to_css_class
237 235 classes += ' invisible-block' if block.display == 'never'
238 236 classes
239 237 end
... ...
app/models/article.rb
... ... @@ -157,7 +157,7 @@ class Article < ActiveRecord::Base
157 157 end
158 158  
159 159 def css_class_list
160   - [self.class.name.underscore.dasherize]
  160 + [self.class.name.to_css_class]
161 161 end
162 162  
163 163 def css_class_name
... ...
app/models/article_block.rb
... ... @@ -49,8 +49,8 @@ class ArticleBlock < Block
49 49 end
50 50  
51 51 def available_articles
52   - return [] if self.box.nil? or self.box.owner.nil?
53   - self.box.owner.kind_of?(Environment) ? self.box.owner.portal_community.articles : self.box.owner.articles
  52 + return [] if self.owner.nil?
  53 + self.owner.kind_of?(Environment) ? self.owner.portal_community.articles : self.owner.articles
54 54 end
55 55  
56 56 def posts_per_page
... ...
app/models/box.rb
... ... @@ -3,12 +3,15 @@ class Box < ActiveRecord::Base
3 3 acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\''
4 4 has_many :blocks, :dependent => :destroy, :order => 'position'
5 5  
  6 + include Noosfero::Plugin::HotSpot
  7 +
6 8 def environment
7 9 owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil
8 10 end
9 11  
10 12 def acceptable_blocks
11   - to_css_class_name central? ? Box.acceptable_center_blocks : Box.acceptable_side_blocks
  13 + blocks_classes = central? ? Box.acceptable_center_blocks + plugins.dispatch(:extra_blocks, :position => 1) : Box.acceptable_side_blocks + plugins.dispatch(:extra_blocks, :position => [2, 3])
  14 + to_css_class_name(blocks_classes)
12 15 end
13 16  
14 17 def central?
... ... @@ -74,8 +77,8 @@ class Box < ActiveRecord::Base
74 77  
75 78 private
76 79  
77   - def to_css_class_name(blocks)
78   - blocks.map{ |block| block.to_s.underscore.tr('_', '-') }
  80 + def to_css_class_name(blocks_classes)
  81 + blocks_classes.map{ |block_class| block_class.name.to_css_class }
79 82 end
80 83  
81 84 end
... ...
app/views/box_organizer/_article_block.rhtml
1 1 <div class="article-block-edition">
2   -<% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %>
  2 +<% if @block.owner.kind_of?(Environment) and @block.owner.portal_community.nil? %>
3 3 <p id="no_portal_community">
4 4 <%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %>
5 5 </p>
... ...
lib/noosfero/core_ext/string.rb
... ... @@ -80,6 +80,10 @@ class String
80 80 transliterate.downcase.gsub(/[^\w~\s:;+=_."'`-]/, '').gsub(/[\s:;+=_"'`-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s
81 81 end
82 82  
  83 + def to_css_class
  84 + underscore.dasherize.gsub('/','_')
  85 + end
  86 +
83 87 def fix_i18n
84 88 self.sub('{fn} ', '')
85 89 end
... ...
plugins/container_block/controllers/admin/container_block_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class ContainerBlockPluginAdminController < AdminController
  2 +
  3 + include ContainerBlockPluginController
  4 +
  5 +end
... ...
plugins/container_block/controllers/container_block_plugin_controller.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +module ContainerBlockPluginController
  2 +
  3 + def saveWidths
  4 + container = boxes_holder.blocks.find(params[:id])
  5 + pairs = params[:widths].split('|')
  6 + settings = container.children_settings
  7 + pairs.each do |pair|
  8 + id, width = pair.split(',')
  9 + settings[id.to_i] = {:width => width.to_i}
  10 + end
  11 + container.children_settings = settings
  12 + container.save!
  13 +
  14 + render :text => _('Block successfully saved.')
  15 + end
  16 +
  17 +end
... ...
plugins/container_block/controllers/myprofile/container_block_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class ContainerBlockPluginMyprofileController < MyProfileController
  2 +
  3 + include ContainerBlockPluginController
  4 +
  5 +end
... ...
plugins/container_block/lib/container_block_plugin.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class ContainerBlockPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "Container Block Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that add a container block.")
  9 + end
  10 +
  11 + def self.extra_blocks
  12 + { ContainerBlockPlugin::ContainerBlock => {} }
  13 + end
  14 +
  15 + def stylesheet?
  16 + true
  17 + end
  18 +
  19 +end
... ...
plugins/container_block/lib/container_block_plugin/container_block.rb 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +class ContainerBlockPlugin::ContainerBlock < Block
  2 +
  3 + after_create :create_box
  4 + after_destroy :destroy_children
  5 + after_destroy :destroy_box
  6 +
  7 + settings_items :container_box_id, :type => Integer, :default => nil
  8 + settings_items :children_settings, :type => Hash, :default => {}
  9 +
  10 + def self.description
  11 + _('Container')
  12 + end
  13 +
  14 + def help
  15 + _('This block acts as a container for another blocks')
  16 + end
  17 +
  18 + def layout_template
  19 + nil
  20 + end
  21 +
  22 + def destroy_children
  23 + blocks.destroy_all
  24 + end
  25 +
  26 + def create_box
  27 + box = Box.create!(:owner => owner)
  28 + settings[:container_box_id] = box.id
  29 + save!
  30 + end
  31 +
  32 + def destroy_box
  33 + container_box.destroy
  34 + end
  35 +
  36 + def container_box
  37 + owner.boxes.find(container_box_id)
  38 + end
  39 +
  40 + def block_classes=(classes)
  41 + classes.each { |c| block = c.constantize.create!(:box => container_box) } if classes
  42 + end
  43 +
  44 + def blocks
  45 + container_box.blocks
  46 + end
  47 +
  48 + def child_width(child_id)
  49 + children_settings[child_id][:width] if children_settings[child_id]
  50 + end
  51 +
  52 + def content(args={})
  53 + block = self
  54 + lambda do
  55 + render :file => 'blocks/container.rhtml', :locals => {:block => block}
  56 + end
  57 + end
  58 +
  59 +end
... ...
plugins/container_block/public/images/handle_e.png 0 → 100644

458 Bytes

plugins/container_block/public/images/handle_w.png 0 → 100644

505 Bytes

plugins/container_block/public/images/scalable/handle.svg 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<!-- Created with Inkscape (http://www.inkscape.org/) -->
  3 +
  4 +<svg
  5 + xmlns:dc="http://purl.org/dc/elements/1.1/"
  6 + xmlns:cc="http://creativecommons.org/ns#"
  7 + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  8 + xmlns:svg="http://www.w3.org/2000/svg"
  9 + xmlns="http://www.w3.org/2000/svg"
  10 + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  11 + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  12 + width="210mm"
  13 + height="297mm"
  14 + id="svg2"
  15 + version="1.1"
  16 + inkscape:version="0.48.1 r9760"
  17 + sodipodi:docname="Novo documento 1">
  18 + <defs
  19 + id="defs4" />
  20 + <sodipodi:namedview
  21 + id="base"
  22 + pagecolor="#ffffff"
  23 + bordercolor="#666666"
  24 + borderopacity="1.0"
  25 + inkscape:pageopacity="0.0"
  26 + inkscape:pageshadow="2"
  27 + inkscape:zoom="0.35"
  28 + inkscape:cx="1290.448"
  29 + inkscape:cy="359.98856"
  30 + inkscape:document-units="px"
  31 + inkscape:current-layer="layer1"
  32 + showgrid="false"
  33 + showguides="true"
  34 + inkscape:guide-bbox="true"
  35 + inkscape:window-width="1600"
  36 + inkscape:window-height="825"
  37 + inkscape:window-x="0"
  38 + inkscape:window-y="24"
  39 + inkscape:window-maximized="1" />
  40 + <metadata
  41 + id="metadata7">
  42 + <rdf:RDF>
  43 + <cc:Work
  44 + rdf:about="">
  45 + <dc:format>image/svg+xml</dc:format>
  46 + <dc:type
  47 + rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
  48 + <dc:title></dc:title>
  49 + </cc:Work>
  50 + </rdf:RDF>
  51 + </metadata>
  52 + <g
  53 + inkscape:label="Camada 1"
  54 + inkscape:groupmode="layer"
  55 + id="layer1">
  56 + <path
  57 + style="fill:#b7b7b7;fill-opacity:0.8627451;stroke:#040400;stroke-width:30;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
  58 + d="m 188,288.93362 154.85715,0 c 0,0 -49.16601,97.1789 -54.28571,225.99999 -4.76678,119.94091 53.75423,244.90317 54.28571,241.71431 l -154.85715,0 z"
  59 + id="rect2988"
  60 + inkscape:connector-curvature="0"
  61 + sodipodi:nodetypes="ccsccc"
  62 + inkscape:export-filename="/home/00838716598/participa/noosfero/plugins/container_block/public/images/handle_e.png"
  63 + inkscape:export-xdpi="5.2851791"
  64 + inkscape:export-ydpi="5.2851791" />
  65 + <path
  66 + style="fill:#737373;fill-opacity:0.8627451;stroke:#040400;stroke-width:30;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
  67 + d="m 448.57143,289.79464 c 0,0 -49.16155,97.17891 -54.28125,226 -1.03249,25.97926 0.92026,52.18412 4.59375,77.28125 8.75453,44.36315 22.00361,91.09021 31.90625,123.375 9.12115,24.76788 16.62682,40.25755 17.65625,41.0625 l 0.125,0 96.84375,0 0,-467.71875 -96.84375,0 z"
  68 + id="use3761"
  69 + inkscape:connector-curvature="0"
  70 + inkscape:export-xdpi="5"
  71 + inkscape:export-ydpi="5"
  72 + inkscape:export-filename="/home/00838716598/participa/noosfero/plugins/container_block/public/images/handle_w.png" />
  73 + </g>
  74 +</svg>
... ...
plugins/container_block/public/style.css 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +#content .boxes .container-block-plugin_container-block .container_block_child, .container-block-plugin_container-block .block-outer {
  2 + display: inline-block;
  3 + vertical-align: top;
  4 + margin-left: -2px;
  5 + margin-right: -2px;
  6 +}
  7 +
  8 +.container-block-plugin_container-block .block-target {
  9 + clear: both;
  10 +}
  11 +
  12 +#content .boxes .container-block-plugin_container-block .block .icon-down, #content .boxes .container-block-plugin_container-block .block .icon-down-disabled {
  13 + background-image: url(/designs/icons/default/Tango/16x16/actions/go-next.png);
  14 +}
  15 +
  16 +#content .boxes .container-block-plugin_container-block .block .icon-up, #content .boxes .container-block-plugin_container-block .block .icon-up-disabled {
  17 + background-image: url(/designs/icons/default/Tango/16x16/actions/go-previous.png);
  18 +}
  19 +
  20 +#content .boxes .container-block-plugin_container-block .block {
  21 + outline-offset: -2px;
  22 +}
  23 +
  24 +#content .boxes .container-block-plugin_container-block .block .ui-resizable-handle {
  25 + width: 10px;
  26 + height: 28px;
  27 + z-index: 0;
  28 +}
  29 +
  30 +#content .boxes .container-block-plugin_container-block .block .ui-resizable-e {
  31 + right: -2px;
  32 + background-image: url(/plugins/container_block/images/handle_e.png);
  33 +}
  34 +
  35 +#content .boxes .container-block-plugin_container-block .block .ui-resizable-w {
  36 + left: -2px;
  37 + background-image: url(/plugins/container_block/images/handle_w.png);
  38 +}
  39 +
  40 +.container-block-plugin_container-block .button-bar .icon-resize {
  41 + background-image: url(/designs/icons/default/Tango/16x16/actions/view-fullscreen.png);
  42 +}
... ...
plugins/container_block/test/functional/container_block_environment_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +require 'test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class EnvironmentDesignController
  5 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  6 + def rescue_action(e)
  7 + raise e
  8 + end
  9 +end
  10 +
  11 +class EnvironmentDesignControllerTest < ActionController::TestCase
  12 +
  13 + def setup
  14 + Environment.delete_all
  15 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  16 + @environment.enabled_plugins = ['ContainerBlockPlugin::ContainerBlock']
  17 + @environment.save!
  18 +
  19 + user = create_user('testinguser')
  20 + @environment.add_admin(user.person)
  21 + login_as(user.login)
  22 +
  23 + @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first)
  24 + end
  25 +
  26 + should 'be able to edit ContainerBlock' do
  27 + get :edit, :id => @block.id
  28 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  29 + end
  30 +
  31 + should 'be able to save ContainerBlock' do
  32 + get :edit, :id => @block.id
  33 + post :save, :id => @block.id, :block => {:title => 'Container' }
  34 + @block.reload
  35 + assert_equal 'Container', @block.title
  36 + end
  37 +
  38 + should 'display container children' do
  39 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  40 + get :index
  41 + assert_tag :div, :attributes => { :id => "block-#{c1.id}" }
  42 + end
  43 +
  44 + should 'display hidden children of container block' do
  45 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never')
  46 + get :index
  47 + assert_tag :div, :attributes => { :id => "block-#{c1.id}", :class => 'block raw-html-block invisible-block' }
  48 + end
  49 +
  50 + should 'display button to save widths of container children' do
  51 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  52 + get :index
  53 + assert_tag :a, :attributes => { :class => "button icon-save container_block_save" }
  54 + end
  55 +
  56 + should 'move child of container block to another box' do
  57 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  58 + get :move_block, :id => c1.id, :target => "end-of-box-#{@environment.boxes.last.id}"
  59 + assert_equal @environment.boxes.last, c1.reload.box
  60 + end
  61 +
  62 + should 'move block to inside of a container block' do
  63 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  64 + c2 = RawHTMLBlock.create!(:box => @environment.boxes.last, :html => 'child2 content')
  65 + get :move_block, :id => c2.id, :target => "before-block-#{c1.id}"
  66 + assert_equal @block.container_box, c2.reload.box
  67 + end
  68 +
  69 + should 'move down a container block child' do
  70 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  71 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  72 + get :move_block_down, :id => c1.id
  73 + assert_equal [c2, c1], @block.blocks
  74 + end
  75 +
  76 + should 'move up a container block child' do
  77 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  78 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  79 + get :move_block_up, :id => c2.id
  80 + assert_equal [c2, c1], @block.blocks
  81 + end
  82 +
  83 +end
... ...
plugins/container_block/test/functional/container_block_home_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +require 'test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class HomeController
  5 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  6 + def rescue_action(e)
  7 + raise e
  8 + end
  9 +end
  10 +
  11 +class HomeControllerTest < ActionController::TestCase
  12 +
  13 + def setup
  14 + Environment.delete_all
  15 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  16 + @environment.enabled_plugins = ['ContainerBlockPlugin::ContainerBlock']
  17 + @environment.save!
  18 +
  19 + user = create_user('testinguser')
  20 + @environment.add_admin(user.person)
  21 + login_as(user.login)
  22 +
  23 + box = Box.create!(:owner => @environment)
  24 + @block = ContainerBlockPlugin::ContainerBlock.create!(:box => box)
  25 +
  26 + @environment.boxes = [box]
  27 + end
  28 +
  29 + should 'display ContainerBlock' do
  30 + get :index
  31 + assert_tag :div, :attributes => { :class => 'block container-block-plugin_container-block' }
  32 + end
  33 +
  34 + should 'display container children' do
  35 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  36 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  37 + get :index
  38 + assert_tag :div, :attributes => { :id => "block-#{c1.id}" }
  39 + assert_tag :div, :attributes => { :id => "block-#{c2.id}" }
  40 + end
  41 +
  42 + should 'display style tags for container children' do
  43 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  44 + @block.children_settings = { c1.id => {:width => "123"} }
  45 + @block.save!
  46 + get :index
  47 + assert_match /#block-#{c1.id} \{ width: 123px; \}/, @response.body
  48 + end
  49 +
  50 + should 'do not display hidden children of container' do
  51 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never')
  52 + get :index
  53 + assert_no_tag :div, :attributes => { :id => "block-#{c1.id}" }
  54 + end
  55 +
  56 + should 'do not display button to save widths of container children' do
  57 + get :index
  58 + assert_no_tag :a, :attributes => { :class => "button icon-save container_block_save" }
  59 + end
  60 +
  61 +end
... ...
plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require 'test_helper'
  2 +
  3 +class ContainerBlockPluginAdminControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + Environment.delete_all
  7 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  8 + @environment.enabled_plugins = ['ContainerBlockPlugin::ContainerBlock']
  9 + @environment.save!
  10 +
  11 + user = create_user('testinguser')
  12 + @environment.add_admin(user.person)
  13 + login_as(user.login)
  14 +
  15 + @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first)
  16 + @child1 = Block.create!(:box => @block.container_box)
  17 + @child2 = Block.create!(:box => @block.container_box)
  18 + end
  19 +
  20 + should 'save widths of container block children' do
  21 + xhr :post, :saveWidths, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  22 + assert_response 200
  23 + assert_equal 'Block successfully saved.', @response.body
  24 + @block.reload
  25 + assert_equal 100, @block.child_width(@child1.id)
  26 + assert_equal 200, @block.child_width(@child2.id)
  27 + end
  28 +
  29 +end
... ...
plugins/container_block/test/functional/container_block_plugin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +require 'test_helper'
  2 +
  3 +class ContainerBlockPluginControllerTest < ActionController::TestCase
  4 +
  5 + include ContainerBlockPluginController
  6 +
  7 + def setup
  8 + Environment.delete_all
  9 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  10 + @environment.enabled_plugins = ['ContainerBlockPlugin::ContainerBlock']
  11 + @environment.save!
  12 +
  13 + user = create_user('testinguser')
  14 + @environment.add_admin(user.person)
  15 + login_as(user.login)
  16 +
  17 + @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first)
  18 + @child1 = Block.create!(:box => @block.container_box)
  19 + @child2 = Block.create!(:box => @block.container_box)
  20 + @environment = Environment.find(@environment.id)
  21 + stubs(:boxes_holder).returns(@environment)
  22 + @params = {}
  23 + end
  24 +
  25 + attr_reader :params
  26 +
  27 + should 'save widths of container block children' do
  28 + @params = {:id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"}
  29 + expects(:render).with(:text => 'Block successfully saved.')
  30 + saveWidths
  31 + @block.reload
  32 + assert_equal 100, @block.child_width(@child1.id)
  33 + assert_equal 200, @block.child_width(@child2.id)
  34 + end
  35 +
  36 + should 'do not change child width that is not passed in widths param' do
  37 + @block.children_settings = {@child2.id => {:width => 200}}
  38 + @block.save!
  39 + @params = {:id => @block.id, :widths => "#{@child1.id},100"}
  40 + expects(:render).with(:text => 'Block successfully saved.')
  41 + saveWidths
  42 + @block.reload
  43 + assert_equal 100, @block.child_width(@child1.id)
  44 + assert_equal 200, @block.child_width(@child2.id)
  45 + end
  46 +
  47 +end
... ...
plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require 'test_helper'
  2 +
  3 +class ContainerBlockPluginMyprofileControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + user = create_user('testinguser')
  7 + login_as(user.login)
  8 +
  9 + @profile = fast_create(Community)
  10 + @profile.add_admin(user.person)
  11 + @box = Box.new(:owner => @profile)
  12 +
  13 + @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @box)
  14 + @child1 = Block.create!(:box => @block.container_box)
  15 + @child2 = Block.create!(:box => @block.container_box)
  16 + end
  17 +
  18 + should 'save widths of container block children' do
  19 + xhr :post, :saveWidths, :profile => @profile.identifier, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  20 + assert_response 200
  21 + assert_equal 'Block successfully saved.', @response.body
  22 + @block.reload
  23 + assert_equal 100, @block.child_width(@child1.id)
  24 + assert_equal 200, @block.child_width(@child2.id)
  25 + end
  26 +
  27 +end
... ...
plugins/container_block/test/unit/block_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require 'test_helper'
  2 +
  3 +class BlockTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = fast_create(Environment)
  7 + @box = Box.create!(:owner => @environment)
  8 + @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box)
  9 + end
  10 +
  11 + should 'return environment box if block owner is not a ContainerBlock' do
  12 + block = Block.create!(:box => @box)
  13 + assert_equal @box, block.box
  14 + end
  15 +
  16 + should 'return container box if block owner is a ContainerBlock' do
  17 + block = Block.create!(:box => @container.container_box)
  18 + assert_equal @container.container_box, block.box
  19 + end
  20 +
  21 + should 'return block owner if block onwer is not a ContainerBlock' do
  22 + block = Block.create!(:box => @box)
  23 + assert_equal @environment, block.owner
  24 + end
  25 +
  26 + should 'return environment as owner if block onwer is a ContainerBlock' do
  27 + block = Block.create!(:box => @container.container_box)
  28 + assert_equal @environment, block.owner
  29 + end
  30 +
  31 +end
... ...
plugins/container_block/test/unit/container_block_plugin/container_block_test.rb 0 → 100644
... ... @@ -0,0 +1,92 @@
  1 +require 'test_helper'
  2 +
  3 +class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @block = ContainerBlockPlugin::ContainerBlock.new
  7 + @block.stubs(:owner).returns(Environment.default)
  8 + end
  9 +
  10 + should 'describe yourself' do
  11 + assert !ContainerBlockPlugin::ContainerBlock.description.blank?
  12 + end
  13 +
  14 + should 'has a help' do
  15 + assert !@block.help.blank?
  16 + end
  17 +
  18 + should 'create a box on save' do
  19 + @block.save!
  20 + assert @block.container_box_id
  21 + end
  22 +
  23 + should 'return created box' do
  24 + @block.save!
  25 + assert @block.container_box
  26 + end
  27 +
  28 + should 'create new blocks when receive block classes' do
  29 + @block.save!
  30 + assert_difference Block, :count, 1 do
  31 + @block.block_classes = ['Block']
  32 + end
  33 + assert_equal Block, Block.last.class
  34 + end
  35 +
  36 + should 'do not create blocks when nothing is passed as block classes' do
  37 + @block.save!
  38 + assert_no_difference Block, :count do
  39 + @block.block_classes = []
  40 + end
  41 + end
  42 +
  43 + should 'do not create blocks when nil is passed as block classes' do
  44 + @block.save!
  45 + assert_no_difference Block, :count do
  46 + @block.block_classes = nil
  47 + end
  48 + end
  49 +
  50 + should 'return a list of blocks associated with the container block' do
  51 + @block.save!
  52 + @block.block_classes = ['Block', 'Block']
  53 + assert_equal [Block, Block], @block.blocks.map(&:class)
  54 + end
  55 +
  56 + should 'return child width' do
  57 + @block.children_settings = {1 => {:width => 10} }
  58 + @block.save!
  59 + assert_equal 10, @block.child_width(1)
  60 + end
  61 +
  62 + should 'return nil in width if child do not exists' do
  63 + @block.children_settings = {2 => {:width => 10} }
  64 + @block.save!
  65 + assert_equal nil, @block.child_width(1)
  66 + end
  67 +
  68 + should 'return nil at layout_template' do
  69 + assert_equal nil, @block.layout_template
  70 + end
  71 +
  72 + should 'return children blocks that have container_box as box' do
  73 + @block.save!
  74 + child = Block.create!(:box_id => @block.container_box.id)
  75 + assert_equal [child], @block.blocks
  76 + end
  77 +
  78 + should 'destroy chilrend when container is removed' do
  79 + @block.save!
  80 + child = Block.create!(:box_id => @block.container_box.id)
  81 + @block.destroy
  82 + assert !Block.exists?(child.id)
  83 + end
  84 +
  85 + should 'destroy box when container is removed' do
  86 + @block.save!
  87 + assert_difference Box, :count, -1 do
  88 + @block.destroy
  89 + end
  90 + end
  91 +
  92 +end
... ...
plugins/container_block/test/unit/container_block_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require 'test_helper'
  2 +
  3 +class ContainerBlockPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @plugin = ContainerBlockPlugin.new
  7 + end
  8 +
  9 + should 'has a name' do
  10 + assert !ContainerBlockPlugin.plugin_name.blank?
  11 + end
  12 +
  13 + should 'has a description' do
  14 + assert !ContainerBlockPlugin.plugin_description.blank?
  15 + end
  16 +
  17 + should 'add a block' do
  18 + assert_equal [ContainerBlockPlugin::ContainerBlock], ContainerBlockPlugin.extra_blocks.keys
  19 + end
  20 +
  21 + should 'has stylesheet' do
  22 + assert @plugin.stylesheet?
  23 + end
  24 +
  25 +end
... ...
plugins/container_block/test/unit/environment_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require 'test_helper'
  2 +
  3 +class EnvironmentTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = fast_create(Environment)
  7 +
  8 + @box = Box.create!(:owner => @environment)
  9 + @block = Block.create!(:box => @box)
  10 +
  11 + @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box)
  12 + end
  13 +
  14 + should 'return blocks as usual' do
  15 + assert_equal [@block, @container], @environment.blocks
  16 + end
  17 +
  18 + should 'return blocks with container children' do
  19 + child = Block.create!(:box => @container.container_box)
  20 + assert_equal [@block, @container, child], @environment.blocks
  21 + end
  22 +
  23 + should 'return block with id at find method' do
  24 + assert_equal @block, @environment.blocks.find(@block.id)
  25 + end
  26 +
  27 + should 'return child block with id at find method' do
  28 + child = Block.create!(:box => @container.container_box)
  29 + assert_equal child, @environment.blocks.find(child.id)
  30 + end
  31 +
  32 +end
... ...
plugins/container_block/test/unit/profile_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require 'test_helper'
  2 +
  3 +class ProfileTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Profile)
  7 +
  8 + @box = Box.create!(:owner => @profile)
  9 + @block = Block.create!(:box => @box)
  10 +
  11 + @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box)
  12 + end
  13 +
  14 + should 'return blocks as usual' do
  15 + assert_equal [@block, @container], @profile.blocks
  16 + end
  17 +
  18 + should 'return blocks with container children' do
  19 + child = Block.create!(:box => @container.container_box)
  20 + assert_equal [@block, @container, child], @profile.blocks
  21 + end
  22 +
  23 + should 'return block with id at find method' do
  24 + assert_equal @block, @profile.blocks.find(@block.id)
  25 + end
  26 +
  27 + should 'return child block with id at find method' do
  28 + child = Block.create!(:box => @container.container_box)
  29 + assert_equal child, @profile.blocks.find(child.id)
  30 + end
  31 +
  32 +end
... ...
plugins/container_block/views/blocks/container.rhtml 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +<% edit_mode = @controller.send(:boxes_editor?) && @controller.send(:uses_design_blocks?) %>
  2 +<% box_decorator = edit_mode ? self : BoxesHelper::DontMoveBlocks %>
  3 +
  4 +
  5 +<div class="box" id="box-<%= block.container_box.id %>">
  6 + <%= display_box_content(block.container_box, nil) %>
  7 + <div class="clear"></div>
  8 +</div>
  9 +<div class="clear"></div>
  10 +
  11 +<style>
  12 + <% box_decorator.select_blocks(block.blocks, { :article => @page, :request_path => request.path, :locale => locale }).each do |child| %>
  13 + #block-<%=block.id%> #block-<%=child.id%> { width: <%= block.child_width(child.id) %>px; }
  14 + <% end %>
  15 +</style>
  16 +
  17 +<% if edit_mode %>
  18 + <div class="button-bar">
  19 + <a href="#" onclick="toggleMoveContainerChildren(<%= block.id %>, <%= block.container_box.id %>); return false;" class="button icon-resize" title=<%= _('Resize blocks').to_json %>></a>
  20 + <%= link_to_remote '', :url => { :controller => @controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id },
  21 + :with => "containerChildrenWidth(#{block.id}, #{block.container_box.id})",
  22 + :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}", :title => _('Save') },
  23 + :loading => "open_loading(DEFAULT_LOADING_MESSAGE);",
  24 + :loaded => "close_loading();",
  25 + :complete => "display_notice(request.responseText);"%>
  26 + </div>
  27 +
  28 + <script>
  29 + function toggleMoveContainerChildren(container, box) {
  30 + var div = jQuery('#box-'+box+' > .block-outer > .block');
  31 + var targetDiv = jQuery('#box-'+box+' .block-outer .block-target');
  32 + if(div.is('.ui-resizable')) {
  33 + targetDiv.show();
  34 + div.find("a").die("click");
  35 + div.resizable('destroy');
  36 + } else {
  37 + targetDiv.hide();
  38 + div.find("a").live("click", function(e) {
  39 + e.preventDefault();
  40 + });
  41 + div.resizable({
  42 + handles: 'e, w',
  43 + containment: '#block-'+container+' .block-inner-2',
  44 + resize: function( event, ui ) {
  45 + ui.element.height('auto');
  46 + }
  47 + });
  48 + }
  49 + }
  50 +
  51 + function containerChildrenWidth(container, box) {
  52 + widths = "";
  53 + jQuery('#box-'+box+' > .block-outer > .block').each(function(i) {
  54 + childId = jQuery(this).attr('id').match(/block-(\d+)/)[1];
  55 + widths+=childId+","+jQuery(this).width()+"|";
  56 + });
  57 + return "widths="+widths;
  58 + }
  59 + </script>
  60 +<% end %>
... ...
plugins/display_content/lib/display_content_block.rb
... ... @@ -120,12 +120,12 @@ class DisplayContentBlock &lt; Block
120 120 protected
121 121  
122 122 def holder
123   - return nil if self.box.nil? || self.box.owner.nil?
124   - if self.box.owner.kind_of?(Environment)
125   - return nil if self.box.owner.portal_community.nil?
126   - self.box.owner.portal_community
  123 + return nil if self.box.nil? || self.owner.nil?
  124 + if self.owner.kind_of?(Environment)
  125 + return nil if self.owner.portal_community.nil?
  126 + self.owner.portal_community
127 127 else
128   - self.box.owner
  128 + self.owner
129 129 end
130 130 end
131 131  
... ...
test/unit/box_test.rb
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2  
3 3 class BoxTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  7 + end
  8 +
4 9 should 'retrieve environment based on owner' do
5 10 profile = fast_create(Profile)
6 11 box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile')
... ... @@ -84,4 +89,34 @@ class BoxTest &lt; ActiveSupport::TestCase
84 89 assert blocks.include?('tags-block')
85 90 end
86 91  
  92 + should 'list plugin block as allowed for box at position 1' do
  93 + class SomePlugin < Noosfero::Plugin
  94 + def self.extra_blocks
  95 + { PluginBlock => {:position => 1} }
  96 + end
  97 + end
  98 + class PluginBlock < Block
  99 + def self.to_s; 'plugin-block'; end
  100 + end
  101 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
  102 +
  103 + blocks = Box.new(:position => 1).acceptable_blocks
  104 + assert blocks.include?('plugin-block')
  105 + end
  106 +
  107 + should 'list plugin block as allowed for box at position 2' do
  108 + class SomePlugin < Noosfero::Plugin
  109 + def self.extra_blocks
  110 + { PluginBlock => {:position => 2} }
  111 + end
  112 + end
  113 + class PluginBlock < Block
  114 + def self.to_s; 'plugin-block'; end
  115 + end
  116 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
  117 +
  118 + blocks = Box.new(:position => 2).acceptable_blocks
  119 + assert blocks.include?('plugin-block')
  120 + end
  121 +
87 122 end
... ...
test/unit/boxes_helper_test.rb
... ... @@ -96,11 +96,6 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
96 96 assert_tag_in_string insert_boxes('main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer'
97 97 end
98 98  
99   - should 'calculate CSS class names correctly' do
100   - assert_equal 'slideshow-block', block_css_class_name(SlideshowBlock.new)
101   - assert_equal 'main-block', block_css_class_name(MainBlock.new)
102   - end
103   -
104 99 should 'add invisible CSS class name for invisible blocks' do
105 100 assert !block_css_classes(Block.new(:display => 'always')).split.any? { |item| item == 'invisible-block'}
106 101 assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'}
... ...
test/unit/string_core_ext_test.rb
... ... @@ -33,4 +33,8 @@ class StringCoreExtTest &lt; ActiveSupport::TestCase
33 33 assert_equal 'aaaaaaAAAAAeeeeEEOOoocaaaiIIiuuyYnNcC', 'ªáàäâåÁÀÄÂÅéèëêÊËÖÔöôçäàâîÏÎïûüÿŸñÑçÇ'.transliterate
34 34 end
35 35  
  36 + should 'convert to css class' do
  37 + assert_equal 'spaceship-propulsion_warp-core', "SpaceshipPropulsion::WarpCore".to_css_class
  38 + end
  39 +
36 40 end
... ...