module Zenweb::Page::MarkdownHelpers
Public Class Methods
page_url(page)
click to toggle source
# File lib/zenweb/plugins/markdown.rb, line 80 def page_url page "[#{page.title}](#{page.clean_url})" end
Public Instance Methods
attr(h_or_name)
click to toggle source
Return a kramdown block-tag to add attributes to the following (or preceding… kramdown is a bit crazy) block. Attributes can either be a simple name or a hash of key/value pairs.
# File lib/zenweb/plugins/markdown.rb, line 110 def attr h_or_name h_or_name = h_or_name.map { |k,v| "#{k}=\"#{v}\"" }.join " " if Hash === h_or_name "{:#{h_or_name}}" end
css_class(name)
click to toggle source
Return a kramdown block-tag for a CSS class.
# File lib/zenweb/plugins/markdown.rb, line 120 def css_class name attr ".#{name}" end
css_id(name)
click to toggle source
Return a kramdown block-tag for a CSS ID.
# File lib/zenweb/plugins/markdown.rb, line 127 def css_id name attr "##{name}" end
image(url, alt=url)
click to toggle source
Return a markdown-formatted image for a given url and an optional alt.
# File lib/zenweb/plugins/markdown.rb, line 141 def image url, alt=url "![#{alt}](#{url})" end
sitemap(title_dated = true, demote = 0)
click to toggle source
Returns a markdown formatted sitemap for the given pages or the current page’s subpages. This intelligently composes a sitemap whether the pages are ordered (dated) or not or a combination of the two.
# File lib/zenweb/plugins/markdown.rb, line 58 def sitemap title_dated = true, demote = 0 self.all_subpages_by_level(true).chunk { |n, p| n }.map { |level, a| level -= demote level = 0 if level < 0 dated, normal = a.map(&:last).reject(&:no_index?).partition(&:dated?) normal = normal.sort_by { |p| p.url.downcase }.map { |p| page_sitemap_url p, level } dated = dated_map(dated) { |month, ps2| x = date_sorted_map(ps2) { |p| page_sitemap_url p, level + (title_dated ? 1 : 0) } x.unshift "#{" " * level}* #{month}:" if title_dated x } normal + dated }.join "\n" end
toc()
click to toggle source
Convenience function to return a markdown TOC.
# File lib/zenweb/plugins/markdown.rb, line 101 def toc "* \n{:toc}\n" end