Skip to content
DocumentTree transforms a file system in a tree with content and meta data.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
document_tree.gemspec

README.rdoc

document_tree

DocumentTree is a gem that can read out a simple file tree. It can be used to generate a tree with documentation in Ruby on Rails, so that pages don't have to be in a database.

Usage

You must have a folder that will be read some where. For example the following example will generate a tree.

  • section (folder)

    • meta.txt (file)

    • othersection (folder)

      • somefile.txt (file)

If you now invoke DocumentTree.root.name the meta.txt is read for a real name.

Meta data

All meta data is YAML format. Normal files have meta data on top of the file, splitted by line. Directories have a meta data on top of meta.txt.

Format folder meta data

The meta data for a folder is read by reading the meta.txt of it's children. For example, meta.txt has the following content, the first line is the YAML meta data, the rest is content.

name: DocumentTree documentation

Here comes the text, maybe formatted in some way.
Tralala.

Now the following code:

node = DocumentTree.root 
node.name
# => DocumentTree.documentation
node.content
# => Here comes the text, maybe formatted in some way.\nTralala.
node.raw_name
# => section

Finding a node

You can search for a node by doing

DocumentTree.root.find_node("hisrawname")

Returning all nodes

DocumentTree.root.all_nodes

Copyright

Copyright © 2010 Jaap van der Meer. See LICENSE for details.

You can’t perform that action at this time.