RTFMd

Forked from defunkt/gollum with:

  • Sinatra mountable app
  • ronn styled
  • Read-only
  • Multiple wiki repositories
  • Markdown, ronn, boson, capistrano support
  • GitHub callbacks

DESCRIPTION

  • documentation is still a very rough WIP, so trust nothing here until I can remove the Gollum bits that no longer apply.

RTFMd is a simple wiki system built on top of Git that powers GitHub Wikis.

RTFMd wikis are simply Git repositories that adhere to a specific format. RTFMd pages may be written in a variety of formats and can be edited in a number of ways depending on your needs. You can edit your wiki locally:

  • With your favorite text editor or IDE (changes will be visible after committing).
  • With the RTFMd Ruby API.

RTFMd follows the rules of Semantic Versioning and uses TomDoc for inline documentation.

RUNNING

To view your RTFMd repository locally via the built in web interface, unblde the RTFMd and thin gem, navigate to your repository via the command line, and run:

RTFM_ROOT="/"
RTFM_REPOS="$HOME:/home $HOME/work/project_a $HOME/work/project_b"
rcport RTFM_ROOT RTFM_REPOS 

RTFM_RU=$(bundle show RTFMd)/config/rtfmd.ru
bundle exec thin start -R $RTFM_RU

This will start up a web server running the RTFMd frontend and you can view your wiki at http://localhost:3000

REPO STRUCTURE

A RTFMd repository's contents are designed to be human editable. Page content is written in page files and may be organized into directories any way you choose. Special footers can be created in footer files. Other content (images, PDFs, etc) may also be present and organized in the same way.

PAGE FILES

Page files may be written in Markdown with extensions:

  • Markdown: .mkd, .markdown, .mdown, .mkdn, .md
  • ronn: .ronn

RTFMd detects the page file format via the extension, so files must have one of the supported extensions in order to be converted.

Page file names may contain any printable UTF-8 character except space (U+0020) and forward slash (U+002F). If you commit a page file with any of these characters in the name it will not be accessible via the web interface.

Even though page files may be placed in any directory, there is still only a single namespace for page names, so all page files should have globally unique names regardless of where they are located in the repository.

The special page file README.mkd or Home.mkd (where the extension is one of the supported formats) will be used as the entrance page to your wiki. If it is missing, an automatically generated table of contents will be shown instead.

Sidebar files allow you to add a simple sidebar to your wiki. Sidebar files are named _Sidebar.mkd where the extension is one of the supported formats. Sidebars affect all pages in their directory and any subdirectories that do not have a sidebar file of their own.

Footer files allow you to add a simple footer to your wiki. Footer files must be named _Footer.mkd where the extension is one of the supported formats. Like sidebars, footers affect all pages in their directory and any subdirectories that do not have a footer file of their own.

HTML SANITIZATION

For security and compatibility reasons RTFMd wikis may not contain custom CSS or JavaScript. These tags will be stripped from the converted HTML. See docs/sanitization.mkd for more details on what tags and attributes are allowed.

BRACKET TAGS

A variety of RTFMd tags use a double bracket syntax. For example:

[[Link]]

Some tags will accept attributes which are separated by pipe symbols. For example:

[[Link|Page Title]]

In all cases, the first thing in the link is what is displayed on the page. So, if the tag is an internal wiki link, the first thing in the tag will be the link text displayed on the page. If the tag is an embedded image, the first thing in the tag will be a path to an image file. Use this trick to easily remember which order things should appear in tags.

Some formats, such as MediaWiki, support the opposite syntax:

[[Page Title|Link]]

To link to another RTFMd wiki page, use the RTFMd Page Link Tag.

[[Frodo Baggins]]

The above tag will create a link to the corresponding page file named Frodo-Baggins.mkd where ext may be any of the allowed extension types. The conversion is as follows:

  1. Replace any spaces (U+0020) with dashes (U+002D)
  2. Replace any slashes (U+002F) with dashes (U+002D)

If you'd like the link text to be something that doesn't map directly to the page name, you can specify the actual page name after a pipe:

[[Frodo|Frodo Baggins]]

The above tag will link to Frodo-Baggins.mkd using "Frodo" as the link text.

The page file may exist anywhere in the directory structure of the repository. RTFMd does a breadth first search and uses the first match that it finds.

Here are a few more examples:

[[J. R. R. Tolkien]] -> J.-R.-R.-Tolkien.mkd
[[Movies / The Hobbit]] -> Movies---The-Hobbit.mkd
[[モルドール]] -> モルドール.mkd

As a convenience, simple external links can be placed within brackets and they will be linked to the given URL with the URL as the link text. For example:

[[http://example.com]]

External links must begin with either "http://" or "https://". If you need something more flexible, you can resort to the link syntax in the page's underlying markup format.

ABSOLUTE VS. RELATIVE VS. EXTERNAL PATH

For RTFMd tags that operate on static files (images, PDFs, etc), the paths may be referenced as either relative, absolute, or external. Relative paths point to a static file relative to the page file within the directory structure of the RTFMd repo (even though after conversion, all page files appear to be top level). These paths are NOT prefixed with a slash. For example:

gollum.pdf
docs/diagram.png

Absolute paths point to a static file relative to the RTFMd repo's root, regardless of where the page file is stored within the directory structure. These paths ARE prefixed with a slash. For example:

/pdfs/gollum.pdf
/docs/diagram.png

External paths are full URLs. An external path must begin with either "http://" or "https://". For example:

http://example.com/pdfs/gollum.pdf
http://example.com/images/diagram.png

All of the examples in this README use relative paths, but you may use whatever works best in your situation.

To link to static files that are contained in the RTFMd repository you should use the RTFMd File Link Tag.

[[RTFMd|gollum.pdf]]

The first part of the tag is the link text. The path to the file appears after the pipe.

IMAGES

To display images that are contained in the RTFMd repository you should use the RTFMd Image Tag. This will display the actual image on the page.

[[gollum.png]]

In addition to the simple format, there are a variety of options that you can specify between pipe delimiters.

To specify alt text, use the alt= option. Default is no alt text.

[[gollum.png|alt=RTFMd and his precious wiki]]

To place the image in a frame, use the frame option. When combined with the alt= option, the alt text will be used as a caption as well. Default is no frame.

[[gollum.png|frame|alt=RTFMd and his precious wiki]]

To specify the alignment of the image on the page, use the align= option. Possible values are left, center, and right. Default is left.

[[gollum.png|align=center]]

To float an image so that text flows around it, use the float option. When float is specified, only left and right are valid align options. Default is not floating. When floating is activated but no alignment is specified, default alignment is left.

[[gollum.png|float]]

To specify a max-width, use the width= option. Units must be specified in either px or em.

[[gollum.png|width=400px]]

To specify a max-height, use the height= option. Units must be specified in either px or em.

[[gollum.png|height=300px]]

Any of these options may be composed together by simply separating them with pipes.

ESCAPING GOLLUM TAGS

If you need the literal text of a wiki or static link to show up in your final wiki page, simply preface the link with a single quote (like in LISP):

'[[Page Link]]
'[[File Link|file.pdf]]
'[[image.jpg]]

This is useful for writing about the link syntax in your wiki pages.

SYNTAX HIGHLIGHTING

In page files you can get automatic syntax highlighting for a wide range of languages (courtesy of Pygments - must install separately) by using the following syntax:

```ruby
  def foo
    puts 'bar'
  end
```

The block must start with three backticks (as the first characters on the line). After that comes the name of the language that is contained by the block. The language must be one of the short name lexer strings supported by Pygments. See the list of lexers for valid options.

If the block contents are indented two spaces or one tab, then that whitespace will be ignored (this makes the blocks easier to read in plaintext).

The block must end with three backticks as the first characters on a line.

API DOCUMENTATION

The RTFMd API allows you to retrieve raw or formatted wiki content from a Git repository, write new content to the repository, and collect various meta data about the wiki as a whole.

Initialize the Gollum::Repo object:

# Require rubygems if necessary
require 'rubygems'

# Require the RTFMd library
require 'gollum'

# Create a new Gollum::Wiki object by initializing it with the path to the
# Git repository.
wiki = Gollum::Wiki.new("my-gollum-repo.git")
# => <Gollum::Wiki>

By default, internal wiki links are all absolute from the root. To specify a different base path, you can specify the :base_path option:

wiki = Gollum::Wiki.new("my-gollum-repo.git", :base_path => "/wiki")

Get the latest version of the given human or canonical page name:

page = wiki.page('page-name')
# => <Gollum::Page>

page.raw_data
# => "# My wiki page"

page.formatted_data
# => "<h1>My wiki page</h1>"

page.format
# => :markdown

vsn = page.version
# => <Grit::Commit>

vsn.id
# => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5'

Get the footer (if any) for a given page:

page.footer
# => <Gollum::Page>

Get a list of versions for a given page:

vsns = wiki.page('page-name').versions
# => [<Grit::Commit, <Grit::Commit, <Grit::Commit>]

vsns.first.id
# => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5'

vsns.first.authored_date
# => Sun Mar 28 19:11:21 -0700 2010

Get a specific version of a given canonical page file:

wiki.page('page-name', '5ec521178e0eec4dc39741a8978a2ba6616d0f0a')

Get the latest version of a given static file:

file = wiki.file('asset.js')
# => <Gollum::File>

file.raw_data
# => "alert('hello');"

file.version
# => <Grit::Commit>

Get a specific version of a given static file:

wiki.file('asset.js', '5ec521178e0eec4dc39741a8978a2ba6616d0f0a')

Get an in-memory Page preview (useful for generating previews for web interfaces):

preview = wiki.preview_page("My Page", "# Contents", :markdown)
preview.formatted_data
# => "<h1>Contents</h1>"

Methods that write to the repository require a Hash of commit data that takes the following form:

commit = { :message => 'commit message',
           :name => 'Tom Preston-Werner',
           :email => '[email protected]' }

Write a new version of a page (the file will be created if it does not already exist) and commit the change. The file will be written at the repo root.

wiki.write_page('Page Name', :markdown, 'Page contents', commit)

Update an existing page. If the format is different than the page's current format, the file name will be changed to reflect the new format.

page = wiki.page('Page Name')
wiki.update_page(page, page.name, page.format, 'Page contents', commit)

To delete a page and commit the change:

wiki.delete_page(page, commit)