Class: Jsus::Util::Documenter
- Inherits:
-
Object
- Object
- Jsus::Util::Documenter
- Defined in:
- lib/jsus/util/documenter.rb
Overview
Very opinionated documenter class. It uses Murdoc to generate the documentation using the template and stylesheet bundled with the jsus gem file. Also generates indices for navigation.
Constant Summary collapse
- DEFAULT_OPTIONS =
Default documenter options
{:highlight_source => true}
Instance Attribute Summary collapse
-
#options ⇒ Object
Documenter options.
Instance Method Summary collapse
-
#<<(source) ⇒ Object
Adds a source file to the documented source tree.
-
#current_scope ⇒ Array
Scope for documentation in pathspec format.
- #current_scope=(scope) ⇒ Object
-
#default_scope ⇒ Array
Default documentation scope.
-
#documented_sources ⇒ Jsus::Util::Tree
Tree with documented sources only.
- #documented_sources! ⇒ Object private
-
#generate(doc_dir = Dir.pwd) ⇒ Object
Generates documentation tree into the given directory.
-
#initialize(options = DEFAULT_OPTIONS) ⇒ Documenter
constructor
Constructor.
-
#only(scope) ⇒ Object
Sets documenter to exclusive scope for documentation.
-
#or(scope) ⇒ Object
Sets documenter to additive scope for documentation.
-
#tree ⇒ Jsus::Util::Tree
Tree with all sources.
Constructor Details
#initialize(options = DEFAULT_OPTIONS) ⇒ Documenter
Constructor. Accepts options as the argument.
18 19 20 21 22 23 |
# File 'lib/jsus/util/documenter.rb', line 18 def initialize( = DEFAULT_OPTIONS) require "murdoc" self. = rescue LoadError raise "You should install murdoc gem in order to produce documentation" end |
Instance Attribute Details
#options ⇒ Object
Documenter options
11 12 13 |
# File 'lib/jsus/util/documenter.rb', line 11 def @options end |
Instance Method Details
#<<(source) ⇒ Object
Adds a source file to the documented source tree
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jsus/util/documenter.rb', line 54 def <<(source) # :nodoc: filename = File.basename(source.filename) if source.package tree["#{source.package.name}/#{filename}"] = source else tree["#{filename}"] = source end self end |
#current_scope ⇒ Array
Scope for documentation in pathspec format. See Jsus::Util::Tree::Node#find_children_matching
74 75 76 |
# File 'lib/jsus/util/documenter.rb', line 74 def current_scope @current_scope ||= default_scope end |
#current_scope=(scope) ⇒ Object
85 86 87 |
# File 'lib/jsus/util/documenter.rb', line 85 def current_scope=(scope) @current_scope = scope end |
#default_scope ⇒ Array
Returns default documentation scope.
80 81 82 |
# File 'lib/jsus/util/documenter.rb', line 80 def default_scope ["/**/*"] end |
#documented_sources ⇒ Jsus::Util::Tree
Returns tree with documented sources only.
112 113 114 |
# File 'lib/jsus/util/documenter.rb', line 112 def documented_sources @documented_sources ||= documented_sources! end |
#documented_sources! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 121 122 123 |
# File 'lib/jsus/util/documenter.rb', line 118 def documented_sources! doctree = Tree.new current_scope.map {|pathspec| tree.find_nodes_matching(pathspec) }. flatten.each {|s| doctree.insert(s.full_path, s.value)} doctree end |
#generate(doc_dir = Dir.pwd) ⇒ Object
Generates documentation tree into the given directory.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jsus/util/documenter.rb', line 29 def generate(doc_dir = Dir.pwd) #FileUtils.rm_rf(doc_dir) FileUtils.mkdir_p(doc_dir) template_path = File.dirname(__FILE__) + "/../../../markup" template = File.read("#{template_path}/template.haml") index_template = File.read("#{template_path}/index_template.haml") stylesheet_path = "#{template_path}/stylesheet.css" documented_sources.traverse(true) do |node| if node.value # leaf dir = doc_dir + File.dirname(node.full_path) FileUtils.mkdir_p(dir) file_from_contents(dir + "/#{node.name}.html", create_documentation_for_source(node.value, template)) else dir = doc_dir + node.full_path FileUtils.mkdir_p(dir) FileUtils.cp(stylesheet_path, dir) file_from_contents(dir + "/index.html", create_index_for_node(node, index_template)) end end end |
#only(scope) ⇒ Object
Sets documenter to exclusive scope for documentation. Exclusive scope overrides all the other scopes.
93 94 95 96 97 |
# File 'lib/jsus/util/documenter.rb', line 93 def only(scope) result = clone result.current_scope = [scope].flatten result end |
#or(scope) ⇒ Object
Sets documenter to additive scope for documentation. Additive scopes match any of the pathspecs given
104 105 106 107 108 |
# File 'lib/jsus/util/documenter.rb', line 104 def or(scope) result = clone result.current_scope = current_scope + [scope].flatten result end |
#tree ⇒ Jsus::Util::Tree
Returns tree with all sources.
67 68 69 |
# File 'lib/jsus/util/documenter.rb', line 67 def tree @tree ||= Tree.new end |