Class: Yardbird::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/yardbird/writer.rb

Instance Method Summary collapse

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, options = {})
  @stream = stream
  @section_level = options[:section_level] || 0
  @indent_level = 0
end

Instance Method Details

#blankObject



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

#flushObject



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, options = {})
  if (anchor = options[: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, options = {}, &block)
  if title
    heading(title, options)
    @section_level += 1
    yield
    @section_level -= 1
  else
    yield
  end
end