Class: MarkdownRubyDocumentation::Generate
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::Generate
- Defined in:
- lib/markdown_ruby_documentation/generate.rb
Defined Under Namespace
Classes: Page
Class Attribute Summary collapse
-
.load_path ⇒ Object
Returns the value of attribute load_path.
-
.output_object ⇒ Object
Returns the value of attribute output_object.
Class Method Summary collapse
- .left_padding(subjects = nil) ⇒ Object
- .progressbar(subjects = nil) ⇒ Object
- .run(subjects:, erb_methods: DefaultErbMethods, output_object:, load_path:, parallel_config: {}) ⇒ Object
Class Attribute Details
.load_path ⇒ Object
Returns the value of attribute load_path.
62 63 64 |
# File 'lib/markdown_ruby_documentation/generate.rb', line 62 def load_path @load_path end |
.output_object ⇒ Object
Returns the value of attribute output_object.
62 63 64 |
# File 'lib/markdown_ruby_documentation/generate.rb', line 62 def output_object @output_object end |
Class Method Details
.left_padding(subjects = nil) ⇒ Object
59 60 61 |
# 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) ⇒ Object
55 56 57 |
# File 'lib/markdown_ruby_documentation/generate.rb', line 55 def (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: {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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) (subject_classes) .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| .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 { .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 .title = "Markdown Documentation Compilation Complete".ljust(left_padding) .finish return_value end |