Class: MarkMaker::Generator
- Inherits:
-
Object
- Object
- MarkMaker::Generator
- Defined in:
- lib/mark_maker/generator.rb
Overview
Generator is the workhorse of the MarkMaker utility. It provides line by line generation of markdown output.
Instance Method Summary collapse
- #block_quote(*content) ⇒ Object
- #bullet(content) ⇒ Object
- #bullets(*content) ⇒ Object
- #code(content) ⇒ Object
- #code_block(*content) ⇒ Object
- #code_span(content) ⇒ Object
- #emphasis(content) ⇒ Object
-
#fenced_code_block(*content) ⇒ Object
creates a github flavored markdown fenced code block.
-
#fenced_code_language(lang, *content) ⇒ Object
creates a github flavored markdown fenced code block that specifies the language for syntax highlighting purposes.
- #header1(title) ⇒ Object
- #header2(title) ⇒ Object
- #header3(title) ⇒ Object
- #line_for(underscore, content) ⇒ Object
- #link(label, url) ⇒ Object
- #number(content, number = 1) ⇒ Object
- #numbers(*content) ⇒ Object
- #strong(content) ⇒ Object
- #table_header(*content) ⇒ Object
- #table_row(*content) ⇒ Object
Instance Method Details
#block_quote(*content) ⇒ Object
88 89 90 |
# File 'lib/mark_maker/generator.rb', line 88 def block_quote(*content) content.map { |c| "#{BLOCK_QUOTE} #{c}"} end |
#bullet(content) ⇒ Object
21 22 23 |
# File 'lib/mark_maker/generator.rb', line 21 def bullet(content) " - #{content}" end |
#bullets(*content) ⇒ Object
25 26 27 |
# File 'lib/mark_maker/generator.rb', line 25 def bullets(*content) content.map { |li| bullet(li) } end |
#code(content) ⇒ Object
42 43 44 |
# File 'lib/mark_maker/generator.rb', line 42 def code(content) " #{content}" end |
#code_block(*content) ⇒ Object
50 51 52 |
# File 'lib/mark_maker/generator.rb', line 50 def code_block(*content) content.map { |c| code(c) } end |
#code_span(content) ⇒ Object
46 47 48 |
# File 'lib/mark_maker/generator.rb', line 46 def code_span(content) "#{CODE_TIC}#{content}#{CODE_TIC}" end |
#emphasis(content) ⇒ Object
69 70 71 |
# File 'lib/mark_maker/generator.rb', line 69 def emphasis(content) "#{EMPHASIS}#{content}#{EMPHASIS}" end |
#fenced_code_block(*content) ⇒ Object
creates a github flavored markdown fenced code block
55 56 57 58 59 |
# File 'lib/mark_maker/generator.rb', line 55 def fenced_code_block(*content) block = *FENCE block.push(*content) block << FENCE end |
#fenced_code_language(lang, *content) ⇒ Object
creates a github flavored markdown fenced code block that specifies the language for syntax highlighting purposes
63 64 65 66 67 |
# File 'lib/mark_maker/generator.rb', line 63 def fenced_code_language(lang, *content) block = *FENCE + lang block.push(*content) block << FENCE end |
#header1(title) ⇒ Object
9 10 11 |
# File 'lib/mark_maker/generator.rb', line 9 def header1(title) "#{title}\n#{line_for('=', title)}" end |
#header2(title) ⇒ Object
13 14 15 |
# File 'lib/mark_maker/generator.rb', line 13 def header2(title) "#{title}\n#{line_for('-', title)}" end |
#header3(title) ⇒ Object
17 18 19 |
# File 'lib/mark_maker/generator.rb', line 17 def header3(title) "### #{title}" end |
#line_for(underscore, content) ⇒ Object
5 6 7 |
# File 'lib/mark_maker/generator.rb', line 5 def line_for(underscore, content) underscore * content.size end |
#link(label, url) ⇒ Object
38 39 40 |
# File 'lib/mark_maker/generator.rb', line 38 def link(label, url) "[#{label}](#{url})" end |
#number(content, number = 1) ⇒ Object
29 30 31 |
# File 'lib/mark_maker/generator.rb', line 29 def number(content, number = 1) " #{number}. #{content}" end |
#numbers(*content) ⇒ Object
33 34 35 36 |
# File 'lib/mark_maker/generator.rb', line 33 def numbers(*content) current_number = 0 content.map { |li| number(li, current_number += 1) } end |
#strong(content) ⇒ Object
73 74 75 |
# File 'lib/mark_maker/generator.rb', line 73 def strong(content) EMPHASIS * 2 + content + EMPHASIS * 2 end |
#table_header(*content) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/mark_maker/generator.rb', line 77 def table_header(*content) [ content.inject("|") { |a, e| a + "#{e}|" }, content.inject("|") { |a, e| a + "-" * e.size + "|" } ] end |
#table_row(*content) ⇒ Object
84 85 86 |
# File 'lib/mark_maker/generator.rb', line 84 def table_row(*content) content.inject("|") { |a, e| a << e << "|" } end |