Class: Gollum::Macro::Series

Inherits:
Gollum::Macro show all
Defined in:
lib/gollum-lib/macro/series.rb

Direct Known Subclasses

SeriesEnd, SeriesStart

Instance Method Summary collapse

Methods inherited from Gollum::Macro

#initialize, instance

Constructor Details

This class inherits a constructor from Gollum::Macro

Instance Method Details

#find_series(series_prefix = "") ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gollum-lib/macro/series.rb', line 20

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 == @page.name}
	if self_index > 0
    return dir[self_index-1], dir[self_index+1]
	else
    return nil, dir[self_index+1]
	end
end

#render(series_prefix = "") ⇒ Object



5
6
7
8
# File 'lib/gollum-lib/macro/series.rb', line 5

def render(series_prefix = "")
	raise "This page's name does not match the prefix '#{series_prefix}'" unless @page.name =~ /^#{series_prefix}/
	render_links(*find_series(series_prefix))
end


10
11
12
13
14
# File 'lib/gollum-lib/macro/series.rb', line 10

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

#wrap_result(result) ⇒ Object



16
17
18
# File 'lib/gollum-lib/macro/series.rb', line 16

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