module Murdoc

Html language module

Html language module

Html language module

Ruby language module

Constants

AnnotatedFile

‘AnnotatedFile` is a struct we pass into our templates

VERSION

Public Class Methods

annotate(filename, highlight = true, do_not_count_comment_lines = false) click to toggle source

‘Murdoc.annotate` arguments are gathered from CLI utility

‘highlight` regulates syntax highlighting and `do_not_count_comment_lines` flag toggles counting comment lines towards line numbering in the output.

# File lib/murdoc.rb, line 22
def self.annotate(filename, highlight = true, do_not_count_comment_lines = false)
  filename = File.expand_path(filename)
  annotator = Annotator.from_file(filename, nil, do_not_count_comment_lines)
  AnnotatedFile.new(filename,
      annotator.metadata,
      annotator.source,
      annotator.source_type,
      annotator.paragraphs,
      annotator.paragraphs.map {|p| FormattedParagraph.new(p, highlight) })
end
default_options() click to toggle source

Rest is self-explanatory

# File lib/murdoc.rb, line 117
def self.default_options
  @options ||= {
    template:   "#{markup_dir}/template.haml",
    stylesheet: "#{markup_dir}/stylesheet.css",
    highlight: true
  }
end
default_options_for_index() click to toggle source
# File lib/murdoc.rb, line 144
def self.default_options_for_index
  @options_index ||= {
    template: "#{markup_dir}/template_index.haml",
    stylesheet: "#{markup_dir}/stylesheet.css"
  }
end
default_options_for_multiple_files() click to toggle source
# File lib/murdoc.rb, line 125
def self.default_options_for_multiple_files
  @options_multi ||= {
    template:   "#{markup_dir}/template_multifile.haml",
    stylesheet: "#{markup_dir}/stylesheet.css",
    highlight: true
  }
end
default_options_for_tree() click to toggle source
# File lib/murdoc.rb, line 133
def self.default_options_for_tree
  @options_tree ||= {
    index_template: default_options_for_index[:template],
    index_stylesheet: default_options_for_index[:stylesheet],
    template: default_options[:template],
    stylesheet: default_options[:stylesheet],
    highlight: default_options[:highlight],
    do_not_count_comment_lines: false
  }
end
generate_from_file(input, output, options = {}) click to toggle source

Generate a single file story

# File lib/murdoc.rb, line 34
def self.generate_from_file(input, output, options = {})
  options = default_options.merge(options)
  annotator = Annotator.from_file(input, nil)
  File.open(output, "w+") do |f|
    annotated_file = annotate(input, options[:highlight], options[:do_not_count_comment_lines])
    f.puts Renderer.new(options[:template]).render(:annotated_file => annotated_file,
                                                   :stylesheet => File.read(options[:stylesheet]))
  end
end
generate_from_multiple_files(input_files, output, options = {}) click to toggle source

… or use multiple files

# File lib/murdoc.rb, line 45
def self.generate_from_multiple_files(input_files, output, options = {})
  options = default_options_for_multiple_files.merge(options)
  annotated_files = input_files.map {|fn| annotate(fn, options[:highlight], options[:do_not_count_comment_lines]) }
  File.open(output, "w+") do |f|
    f.puts Renderer.new(options[:template]).render(:annotated_files => annotated_files,
                                                   :stylesheet => File.read(options[:stylesheet]))
  end
end
generate_index(fn, options) click to toggle source
# File lib/murdoc.rb, line 101
def self.generate_index(fn, options)
  options = default_options_for_index.merge(options)
  File.open(fn, 'w+') do |f|
    f.puts Renderer.new(options[:template]).render({
      stylesheet: File.read(options[:stylesheet]),
      base_dir: options[:base_dir],
      has_parent: options[:has_parent],
      current_directory: options[:current_directory],
      files: options[:files],
      directories: options[:directories]
    })
  end
end
generate_tree(input_dir, output_dir, has_parent = false, base_dir = nil, options = {}) click to toggle source

Generate a documentation tree

# File lib/murdoc.rb, line 55
def self.generate_tree(input_dir, output_dir, has_parent = false, base_dir = nil, options = {})
  options = default_options_for_tree.merge(options)
  input_dir = Pathname(input_dir).expand_path
  output_dir = Pathname(output_dir).expand_path
  base_dir ||= input_dir

  FileUtils.mkdir_p(output_dir)

  entries = input_dir.children

  directories = entries.select(&:directory?).
                        reject {|dir| dir == output_dir }.
                        reject {|dir| dir.basename.to_s.start_with?('.')}
  directories.each do |dir|
    next if dir == output_dir
    generate_tree(dir,
                  output_dir + dir.relative_path_from(input_dir),
                  true,
                  base_dir,
                  options)
  end

  files = entries.select(&:file?).select {|file| Languages.detect(file.to_s) }
  files.each do |file|
    relpath = file.relative_path_from(input_dir)
    generate_from_file(file, "#{output_dir}/#{relpath}.html", {
      highlight: options[:highlight],
      template: options[:template],
      stylesheet: options[:stylesheet],
      do_not_count_comment_lines: options[:do_not_count_comment_lines]
    })
  end

  unless files.empty? && directories.empty?
    generate_index("#{output_dir}/index.html", {
     current_directory: input_dir,
     files: files,
     directories: directories,
     has_parent: has_parent,
     base_dir: base_dir,
     template: options[:index_template],
     stylesheet: options[:index_stylesheet]
    })
  end
end
markup_dir() click to toggle source
# File lib/murdoc.rb, line 151
def self.markup_dir
  File.expand_path("../..", __FILE__)+ "/markup"
end
try_load_yaml(yaml) click to toggle source
# File lib/murdoc.rb, line 156
def self.try_load_yaml(yaml)
  YAML.load(yaml)
rescue => e
  nil
end