diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index e6b0885..6a76499 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -142,53 +142,6 @@ class DisplayContentBlock < Block documents end - def content(args={}) - block = self - - items = self.docs - - proc do - block.block_title(block.title, block.subtitle) + - content_tag('ul', items.map {|item| - if !item.folder? && item.class != RssFeed - content_sections = '' - read_more_section = '' - tags_section = '' - - block.sections.select { |section| - case section[:value] - when 'publish_date' - content_sections += (block.display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '') - when 'title' - content_sections += (block.display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '') - when 'abstract' - content_sections += (block.display_section?(section) ? (content_tag('div', item.abstract.html_safe , :class => 'lead')) : '' ) - if block.display_section?(section) - read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more') - end - when 'body' - content_sections += (block.display_section?(section) ? (content_tag('div', item.body.html_safe ,:class => 'body')) : '' ) - when 'image' - image_section = image_tag item.image.public_filename if item.image - if !image_section.blank? - content_sections += (block.display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' ) - end - when 'tags' - if !item.tags.empty? - tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("") - content_sections += (block.display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '') - end - end - } - - content_sections += read_more_section if !read_more_section.blank? -#raise sections.inspect - content_tag('li', content_sections.html_safe) - end - }.join(" ").html_safe) - end - end - def url_params params = {:block_id => self.id} if self.owner.is_a?(Profile) diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index 6f197de..6a14691 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -347,53 +347,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase end - should 'list links for all articles title defined in nodes' do - profile = create_user('testuser').person - Article.delete_all - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) - - block = DisplayContentBlock.new - block.sections = [{:value => 'title', :checked => true}] - block.nodes = [a1.id, a2.id] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /.*#{a1.title}<\/a>/, instance_eval(&block.content) - assert_match /.*#{a2.title}<\/a>/, instance_eval(&block.content) - end - - should 'list content for all articles lead defined in nodes' do - profile = create_user('testuser').person - Article.delete_all - a1 = fast_create(TinyMceArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') - a2 = fast_create(TinyMceArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') - - block = DisplayContentBlock.new - block.sections = [{:value => 'abstract', :checked => true}] - block.nodes = [a1.id, a2.id] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /
#{a1.lead}<\/div>/, instance_eval(&block.content) - assert_match /
#{a2.lead}<\/div>/, instance_eval(&block.content) - end - - should 'not crash when referenced article is removed' do - profile = create_user('testuser').person - a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) - - block = DisplayContentBlock.new - block.nodes = [a1.id] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - Article.delete_all - assert_match /
    <\/ul>/, instance_eval(&block.content) - end include ActionView::Helpers include Rails.application.routes.url_helpers @@ -420,48 +373,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert_equal params, block.url_params end - should 'show title if defined by user' do - profile = create_user('testuser').person - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) - - block = DisplayContentBlock.new - block.nodes = [a.id] - block.sections = [{:value => 'title', :checked => true}] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /.*#{a.title}<\/a>/, instance_eval(&block.content) - end - - should 'show abstract if defined by user' do - profile = create_user('testuser').person - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'some abstract') - - block = DisplayContentBlock.new - block.nodes = [a.id] - block.sections = [{:value => 'abstract', :checked => true}] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /#{a.abstract}/, instance_eval(&block.content) - end - - should 'show body if defined by user' do - profile = create_user('testuser').person - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') - - block = DisplayContentBlock.new - block.nodes = [a.id] - block.sections = [{:value => 'body', :checked => true}] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /#{a.body}/, instance_eval(&block.content) - end - should 'display_attribute be true for title by default' do profile = create_user('testuser').person @@ -489,20 +400,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert block.display_section?({:value => 'publish_date', :checked => true}) end - should 'show publishd date if defined by user' do - profile = create_user('testuser').person - a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') - - block = DisplayContentBlock.new - block.nodes = [a.id] - block.sections = [{:value => 'publish_date', :checked => true}] - box = mock() - block.stubs(:box).returns(box) - box.stubs(:owner).returns(profile) - - assert_match /#{a.published_at}/, instance_eval(&block.content) - end - should 'do not save children if a folder is checked' do profile = create_user('testuser').person Article.delete_all @@ -648,6 +545,117 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert_equal [], block.parent_nodes end +end + +require 'boxes_helper' + +class DisplayContentBlockViewTest < ActionView::TestCase + include BoxesHelper + + should 'list links for all articles title defined in nodes' do + profile = create_user('testuser').person + Article.delete_all + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) + + block = DisplayContentBlock.new + block.sections = [{:value => 'title', :checked => true}] + block.nodes = [a1.id, a2.id] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /.*#{a1.title}<\/a>/, render_block_content(block) + assert_match /.*#{a2.title}<\/a>/, render_block_content(block) + end + + should 'list content for all articles lead defined in nodes' do + profile = create_user('testuser').person + Article.delete_all + a1 = fast_create(TinyMceArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') + a2 = fast_create(TinyMceArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') + + block = DisplayContentBlock.new + block.sections = [{:value => 'abstract', :checked => true}] + block.nodes = [a1.id, a2.id] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /
    #{a1.lead}<\/div>/, render_block_content(block) + assert_match /
    #{a2.lead}<\/div>/, render_block_content(block) + end + + should 'not crash when referenced article is removed' do + profile = create_user('testuser').person + a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) + + block = DisplayContentBlock.new + block.nodes = [a1.id] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + Article.delete_all + assert_match /
      <\/ul>/, render_block_content(block) + end + + should 'show title if defined by user' do + profile = create_user('testuser').person + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) + + block = DisplayContentBlock.new + block.nodes = [a.id] + block.sections = [{:value => 'title', :checked => true}] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /.*#{a.title}<\/a>/, render_block_content(block) + end + + should 'show abstract if defined by user' do + profile = create_user('testuser').person + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'some abstract') + + block = DisplayContentBlock.new + block.nodes = [a.id] + block.sections = [{:value => 'abstract', :checked => true}] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /#{a.abstract}/, render_block_content(block) + end + + should 'show body if defined by user' do + profile = create_user('testuser').person + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') + + block = DisplayContentBlock.new + block.nodes = [a.id] + block.sections = [{:value => 'body', :checked => true}] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /#{a.body}/, render_block_content(block) + end + + should 'show publishd date if defined by user' do + profile = create_user('testuser').person + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') + + block = DisplayContentBlock.new + block.nodes = [a.id] + block.sections = [{:value => 'publish_date', :checked => true}] + box = mock() + block.stubs(:box).returns(box) + box.stubs(:owner).returns(profile) + + assert_match /#{a.published_at}/, render_block_content(block) + end + should 'show articles in recent order' do profile = create_user('testuser').person Article.delete_all @@ -663,8 +671,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block.order_by_recent = true - a1_index = instance_eval(&block.content).index(a1.name) - a2_index = instance_eval(&block.content).index(a2.name) + a1_index = render_block_content(block).index(a1.name) + a2_index = render_block_content(block).index(a2.name) assert a2_index < a1_index end @@ -684,8 +692,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block.order_by_recent = false - a1_index = instance_eval(&block.content).index(a1.name) - a2_index = instance_eval(&block.content).index(a2.name) + a1_index = render_block_content(block).index(a1.name) + a2_index = render_block_content(block).index(a2.name) assert a1_index < a2_index end @@ -706,7 +714,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block.order_by_recent = true block.limit_to_show = 1 - a1_index = instance_eval(&block.content).index(a1.name) + a1_index = render_block_content(block).index(a1.name) assert a1_index.nil? end @@ -730,15 +738,15 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) - assert_nil instance_eval(&block.content).index(en_article.name) - assert_nil instance_eval(&block.content).index(en_article2.name) - assert instance_eval(&block.content).index(pt_article.name).present? + assert_nil render_block_content(block).index(en_article.name) + assert_nil render_block_content(block).index(en_article2.name) + assert render_block_content(block).index(pt_article.name).present? FastGettext.stubs(:locale).returns('en') - assert instance_eval(&block.content).index(en_article.name) - assert instance_eval(&block.content).index(en_article2.name) - assert_nil instance_eval(&block.content).index(pt_article.name) + assert render_block_content(block).index(en_article.name) + assert render_block_content(block).index(en_article2.name) + assert_nil render_block_content(block).index(pt_article.name) end should 'replace article with its translation' do @@ -758,12 +766,12 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) - assert_nil instance_eval(&block.content).index(en_article.name) - assert instance_eval(&block.content).index(pt_article.name).present? + assert_nil render_block_content(block).index(en_article.name) + assert render_block_content(block).index(pt_article.name).present? FastGettext.stubs(:locale).returns('en') - assert instance_eval(&block.content).index(en_article.name).present? - assert_nil instance_eval(&block.content).index(pt_article.name) + assert render_block_content(block).index(en_article.name).present? + assert_nil render_block_content(block).index(pt_article.name) end end diff --git a/plugins/display_content/views/blocks/_document.slim b/plugins/display_content/views/blocks/_document.slim new file mode 100644 index 0000000..068853a --- /dev/null +++ b/plugins/display_content/views/blocks/_document.slim @@ -0,0 +1,4 @@ +li + - unless item.folder? || item.class == RssFeed + = render partial: 'blocks/section', collection: block.sections, locals: { block: block, item: item } + = render partial: 'blocks/read_more', locals: { item: item, abstract_section: block.sections.bsearch { |section| section[:value] == 'abstract' }, block: block } \ No newline at end of file diff --git a/plugins/display_content/views/blocks/_read_more.slim b/plugins/display_content/views/blocks/_read_more.slim new file mode 100644 index 0000000..0c68b51 --- /dev/null +++ b/plugins/display_content/views/blocks/_read_more.slim @@ -0,0 +1,3 @@ +- if !abstract_section.nil? && block.display_section?(abstract_section) + div class='read_more' + = link_to(_('Read more'), item.url) diff --git a/plugins/display_content/views/blocks/_section.slim b/plugins/display_content/views/blocks/_section.slim new file mode 100644 index 0000000..cb20f82 --- /dev/null +++ b/plugins/display_content/views/blocks/_section.slim @@ -0,0 +1,22 @@ +- if block.display_section?(section) + - case section[:value] + - when 'publish_date' + div class='published-at' + = show_date(item.published_at, false) + - when 'title' + div class='title' + = link_to(h(item.title), item.url) + - when 'abstract' + div class='lead' + = item.abstract + - when 'body' + div class='body' + = item.body + - when 'image' + - unless item.image || item.image.public_filename + div class='image' + = link_to(image_tag(item.image.public_filename), item.url) + - when 'tags' + - unless item.tags.empty? + div class='tags' + = render partial: 'blocks/tag', collection: item.tags diff --git a/plugins/display_content/views/blocks/_tag.slim b/plugins/display_content/views/blocks/_tag.slim new file mode 100644 index 0000000..bf3c833 --- /dev/null +++ b/plugins/display_content/views/blocks/_tag.slim @@ -0,0 +1,2 @@ +span + = tag.name \ No newline at end of file diff --git a/plugins/display_content/views/blocks/display_content.slim b/plugins/display_content/views/blocks/display_content.slim new file mode 100644 index 0000000..75193cd --- /dev/null +++ b/plugins/display_content/views/blocks/display_content.slim @@ -0,0 +1,4 @@ += block.block_title(block.title, block.subtitle) + +ul + = render partial: 'blocks/document', collection: block.docs, as: :item, locals: { block: block } -- libgit2 0.21.2