Sha256: d1a031af56194db0cbf84fe3abd182f89ff148b642d84abed9c1d389c939cdda

Contents?: true

Size: 1.95 KB

Versions: 16

Compression:

Stored size: 1.95 KB

Contents

module Gollum
  class Macro

    class Series < Gollum::Macro
      def render(series_prefix = "")
      	raise "This page's name does not match the prefix '#{series_prefix}'" unless active_page.name =~ /^#{series_prefix}/
      	render_links(*find_series(series_prefix))
      end

      def render_links(previous_page, next_page)
      	result = "Previous: <a href=\"#{CGI::escapeHTML(::File.join(@wiki.base_path,previous_page.escaped_url_path))}\">#{CGI::escapeHTML(previous_page.name)}</a>" if previous_page
      	result = "#{result}#{result ? ' | ' : ''}Next: <a href=\"#{CGI::escapeHTML(::File.join(@wiki.base_path,next_page.escaped_url_path))}\">#{CGI::escapeHTML(next_page.name)}</a>" if next_page
      	wrap_result(result)
      end

      def wrap_result(result)
      	result.nil? ? "" : "<div class=\"series\">#{result}</div>"
      end

      def find_series(series_prefix = "")
      	dir = @wiki.pages.select {|page| ::File.dirname(page.path) == ::File.dirname(@page.path)}
      	dir.select! {|page| page.name =~ /\A#{series_prefix}/ } unless series_prefix.empty?
      	dir.sort_by! {|page| page.name}
      	self_index = dir.find_index {|page| page.name == active_page.name}
      	if self_index > 0
          return dir[self_index-1], dir[self_index+1]
      	else
          return nil, dir[self_index+1]
      	end
      end
    end

    class SeriesStart < Gollum::Macro::Series
      def render_links(previous_page, next_page)
        result = "Next: <a href=\"#{CGI::escapeHTML(::File.join(@wiki.base_path,next_page.escaped_url_path))}\">#{CGI::escapeHTML(next_page.name)}</a>" if next_page
        wrap_result(result)
      end
    end

    class SeriesEnd < Gollum::Macro::Series
      def render_links(previous_page, next_page)
        result = "Previous: <a href=\"#{CGI::escapeHTML(::File.join(@wiki.base_path,previous_page.escaped_url_path))}\">#{CGI::escapeHTML(previous_page.name)}</a>" if previous_page
        wrap_result(result)
      end
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gollum-lib-6.0-java lib/gollum-lib/macro/series.rb
gollum-lib-6.0 lib/gollum-lib/macro/series.rb
gollum-lib-5.2.4-java lib/gollum-lib/macro/series.rb
gollum-lib-5.2.4 lib/gollum-lib/macro/series.rb
gollum-lib-5.2.3-java lib/gollum-lib/macro/series.rb
gollum-lib-5.2.3 lib/gollum-lib/macro/series.rb
gollum-lib-5.2.2-java lib/gollum-lib/macro/series.rb
gollum-lib-5.2.2 lib/gollum-lib/macro/series.rb
gollum-lib-5.2.1-java lib/gollum-lib/macro/series.rb
gollum-lib-5.2.1 lib/gollum-lib/macro/series.rb
gollum-lib-5.2-java lib/gollum-lib/macro/series.rb
gollum-lib-5.2 lib/gollum-lib/macro/series.rb
gollum-lib-5.1.3-java lib/gollum-lib/macro/series.rb
gollum-lib-5.1.3 lib/gollum-lib/macro/series.rb
gollum-lib-5.1.2-java lib/gollum-lib/macro/series.rb
gollum-lib-5.1.2 lib/gollum-lib/macro/series.rb