Commit 02eedc73b787da575a4f82214bc89cc985ed8b18
Committed by
Aurélio A. Heckert
1 parent
82c567f2
Exists in
master
and in
23 other branches
Enable Blog in the ArticleBlock
ActionItem2381
Showing
5 changed files
with
35 additions
and
6 deletions
Show diff stats
app/helpers/application_helper.rb
app/models/article_block.rb
| ... | ... | @@ -12,7 +12,7 @@ class ArticleBlock < Block |
| 12 | 12 | block = self |
| 13 | 13 | lambda do |
| 14 | 14 | block_title(block.title) + |
| 15 | - (block.article ? article_to_html(block.article, :gallery_view => false) : _('Article not selected yet.')) | |
| 15 | + (block.article ? article_to_html(block.article, :gallery_view=>false, :inside_block=>block) : _('Article not selected yet.')) | |
| 16 | 16 | end |
| 17 | 17 | end |
| 18 | 18 | ... | ... |
app/models/blog.rb
| ... | ... | @@ -24,8 +24,9 @@ class Blog < Folder |
| 24 | 24 | # FIXME isn't this too much including just to be able to generate some HTML? |
| 25 | 25 | include ActionView::Helpers::TagHelper |
| 26 | 26 | def to_html(options = {}) |
| 27 | + me = self | |
| 27 | 28 | lambda do |
| 28 | - render :file => 'content_viewer/blog_page' | |
| 29 | + render :file => 'content_viewer/blog_page', :locals => { :blog=>me, :inside_block=>options[:inside_block] } | |
| 29 | 30 | end |
| 30 | 31 | end |
| 31 | 32 | ... | ... |
app/views/content_viewer/blog_page.rhtml
| 1 | -<% add_rss_feed_to_head(@page.name, @page.feed.url) if @page.blog? && @page.feed %> | |
| 1 | +<% add_rss_feed_to_head(blog.name, blog.feed.url) if blog.blog? && blog.feed %> | |
| 2 | 2 | |
| 3 | -<%= content_tag('em', _('(external feed was not loaded yet)'), :id => 'external-feed-info', :class => 'metadata') if @page.blog? && @page.external_feed && @page.external_feed.enabled && @page.external_feed.fetched_at.nil? %> | |
| 3 | +<%= content_tag('em', _('(external feed was not loaded yet)'), :id => 'external-feed-info', :class => 'metadata') if blog.blog? && blog.external_feed && blog.external_feed.enabled && blog.external_feed.fetched_at.nil? %> | |
| 4 | 4 | |
| 5 | 5 | <div> |
| 6 | 6 | <div class='blog-description'> |
| 7 | - <%= @page.body %> | |
| 7 | + <%= blog.body %> | |
| 8 | 8 | </div> |
| 9 | 9 | </div> |
| 10 | 10 | <hr class="pre-posts"/> |
| 11 | 11 | <div class="blog-posts"> |
| 12 | - <%= (@page.empty? ? content_tag('em', _('(no posts)')) : list_posts(@posts, @page.visualization_format)) %> | |
| 12 | + <%= | |
| 13 | + posts = @posts | |
| 14 | + if inside_block | |
| 15 | + posts = blog.posts.paginate(:page=>1, :per_page=>1) | |
| 16 | + end | |
| 17 | + (blog.empty? ? content_tag('em', _('(no posts)')) : list_posts(posts, blog.visualization_format)) | |
| 18 | + %> | |
| 13 | 19 | </div> | ... | ... |
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
| 2 | + | |
| 3 | +class BlocksIntegrationTest < ActionController::IntegrationTest | |
| 4 | + | |
| 5 | + should "allow blog as block content" do | |
| 6 | + profile = fast_create(Profile) | |
| 7 | + blog = fast_create(Blog, :name => 'Blog', :profile_id => profile.id) | |
| 8 | + post = fast_create(TinyMceArticle, :name => "A Post", :profile_id => profile.id, :parent_id => blog.id, :body => 'Lorem ipsum dolor sit amet') | |
| 9 | + block = ArticleBlock.new | |
| 10 | + block.article = blog | |
| 11 | + profile.boxes << Box.new | |
| 12 | + profile.boxes.first.blocks << block | |
| 13 | + | |
| 14 | + get "/profile/#{profile.identifier}" | |
| 15 | + assert_match(/Lorem ipsum dolor sit amet/, @response.body) | |
| 16 | + end | |
| 17 | + | |
| 18 | +end | ... | ... |