class MarkdownRubyDocumentation::Generate

Attributes

load_path[RW]
output_object[RW]

Public Class Methods

left_padding(subjects=nil) click to toggle source
# File lib/markdown_ruby_documentation/generate.rb, line 59
def left_padding(subjects=nil)
  @left_padding ||= subjects.map(&:name).group_by(&:size).max.first
end
progressbar(subjects=nil) click to toggle source
# File lib/markdown_ruby_documentation/generate.rb, line 55
def progressbar(subjects=nil)
  @progressbar ||= ProgressBar.create(title: "Compiling Markdown".ljust(left_padding(subjects)), total: subjects.count+ 1)
end
run( subjects:, erb_methods: DefaultErbMethods, output_object:, load_path:, parallel_config: {}) click to toggle source
# File lib/markdown_ruby_documentation/generate.rb, line 9
def run(
  subjects:,
  erb_methods: DefaultErbMethods,
  output_object:,
  load_path:,
  parallel_config: {})
  self.output_object = output_object
  self.load_path     = load_path
  erb_methods_class  = Class.new
  erb_methods_class.extend TemplateParser::CommentMacros
  erb_methods_class.extend erb_methods
  TemplateParser::CommentMacros.include erb_methods
  subject_classes = subjects.map { |h| h.fetch(:class) }
  left_padding(subject_classes)
  progressbar(subject_classes)
  progressbar.title = "Compiling Markdown".ljust(left_padding)
  batches           = subjects.each_slice(parallel_config.fetch(:in_threads, 2))
  threads           = []
  batches.each do |batch|
    threads << Thread.new(batch) do |inner_batch|
      Array[inner_batch].flatten.map do |subject|
        progressbar.title = subject.fetch(:class).name.ljust(left_padding)
        Page.new(
          subject_class:     subject.fetch(:class),
          subject_location:  subject.fetch(:file_path).to_s,
          output_object:     output_object,
          erb_methods_class: erb_methods_class,
          load_path:         load_path
        ).call.tap { progressbar.increment }
      end
    end
  end
  pages             = threads.flat_map(&:value)
  return_value      = pages.each_with_object({}) do |page, hash|
    name_parts      = page.subject.name.split("::")
    name            = name_parts.pop
    namespace       = name_parts.join("::")
    hash[namespace] ||= {}
    hash[namespace].merge!({ name => page })
    hash
  end
  progressbar.title = "Markdown Documentation Compilation Complete".ljust(left_padding)
  progressbar.finish
  return_value
end