Skip to content

Commit

Permalink
add excerpts functionality using <!--more--> tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cobyism committed Apr 27, 2012
1 parent f5ce330 commit 7d1981e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ def to_param
def external?
!url.blank?
end

def has_more_tag
content =~ /<!--\s*more\s*-->/i ? true : false
end

def excerpt
if content.index(/<!--\s*more\s*-->/i)
content.split(/<!--\s*more\s*-->/i)[0]
else
content
end
end
end
7 changes: 6 additions & 1 deletion app/views/posts/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<h1><% if @single_post %><%= post.title %><% else %><%= link_to post.title, post.slug %><% end %></h1>
<%- end -%>
<% if post.content %><%= markdown(post.content).to_html.html_safe %><% end %>
<% if post.has_more_tag && !@single_post %>
<% if post.excerpt %><%= markdown(post.excerpt).to_html.html_safe %><% end %>
<%= link_to "Read More", post.slug, :class => "button" %>
<% else %>
<% if post.content %><%= markdown(post.content).to_html.html_safe %><% end %>
<% end %>
<%- if is_admin? -%>
<ul class="actions">
Expand Down

0 comments on commit 7d1981e

Please sign in to comment.