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.
This commit is contained in:
parent
0e4dbb28e9
commit
8d031ed0c7
7 changed files with 62 additions and 2 deletions
|
@ -37,6 +37,16 @@ module Admin
|
||||||
:layout => false
|
:layout => false
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,10 @@ module BlogPostsHelper
|
||||||
post.next.present? or post.prev.present?
|
post.next.present? or post.prev.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blog_post_teaser_enabled?
|
||||||
|
BlogPost.teasers_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def blog_post_teaser(post)
|
def blog_post_teaser(post)
|
||||||
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
|
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
|
||||||
post.custom_teaser.html_safe
|
post.custom_teaser.html_safe
|
||||||
|
|
|
@ -75,6 +75,19 @@ class BlogPost < ActiveRecord::Base
|
||||||
:scoping => 'blog'
|
:scoping => 'blog'
|
||||||
})
|
})
|
||||||
end
|
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
|
def uncategorized
|
||||||
BlogPost.live.reject { |p| p.categories.any? }
|
BlogPost.live.reject { |p| p.categories.any? }
|
||||||
|
|
|
@ -85,6 +85,10 @@
|
||||||
notification_recipients_admin_blog_settings_url(:dialog => true, :height => 400),
|
notification_recipients_admin_blog_settings_url(:dialog => true, :height => 400),
|
||||||
:class => 'user_comment_icon' %>
|
:class => 'user_comment_icon' %>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to t('.settings.teasers'),
|
||||||
|
teasers_admin_blog_settings_url, :class => "#{BlogPost.teasers_enabled? ? 'success' : 'failure'}_icon" %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -22,11 +22,15 @@
|
||||||
</section>
|
</section>
|
||||||
</header>
|
</header>
|
||||||
<section class='clearfix'>
|
<section class='clearfix'>
|
||||||
<%= blog_post_teaser(post) %>
|
<% if blog_post_teaser_enabled? %>
|
||||||
|
<%= blog_post_teaser(post) %>
|
||||||
|
<% else %>
|
||||||
|
<%= post.body.html_safe %>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
<footer>
|
<footer>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
<aside class='comment_count'>
|
<aside class='comment_count'>
|
||||||
<% if BlogPost.comments_allowed? %>
|
<% if BlogPost.comments_allowed? %>
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
get :moderation
|
get :moderation
|
||||||
get :comments
|
get :comments
|
||||||
|
get :teasers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -190,4 +190,28 @@ describe BlogPost do
|
||||||
Factory.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
Factory.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".teasers_enabled?" do
|
||||||
|
context "with RefinerySetting teasers_enabled set to true" do
|
||||||
|
before do
|
||||||
|
RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => true })
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be true" do
|
||||||
|
BlogPost.teasers_enabled?.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with RefinerySetting teasers_enabled set to true" do
|
||||||
|
before do
|
||||||
|
RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => false })
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be false" do
|
||||||
|
BlogPost.teasers_enabled?.should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue