Module:Chapter navigation

From Wikibooks, open books for an open world
Jump to: navigation, search
Documentation[edit] [history] [purge]

This module provides a way to generate navigation bars to navigate between chapters of a book and a way to put a book chapter in the book category.

Usage[edit]

This module should not be invoked directly. The simple chapter navigation template should be used instead.

Functions[edit]

This module provides two functions: one to create a navigation bar and one to categorize the page automatically, assuming it is a book chapter. The former receives two optional arguments, previous and next, which should be the names of the previous and next chapters, respectively. It uses these chapter names to generate a navigation bar that is meant to be put at the bottom of the chapter page. The latter function does not have any parameter and puts the chapter page in the book category, ordering it properly. These two functions assume that the book follows the Wikibooks naming policy and are likely to work improperly if it is not followed.

return {
	navigation_bar = function(frame)
		local current_title = mw.title.getCurrentTitle()
		local base_page_name = current_title.baseText
		local bar = mw.html.create('div')
			:addClass('noprint')
			:css {
				['border-top-style'] = 'solid';
				['border-top-width'] = 'thin';
				clear = 'both';
				['margin-top'] = "1em";
				width = "100%"
			}
		if frame.args.previous and frame.args.previous ~= '' then
			bar:tag('span'):css('float', 'left'):wikitext('[[' .. base_page_name .. '/' .. frame.args.previous .. '|' .. frame.args.previous .. ']]')
		end
		if frame.args.next and frame.args.next ~= '' then
			bar:tag('span'):css('float', 'right'):wikitext('[[' .. base_page_name .. '/' .. frame.args.next .. '|' .. frame.args.next .. ']]')
		end
		return tostring(bar)
	end;
	categorize = function(frame)
		local current_title = mw.title.getCurrentTitle()
		return "[[Category:" .. current_title.baseText .. '|' .. current_title.subpageText .. ']]'
	end
}