Sha256: 451dc6521f46835e8d96f36e2f106ba27b5d1db9c86add1c47d4cf7099c2b9c2

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 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=\"#{::File.join(@wiki.base_path,previous_page.escaped_url_path)}\">#{previous_page.name}</a>" if previous_page
      	result = "#{result}#{result ? ' | ' : ''}Next: <a href=\"#{::File.join(@wiki.base_path,next_page.escaped_url_path)}\">#{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=\"#{::File.join(@wiki.base_path,next_page.escaped_url_path)}\">#{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=\"#{::File.join(@wiki.base_path,previous_page.escaped_url_path)}\">#{previous_page.name}</a>" if previous_page
        wrap_result(result)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gollum-lib-5.1.1-java lib/gollum-lib/macro/series.rb
gollum-lib-5.1.1 lib/gollum-lib/macro/series.rb
gollum-lib-5.1-java lib/gollum-lib/macro/series.rb
gollum-lib-5.1 lib/gollum-lib/macro/series.rb
gollum-lib-5.0.6-java lib/gollum-lib/macro/series.rb
gollum-lib-5.0.6 lib/gollum-lib/macro/series.rb
gollum-lib-5.0.5-java lib/gollum-lib/macro/series.rb
gollum-lib-5.0.5 lib/gollum-lib/macro/series.rb