# Provides methods for showing a summary of visits to a page, or overall popular pages.
module MintHelper
# Shows a little HTML summary of hits to a url.
#
# Returns nil if the page has never been hit.
#
# Pulls straight from the mint_visit table, so it can be very slow.
def mint_page_views(url)
if (visit_count = Mint.visits_to_resource(url)) > 0
return %(
This page has been viewed #{visit_count} times since #{Mint.earliest_visit_to_resource(url).strftime('%B %d, %Y')}
)
end
nil
end
# Returns an HTML summary for a specific page. Uses the cache, which is built with
#
# rake mint:rebuild
#
# Call from Typo with
#
# mint_cached_page_views(article_url(article, true))
#
# See a stylesheet for the results at
#
# http://nubyonrails.com/stylesheets/theme/mint.css
#
def mint_cached_page_views(url)
if (hit_summary = MintCache.visits_to_resource(url))
return %(This page has been viewed #{number_with_delimiter hit_summary.visit_count} times since #{hit_summary.earliest_visit.strftime('%B %d, %Y')}
)
end
nil
end
# Shows a summary of popular pages, with links.
def mint_cached_popular_pages(options={})
stats = MintCache.popular_pages(options)
stat_summaries = stats.map { |stat| "#{link_to(stat.resource_title, stat.resource)} (#{number_with_delimiter stat.visit_count} views)" }
return %(
Recently Popular Pages (Top #{stat_summaries.length})
#{stat_summaries.join('')}
)
end
end