Module: Gollum

Defined in:
lib/gollum-lib/filter.rb,
lib/gollum-lib.rb,
lib/gollum-lib/file.rb,
lib/gollum-lib/hook.rb,
lib/gollum-lib/page.rb,
lib/gollum-lib/wiki.rb,
lib/gollum-lib/macro.rb,
lib/gollum-lib/markup.rb,
lib/gollum-lib/gitcode.rb,
lib/gollum-lib/helpers.rb,
lib/gollum-lib/markups.rb,
lib/gollum-lib/version.rb,
lib/gollum-lib/committer.rb,
lib/gollum-lib/file_view.rb,
lib/gollum-lib/blob_entry.rb,
lib/gollum-lib/git_access.rb,
lib/gollum-lib/pagination.rb,
lib/gollum-lib/macro/series.rb,
lib/gollum-lib/sanitization.rb,
lib/gollum-lib/macro/all_pages.rb,
lib/gollum-lib/macro/global_toc.rb,
lib/gollum-lib/macro/navigation.rb

Overview

A “filter”, in Gollum-speak, is an object which extracts tokens from an input stream of an arbitrary markup language, then replaces them with a final form in a rendered form of the same document. Filters are composed into a “filter chain”, which forms the order in which filters are applied in both the extraction and processing phases (processing happens in the reverse order to extraction). A single instance of a filter class is used for both the extraction and processing, so you can store internal state from the extraction phase for use in the processing phase.

Any class which is to be used as a filter must have an ‘initialize` method which takes a single mandatory argument (the instance of the `Markup` class we’re being called from), and must implement two methods: ‘extract` and `process`, both of which must take a string as input and return a (possibly modified) form of that string as output.

An example rendering session: consider a filter chain with three filters in it, :A, :B, and :C (filter chains are specified as symbols, which are taken to be class names within the Gollum::Filter namespace). An equivalent of the following will take place:

a = Gollum::Filter.const_get(:A).new
b = Gollum::Filter.const_get(:B).new
c = Gollum::Filter.const_get(:C).new

data = "<some markup>"

data = a.extract(data)
data = b.extract(data)
data = c.extract(data)

data = c.process(data)
data = b.process(data)
data = a.process(data)

# `data` now contains the rendered document, ready for processing

Note how the extraction steps go in the order of the filter chain, while the processing steps go in the reverse order. There hasn’t (yet) been a case where that is a huge problem.

If your particular filter doesn’t need to do something with either the original markup or rendered forms, you can simply define the relevant method to be a pass-through (‘def extract(d) d; end`), but you must define both methods yourself.

Defined Under Namespace

Modules: Helpers, Lib, Pagination Classes: BlobEntry, Committer, DuplicatePageError, Error, File, FileView, Filter, GitAccess, Gitcode, Hook, InvalidGitRepositoryError, Macro, Markup, NoSuchPathError, Page, Sanitization, Wiki

Constant Summary collapse

MarkupGFM =
Markup

Class Method Summary collapse

Class Method Details

.assets_pathObject



43
44
45
# File 'lib/gollum-lib.rb', line 43

def self.assets_path
  ::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
end