Commit 57b07ea3c90d269c699c11bea28a434f5060fde0

Authored by Rafael Reggiani Manzo
Committed by Rodrigo Souto
1 parent 555c63fe

Refactored view code generation for gallery_block

The HTMl generation has been removed from the model and should get
handled by BoxesHelper.

There were no tests for the view, so some basic ones were added to
assure this refactor has preserved some basic bahaviour.
plugins/gallery_block/lib/gallery_block.rb
... ... @@ -30,12 +30,4 @@ class GalleryBlock < Block
30 30 def images
31 31 gallery ? gallery.images : []
32 32 end
33   -
34   - def content(args={})
35   - block = self
36   - proc do
37   - render :file => 'gallery_block', :locals => { :block => block }
38   - end
39   - end
40   -
41 33 end
... ...
plugins/gallery_block/test/unit/gallery_block_test.rb
... ... @@ -20,3 +20,38 @@ class GalleryBlockTest < ActiveSupport::TestCase
20 20 end
21 21  
22 22 end
  23 +
  24 +require 'boxes_helper'
  25 +
  26 +class GalleryBlockViewTest < ActionView::TestCase
  27 + include BoxesHelper
  28 +
  29 + def setup
  30 + @community = fast_create(Community)
  31 + end
  32 +
  33 + should 'display the default message for empty gallery' do
  34 + block = GalleryBlock.new
  35 + block.stubs(:owner).returns(@community)
  36 +
  37 + ActionView::Base.any_instance.expects(:block_title).returns("")
  38 +
  39 + content = render_block_content(block)
  40 +
  41 + assert_match /#{_('Please, edit this block and choose some gallery')}/, content
  42 + end
  43 +
  44 + should "display the gallery's content" do
  45 + gallery = fast_create(Gallery, :profile_id => @community.id)
  46 + image = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => @community)
  47 + block = create(GalleryBlock, :gallery_id => gallery.id)
  48 + block.stubs(:owner).returns(@community)
  49 +
  50 + ActionView::Base.any_instance.expects(:block_title).returns("")
  51 +
  52 + content = render_block_content(block)
  53 +
  54 + assert_tag_in_string content, tag: 'img', attributes: {src: image.public_filename(:thumb)}
  55 + assert_tag_in_string content, tag: 'span', content: _('Next')
  56 + end
  57 +end
... ...
plugins/gallery_block/views/blocks/gallery.html.erb 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +<%= block_title(block.title, block.subtitle) %>
  2 +
  3 +<% unless block.images.blank? %>
  4 + <%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %>
  5 + <div class="gallery-block-container">
  6 + <ul class="gallery-list">
  7 + <% block.images.in_groups_of(block.groups_of).each do |group| %>
  8 + <li class="gallery-group">
  9 + <div class="gallery-items">
  10 + <ul>
  11 + <% group.reject{ |x| x.nil? }.each_with_index do |p, i| %>
  12 + <li class="gallery-item">
  13 + <%= link_to image_tag(p.public_filename(:thumb), :alt => p.name, :title => p.name), p.view_url, :class => 'gallery-image' %>
  14 + <div class="gallery-image-info position-<%= i + 1 %>" style="display: none">
  15 + <div class="gallery-image-text">
  16 + <h3><%= p.name %></h3>
  17 + </div>
  18 + </div>
  19 + </li>
  20 + <% end %>
  21 + </ul>
  22 + </div>
  23 + </li>
  24 + <% end %>
  25 + </ul>
  26 + </div>
  27 + <%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %>
  28 + <script type="text/javascript">
  29 + (function($) {
  30 + var options = {
  31 + fx : 'scrollHorz',
  32 + timeout: 0,
  33 + prev: '#block-<%= block.id %> .gallery-block-prev',
  34 + next: '#block-<%= block.id %> .gallery-block-next',
  35 + speed: 2000,
  36 + timeout: <%= block.interval * 1000 %>
  37 + }
  38 + $('#block-<%= block.id %> .gallery-list').cycle(options);
  39 + })(jQuery);
  40 + </script>
  41 + <p class="gallery-block-footer"></p>
  42 +<% else %>
  43 + <em><%= _('Please, edit this block and choose some gallery') %></em>
  44 +<% end %>
... ...
plugins/gallery_block/views/gallery_block.html.erb
... ... @@ -1,44 +0,0 @@
1   -<%= block_title(block.title, block.subtitle) %>
2   -
3   -<% unless block.images.blank? %>
4   - <%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %>
5   - <div class="gallery-block-container">
6   - <ul class="gallery-list">
7   - <% block.images.in_groups_of(block.groups_of).each do |group| %>
8   - <li class="gallery-group">
9   - <div class="gallery-items">
10   - <ul>
11   - <% group.reject{ |x| x.nil? }.each_with_index do |p, i| %>
12   - <li class="gallery-item">
13   - <%= link_to image_tag(p.public_filename(:thumb), :alt => p.name, :title => p.name), p.view_url, :class => 'gallery-image' %>
14   - <div class="gallery-image-info position-<%= i + 1 %>" style="display: none">
15   - <div class="gallery-image-text">
16   - <h3><%= p.name %></h3>
17   - </div>
18   - </div>
19   - </li>
20   - <% end %>
21   - </ul>
22   - </div>
23   - </li>
24   - <% end %>
25   - </ul>
26   - </div>
27   - <%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %>
28   - <script type="text/javascript">
29   - (function($) {
30   - var options = {
31   - fx : 'scrollHorz',
32   - timeout: 0,
33   - prev: '#block-<%= block.id %> .gallery-block-prev',
34   - next: '#block-<%= block.id %> .gallery-block-next',
35   - speed: 2000,
36   - timeout: <%= block.interval * 1000 %>
37   - }
38   - $('#block-<%= block.id %> .gallery-list').cycle(options);
39   - })(jQuery);
40   - </script>
41   - <p class="gallery-block-footer"></p>
42   -<% else %>
43   - <em><%= _('Please, edit this block and choose some gallery') %></em>
44   -<% end %>