aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJohan Bruning <johan.h.bruning@gmail.com>2011-07-04 16:22:48 +0200
committerJohan Bruning <johan.h.bruning@gmail.com>2011-07-04 16:22:48 +0200
commit8d031ed0c717a32f6a5ad28ccd37e748026dc21c (patch)
treeeee0f8d60909f9000dfb2649909dd1edbb23dc95 /app
parent0e4dbb28e923ca2a9065f23ba433ce74f9f0d42d (diff)
downloadrefinerycms-blog-8d031ed0c717a32f6a5ad28ccd37e748026dc21c.tar.gz
refinerycms-blog-8d031ed0c717a32f6a5ad28ccd37e748026dc21c.tar.bz2
refinerycms-blog-8d031ed0c717a32f6a5ad28ccd37e748026dc21c.zip
Added ability to disable teaser independent of teaser length
I prefer full length articles at all times on blogs and don't like teasers. I added the ability for people to disable teasers so full articles will be shown by default. The teasers can e enabled just like comments from the admin page or trough the normal settings. However not sure if the post partial now is conform standards. Maybe the helper method "blog_post_teaser" could encapsulate the check which is now done in the view and return the full length article instead of a teaser if the teasers are disabled.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/blog/settings_controller.rb10
-rw-r--r--app/helpers/blog_posts_helper.rb4
-rw-r--r--app/models/blog_post.rb13
-rw-r--r--app/views/admin/blog/_submenu.html.erb4
-rw-r--r--app/views/blog/shared/_post.html.erb8
5 files changed, 37 insertions, 2 deletions
diff --git a/app/controllers/admin/blog/settings_controller.rb b/app/controllers/admin/blog/settings_controller.rb
index 7d0c230..5f2b3be 100644
--- a/app/controllers/admin/blog/settings_controller.rb
+++ b/app/controllers/admin/blog/settings_controller.rb
@@ -37,6 +37,16 @@ module Admin
:layout => false
end
end
+
+ def teasers
+ enabled = BlogPost.teaser_enabled_toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
end
end
diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb
index a15de1d..0848632 100644
--- a/app/helpers/blog_posts_helper.rb
+++ b/app/helpers/blog_posts_helper.rb
@@ -42,6 +42,10 @@ module BlogPostsHelper
post.next.present? or post.prev.present?
end
+ def blog_post_teaser_enabled?
+ BlogPost.teasers_enabled?
+ end
+
def blog_post_teaser(post)
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
post.custom_teaser.html_safe
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index ef88f1e..738d25c 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -75,6 +75,19 @@ class BlogPost < ActiveRecord::Base
:scoping => 'blog'
})
end
+
+ def teasers_enabled?
+ RefinerySetting.find_or_set(:teasers_enabled, true, {
+ :scoping => 'blog'
+ })
+ end
+
+ def teaser_enabled_toggle!
+ currently = RefinerySetting.find_or_set(:teasers_enabled, true, {
+ :scoping => 'blog'
+ })
+ RefinerySetting.set(:teasers_enabled, {:value => !currently, :scoping => 'blog'})
+ end
def uncategorized
BlogPost.live.reject { |p| p.categories.any? }
diff --git a/app/views/admin/blog/_submenu.html.erb b/app/views/admin/blog/_submenu.html.erb
index 9d06898..25f437b 100644
--- a/app/views/admin/blog/_submenu.html.erb
+++ b/app/views/admin/blog/_submenu.html.erb
@@ -85,6 +85,10 @@
notification_recipients_admin_blog_settings_url(:dialog => true, :height => 400),
:class => 'user_comment_icon' %>
</li>
+ <li>
+ <%= link_to t('.settings.teasers'),
+ teasers_admin_blog_settings_url, :class => "#{BlogPost.teasers_enabled? ? 'success' : 'failure'}_icon" %>
+ </li>
</ul>
</nav>
diff --git a/app/views/blog/shared/_post.html.erb b/app/views/blog/shared/_post.html.erb
index 0f65e1d..6cda22d 100644
--- a/app/views/blog/shared/_post.html.erb
+++ b/app/views/blog/shared/_post.html.erb
@@ -22,11 +22,15 @@
</section>
</header>
<section class='clearfix'>
- <%= blog_post_teaser(post) %>
+ <% if blog_post_teaser_enabled? %>
+ <%= blog_post_teaser(post) %>
+ <% else %>
+ <%= post.body.html_safe %>
+ <% end %>
</section>
<footer>
<p>
- <%= link_to t('read_more', :scope => 'blog.shared.posts'), blog_post_url(post) %>
+ <%= link_to t('read_more', :scope => 'blog.shared.posts'), blog_post_url(post) if blog_post_teaser_enabled? %>
</p>
<aside class='comment_count'>
<% if BlogPost.comments_allowed? %>