Render category descriptions differently on the categories page

This commit is contained in:
Neil Lalonde 2013-06-14 11:18:27 -04:00
parent bd1b4d3130
commit f62c421c91
5 changed files with 41 additions and 22 deletions

View File

@ -13,12 +13,21 @@
<th class='num'>{{i18n age}}</th>
</tr>
{{#if description_excerpt}}
<tr class="category-description">
<td colspan="3">
{{{description_excerpt}}}
</td>
</tr>
{{/if}}
{{#each topics}}
<tr {{bindAttr class="archived"}}>
<td class='main-link'>
<div class='topic-inset'>
{{topicStatus topic=this}}
{{{topicLink this}}}
{{#if unread}}
<a href="{{unbound lastReadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts unread="unread"}}'>{{unbound unread}}</a>
{{/if}}
@ -40,7 +49,6 @@
{{/if}}
</div>
{{/if}}
</div>
</td>
<td class='num'><span class='badge-posts'>{{number posts_count}}</span></td>

View File

@ -54,6 +54,11 @@
vertical-align: top;
margin-top: 2px;
}
&.category-description {
td {
color: lighten($topic-list-td-color, 5%);
}
}
}
th,
td {

View File

@ -23,7 +23,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base
admin.admin = true
admin.id = -1
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics)
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id)
results = query.list_category(c)
if results.present?
results.topic_ids.each_with_index do |topic_id, idx|

View File

@ -10,6 +10,7 @@ class CategoryDetailedSerializer < ApplicationSerializer
:topics_month,
:topics_year,
:description,
:description_excerpt,
:is_uncategorized
has_many :featured_users, serializer: BasicUserSerializer
@ -39,4 +40,8 @@ class CategoryDetailedSerializer < ApplicationSerializer
return displayable_topics.present?
end
def description_excerpt
PrettyText.excerpt(description,300) if description
end
end

View File

@ -16,7 +16,8 @@ describe CategoryFeaturedTopic do
category.allow(Group[:trust_level_1])
category.save
post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
category_post = PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name)
CategoryFeaturedTopic.feature_topics_for(category)
CategoryFeaturedTopic.count.should == 1