Skip to content

Instantly share code, notes, and snippets.

@1gor
Created July 18, 2012 07:21

Revisions

  1. 1gor revised this gist Jul 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ module Helpers
    def article_summary(item, read_more_text="Read more...", separator="<!--MORE-->")
    summary,body = item.compiled_content.split(separator)
    return item.compiled_content unless body
    link = link_to( (item[:read_more] || read_more_text), item.path, :class=>'read_more' )
    link = link_to( (item[:read_more] || read_more_text), item.path, :class=>'readmore' )
    return summary+"<p class='readmore'>#{link}</p>"
    end
    end
  2. 1gor created this gist Jul 18, 2012.
    29 changes: 29 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    module My
    module Helpers
    # Nanoc helper to display blog post summary and a link to the full post.
    # Used inside <% sorted_articles.each do |item| %>...<% end %> block etc.
    #
    # @example Put the following in your layout:
    #
    # <%= article_summary(item,'Read the full article>>') %>
    #
    # To customize the link text you can add 'read_more' attribute to your
    # item metadata or pass the string to the helper, as above.
    #
    # Add <!--MORE--> separator somewhere in your item to split it. Otherwise
    # the full article text is displayed.
    #
    # @param [String] item The blog post
    #
    # @param [String] read_more_text The 'Read more...' text
    #
    # @param [String] separator Separates item summary from item body. Defaults to <!--MORE-->
    #
    def article_summary(item, read_more_text="Read more...", separator="<!--MORE-->")
    summary,body = item.compiled_content.split(separator)
    return item.compiled_content unless body
    link = link_to( (item[:read_more] || read_more_text), item.path, :class=>'read_more' )
    return summary+"<p class='readmore'>#{link}</p>"
    end
    end
    end