class Rspec::Usecases::Generator::MarkdownGenerator
Markdown generator can build a markdown documentation file based on the document content
Public Instance Methods
generate()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/rspec/usecases/generator/markdown_generator.rb, line 28 def generate print_document_header print_groups(document.groups) end
run()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/rspec/usecases/generator/markdown_generator.rb, line 11 def run @key_width = 30 @indent_size = 0 generate print_output if options.printable? return unless options.writable? write_file(options.file) prettier_file(options.file) if options.prettier? open_file_in_vscode(options.file) if options.openable? end
Private Instance Methods
bullet(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 126 def bullet(title) write_line("- #{title}") if title != '' end
h1(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 102 def h1(title) write_line("# #{title}") if title != '' end
h2(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 106 def h2(title) write_line("## #{title}") if title != '' end
h3(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 110 def h3(title) write_line("### #{title}") if title != '' end
h4(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 114 def h4(title) write_line("#### #{title}") if title != '' end
h5(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 118 def h5(title) write_line("##### #{title}") if title != '' end
h6(title)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 122 def h6(title) write_line("###### #{title}") if title != '' end
hr()
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 130 def hr write_line '---' end
print_contents(usecase)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 72 def print_contents(usecase) return if usecase.contents.empty? usecase.contents.each do |content| write_line '---' if content.is_hr render_outcome(content) if content.type == 'outcome' render_code(content) if content.type == 'code' end print_groups(usecase.groups) end
print_document_header()
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 35 def print_document_header h1 document.title write_line document.description write_lf end
print_groups(groups)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 41 def print_groups(groups) groups.each { |usecase| print_usecase(usecase) } end
print_summary(usecase)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 53 def print_summary(usecase) return unless usecase.summary write_line usecase.summary write_lf end
print_usage(usecase)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 60 def print_usage(usecase) return if usecase.usage == '' h3 usecase.usage write_lf return unless usecase.usage_description write_line usecase.usage_description write_lf end
print_usecase(usecase)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 45 def print_usecase(usecase) h2 usecase.title write_lf print_summary(usecase) print_usage(usecase) print_contents(usecase) end
render_code(content)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 90 def render_code(content) h4 content.title # write_line content.note if content.note render_code_block(content.source, content.code_type) unless content.source == '' end
render_code_block(source, code_type)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 96 def render_code_block(source, code_type) write_line "```#{code_type}" write_line source write_line '```' end
render_outcome(content)
click to toggle source
# File lib/rspec/usecases/generator/markdown_generator.rb, line 85 def render_outcome(content) bullet content.title write_line content.note if content.note end