notroff 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,16 +6,28 @@ class CodeTypeRefiner
6
6
 
7
7
  paragraphs.each_with_index do |paragraph, i|
8
8
  type = paragraph[:type]
9
- previous_type = ( paragraphs.first == paragraph) ? nil : paragraphs[i-1][:type]
10
- next_type = ( paragraphs.last == paragraph) ? nil : paragraphs[i+1][:type]
9
+ previous_type = previous_paragraph_type(paragraphs, i)
10
+ next_type = next_paragraph_type(paragraphs, i)
11
11
  new_type = code_type_for( previous_type, type, next_type )
12
- paragraph[:type] = new_type
13
- processed_paragraphs << paragraph
12
+ new_paragraph = paragraph.clone
13
+ new_paragraph[:type] = new_type
14
+ processed_paragraphs << new_paragraph
14
15
  end
15
16
  processed_paragraphs
16
17
  end
17
18
 
19
+ def previous_paragraph_type(paragraphs, i)
20
+ return nil if i <= 0
21
+ paragraphs[i-1][:type]
22
+ end
23
+
24
+ def next_paragraph_type(paragraphs, i)
25
+ return nil if (i + 1) >= paragraphs.size
26
+ paragraphs[i+1][:type]
27
+ end
28
+
18
29
  def code_type_for( previous_type, type, next_type )
30
+ Logger.log "code type for [#{previous_type}] [#{type}] [#{next_type}]"
19
31
  if type != :code
20
32
  new_type = type
21
33
 
@@ -32,6 +44,7 @@ class CodeTypeRefiner
32
44
  new_type = :single_code
33
45
  end
34
46
 
47
+ Logger.log("new type: #{new_type}")
35
48
  new_type
36
49
  end
37
50
  end
@@ -7,8 +7,7 @@ class ParagraphJoiner
7
7
 
8
8
  if join?(paragraph)
9
9
  if new_p
10
- new_p.string += " "
11
- new_p.string += paragraph
10
+ new_p.string = join(new_p.string, paragraph)
12
11
  else
13
12
  new_p = paragraph
14
13
  end
@@ -24,6 +23,10 @@ class ParagraphJoiner
24
23
  processed_paragraphs
25
24
  end
26
25
 
26
+ def join(first, second)
27
+ first + " " + second
28
+ end
29
+
27
30
  def join?(paragraph)
28
31
  false
29
32
  end
@@ -46,6 +49,10 @@ class BodyParagraphJoiner < ParagraphJoiner
46
49
  end
47
50
 
48
51
  class CodeParagraphJoiner < ParagraphJoiner
52
+ def join(first, second)
53
+ first + "\n" + second
54
+ end
55
+
49
56
  def join?(paragraph)
50
57
  return false unless paragraph[:type] == :code
51
58
  true
@@ -24,3 +24,19 @@ describe BodyParagraphJoiner do
24
24
  new_paras[1].string.should == "para4 para5"
25
25
  end
26
26
  end
27
+
28
+ describe CodeParagraphJoiner do
29
+ let(:pj) { CodeParagraphJoiner.new(:code) }
30
+
31
+ let(:paras) do
32
+ paras = %W{ para1 para2 para3 para4 para5}
33
+ paras.map {|p| Text.new(p, :type => :code) }
34
+ end
35
+
36
+ it 'should join paragraphs with the newlines intact' do
37
+ new_paras = pj.process(paras)
38
+ new_paras.size.should == 1
39
+ new_paras[0][:type].should == :code
40
+ new_paras[0].string.should == "para1\npara2\npara3\npara4\npara5"
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notroff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: