Class: SpecRenderer

Inherits:
Processor show all
Includes:
REXML, Tokenize
Defined in:
lib/notroff/spec_renderer.rb

Constant Summary collapse

@@footnote_number =
1

Instance Method Summary collapse

Methods included from Tokenize

#parse_link, #remove_escapes, #token_text, #token_type, #tokenize_body_text

Constructor Details

#initializeSpecRenderer

Returns a new instance of SpecRenderer.



11
12
13
# File 'lib/notroff/spec_renderer.rb', line 11

def initialize
  @last_code = false
end

Instance Method Details

#code_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/notroff/spec_renderer.rb', line 49

def code_type?( type )
  [ :first_code, :middle_code, :end_code, :single_code,
    :listing, :first_listing, :middle_listing, :end_listing ].include?(type)
end

#format(para) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/notroff/spec_renderer.rb', line 24

def format( para )
  Logger.log "Format: #{para.inspect}"
  type = para[:type]
  text = para

  this_code = code_type?(type)


  if @last_code and this_code
    ret =  "#{para}\n"

  elsif @last_code
    ret =  "##FOO_B\n  end\n"

  elsif this_code
    ret = "\n  it 'should foo' do\n##FOO_A\n#{para}\n"

  else
    ret = nil
  end

  @last_code = this_code
  ret
end

#process(paragraphs) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/notroff/spec_renderer.rb', line 15

def process( paragraphs )
  elements = []
  paragraphs.each do |paragraph|
    new_element = format( paragraph )
    elements << new_element if new_element
  end
  "require 'utils/utils'\n\ndescribe 'foo' do\n\n#{elements.join}\nend\n"
end