Permalink
Browse files

excerpts: pre-process the excerpts with the filter

This allows posts with markup early in the body to not show said markup.
  • Loading branch information...
1 parent 3bff4ad commit 58f615f5754a627397dc7dbf90c865117e17aad6 @Flameeyes committed Feb 17, 2013
Showing with 14 additions and 1 deletion.
  1. +13 −0 app/models/content_base.rb
  2. +1 −1 lib/transforms.rb
View
@@ -70,6 +70,19 @@ def html_map field
content_fields.include? field
end
+ def excerpt_text(length = 160)
+ if respond_to?(:excerpt) and (excerpt || "") != ""
+ text = generate_html(:excerpt, excerpt)
+ else
+ text = html(:all)
+ end
+
+ text = text.strip_html
+
+ return text.slice(0, length) +
+ (text.length > length ? '...' : '');
+ end
+
def invalidates_cache?(on_destruction = false)
@invalidates_cache ||= if on_destruction
just_changed_published_status? || published?
View
@@ -54,7 +54,7 @@ def to_title(item, settings, params)
# Tags for item
s = s.gsub('%title%', item.title) if s =~ /(%title)/ and item.respond_to? :title
- s = s.gsub('%excerpt%', (item.body || '').strip_html.slice(0, 160)) if s =~ /(%excerpt%)/ and item.respond_to? :body
+ s = s.gsub('%excerpt%', item.excerpt_text) if s =~ /(%excerpt%)/ and item.respond_to? :excerpt_text
s = s.gsub('%description%', item.description) if s =~ /(%description%)/ and item.respond_to? :description
s = s.gsub('%name%', item.name) if s =~ /(%name%)/ and item.respond_to? :name
s = s.gsub('%author%', item.name) if s =~ /(%author%)/ and item.respond_to? :name

1 comment on commit 58f615f

mvz commented on 58f615f Feb 22, 2013

This causes as failing spec

Please sign in to comment.