Class: Yardbird::Writer
- Inherits:
-
Object
- Object
- Yardbird::Writer
- Defined in:
- lib/yardbird/writer.rb
Instance Method Summary collapse
- #blank ⇒ Object
- #bullet(s) ⇒ Object
- #code_block(&block) ⇒ Object
- #flush ⇒ Object
- #heading(s, options = {}) ⇒ Object
- #indent(count = 1, &block) ⇒ Object
-
#initialize(stream, options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #line(*args) ⇒ Object
- #section(title, options = {}, &block) ⇒ Object
Constructor Details
#initialize(stream, options = {}) ⇒ Writer
Returns a new instance of Writer.
4 5 6 7 8 |
# File 'lib/yardbird/writer.rb', line 4 def initialize(stream, = {}) @stream = stream @section_level = [:section_level] || 0 @indent_level = 0 end |
Instance Method Details
#blank ⇒ Object
35 36 37 |
# File 'lib/yardbird/writer.rb', line 35 def blank @need_blank = true end |
#bullet(s) ⇒ Object
49 50 51 |
# File 'lib/yardbird/writer.rb', line 49 def bullet(s) line("* #{s}") end |
#code_block(&block) ⇒ Object
53 54 55 56 57 |
# File 'lib/yardbird/writer.rb', line 53 def code_block(&block) indent(4) do yield end end |
#flush ⇒ Object
10 11 12 |
# File 'lib/yardbird/writer.rb', line 10 def flush @stream.flush end |
#heading(s, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/yardbird/writer.rb', line 39 def heading(s, = {}) if (anchor = [:anchor]) s = "<a name='#{anchor}'>#{s}</a>" end blank line(('#' * (@section_level + 1)) + " #{s}") blank end |
#indent(count = 1, &block) ⇒ Object
59 60 61 62 63 |
# File 'lib/yardbird/writer.rb', line 59 def indent(count = 1, &block) @indent_level += count yield @indent_level -= count end |
#line(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/yardbird/writer.rb', line 14 def line(*args) if @need_blank @stream.write("\n") @need_blank = false end @stream.write(' ' * @indent_level) @stream.write(args.join) @stream.write("\n") end |
#section(title, options = {}, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/yardbird/writer.rb', line 24 def section(title, = {}, &block) if title heading(title, ) @section_level += 1 yield @section_level -= 1 else yield end end |