serenity-odt 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Spec::Rake::SpecTask.new("spec")
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = %q{serenity-odt}
11
- s.version = "0.2.0"
11
+ s.version = "0.2.1"
12
12
 
13
13
  s.authors = ["Tomas Kramar"]
14
14
  s.description = <<-EOF
Binary file
@@ -3,6 +3,11 @@ class String
3
3
  mgsub!([[/&/, '&amp;'], [/</, '&lt;'], [/>/, '&gt;']])
4
4
  end
5
5
 
6
+ def convert_newlines
7
+ gsub!("\n", '<text:line-break/>')
8
+ self
9
+ end
10
+
6
11
  def mgsub!(key_value_pairs=[].freeze)
7
12
  regexp_fragments = key_value_pairs.collect { |k,v| k }
8
13
  gsub!(Regexp.union(*regexp_fragments)) do |match|
@@ -44,13 +44,17 @@ module Serenity
44
44
  end
45
45
 
46
46
  def escape_code code
47
- code.mgsub! [[/&apos;/, "'"], [/&gt;/, '>'], [/&lt/, '<'], [/&quot;/, '"']]
47
+ code.mgsub! [[/&apos;/, "'"], [/&gt;/, '>'], [/&lt/, '<'], [/&quot;/, '"'], [/&amp;/, '&']]
48
48
  end
49
49
  end
50
50
 
51
51
  class StringLine < CodeLine
52
52
  def to_buf
53
- " _buf << (" << escape_code(@text) << ").to_s.escape_xml;"
53
+ " _buf << (" << escape_code(@text) << ").to_s.escape_xml.convert_newlines;"
54
+ end
55
+
56
+ def convert_newlines text
57
+ text.gsub("First line", '<text:line-break>')
54
58
  end
55
59
  end
56
60
 
@@ -51,7 +51,7 @@ module Serenity
51
51
  end
52
52
 
53
53
  def process_instruction text
54
- text = text.strip
54
+ #text = text.strip
55
55
  pos = 0
56
56
  src = []
57
57
 
@@ -10,9 +10,9 @@ module Serenity
10
10
 
11
11
  @src.scan(/<.*?>/) do |node|
12
12
  m = Regexp.last_match
13
- if m.begin(0) > last_match_pos + 1
13
+ if m.begin(0) > last_match_pos
14
14
  text = @src[last_match_pos...m.begin(0)]
15
- yield text.strip, node_type(text) if text.gsub(/\s+/, '') != ''
15
+ yield text, node_type(text) if text.gsub(/\s+/, '') != ''
16
16
  end
17
17
 
18
18
  last_match_pos = m.end(0)
@@ -89,5 +89,14 @@ module Serenity
89
89
 
90
90
  run_spec template, expected
91
91
  end
92
+
93
+ it 'should replace \n with soft newlines' do
94
+ text_with_newline = "First line\nSecond line"
95
+
96
+ template = '<text:p text:style-name="P2">{%= text_with_newline %}</text:p>'
97
+ expected = '<text:p text:style-name="P2">First line <text:line-break/>Second line</text:p>'
98
+
99
+ run_spec template, expected, binding
100
+ end
92
101
  end
93
102
  end
@@ -14,35 +14,50 @@ module Serenity
14
14
  @title = 'captain'
15
15
 
16
16
  template = Template.new(fixture('variables.odt'), 'output_variables.odt')
17
- lambda {template.process binding}.should_not raise_error
17
+ template.process binding
18
+
19
+ 'output_variables.odt'.should contain_in('content.xml', 'Malcolm Reynolds')
20
+ 'output_variables.odt'.should contain_in('content.xml', 'captain')
18
21
  end
19
22
 
20
23
  it "should unroll a simple for loop" do
21
24
  @crew = %w{'River', 'Jayne', 'Wash'}
22
25
 
23
26
  template = Template.new(fixture('loop.odt'), 'output_loop.odt')
24
- lambda {template.process binding}.should_not raise_error
27
+ template.process binding
25
28
  end
26
29
 
27
30
  it "should unroll an advanced loop with tables" do
28
31
  @ships = [Ship.new('Firefly', 'transport'), Ship.new('Colonial', 'battle')]
29
32
 
30
33
  template = Template.new(fixture('loop_table.odt'), 'output_loop_table.odt')
31
- lambda {template.process binding}.should_not raise_error
34
+ template.process binding
35
+
36
+ ['Firefly', 'transport', 'Colonial', 'battle'].each do |text|
37
+ 'output_loop_table.odt'.should contain_in('content.xml', text)
38
+ end
32
39
  end
33
40
 
34
41
  it "should process an advanced document" do
35
42
  @persons = [Person.new('Malcolm', 'captain'), Person.new('River', 'psychic'), Person.new('Jay', 'gunslinger')]
36
43
 
37
44
  template = Template.new(fixture('advanced.odt'), 'output_advanced.odt')
38
- lambda {template.process binding}.should_not raise_error
45
+ template.process binding
46
+
47
+ ['Malcolm', 'captain', 'River', 'psychic', 'Jay', 'gunslinger'].each do |text|
48
+ 'output_advanced.odt'.should contain_in('content.xml', text)
49
+ end
39
50
  end
40
51
 
41
52
  it "should loop and generate table rows" do
42
53
  @ships = [Ship.new('Firefly', 'transport'), Ship.new('Colonial', 'battle')]
43
54
 
44
55
  template = Template.new(fixture('table_rows.odt'), 'output_table_rows.odt')
45
- lambda {template.process binding}.should_not raise_error
56
+ template.process binding
57
+
58
+ ['Firefly', 'transport', 'Colonial', 'battle'].each do |text|
59
+ 'output_table_rows.odt'.should contain_in('content.xml', text)
60
+ end
46
61
  end
47
62
 
48
63
  it "should parse the header" do
@@ -52,5 +67,13 @@ module Serenity
52
67
  template.process(binding)
53
68
  'output_header.odt'.should contain_in('styles.xml', 'captain')
54
69
  end
70
+
71
+ it 'should parse the footer' do
72
+ @title = 'captain'
73
+
74
+ template = Template.new(fixture('footer.odt'), 'output_footer.odt')
75
+ template.process(binding)
76
+ 'output_footer.odt'.should contain_in('styles.xml', 'captain')
77
+ end
55
78
  end
56
79
  end
@@ -31,7 +31,7 @@ module Serenity
31
31
 
32
32
  idx = 0
33
33
  reader.each_node do |node, type|
34
- expected[idx].text.should == node
34
+ expected[idx].text.should == node.strip
35
35
  expected[idx].type.should == type
36
36
  idx += 1
37
37
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serenity-odt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 0
10
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Tomas Kramar
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-23 00:00:00 +02:00
17
+ date: 2010-11-03 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 57
30
28
  segments:
31
29
  - 0
32
30
  - 9
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 13
46
43
  segments:
47
44
  - 1
48
45
  - 2
@@ -80,6 +77,7 @@ files:
80
77
  - spec/template_spec.rb
81
78
  - spec/xml_reader_spec.rb
82
79
  - fixtures/advanced.odt
80
+ - fixtures/footer.odt
83
81
  - fixtures/header.odt
84
82
  - fixtures/loop.odt
85
83
  - fixtures/loop_table.odt
@@ -99,7 +97,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
97
  requirements:
100
98
  - - ">="
101
99
  - !ruby/object:Gem::Version
102
- hash: 3
103
100
  segments:
104
101
  - 0
105
102
  version: "0"
@@ -108,7 +105,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
105
  requirements:
109
106
  - - ">="
110
107
  - !ruby/object:Gem::Version
111
- hash: 3
112
108
  segments:
113
109
  - 0
114
110
  version: "0"
@@ -129,6 +125,7 @@ test_files:
129
125
  - spec/template_spec.rb
130
126
  - spec/xml_reader_spec.rb
131
127
  - fixtures/advanced.odt
128
+ - fixtures/footer.odt
132
129
  - fixtures/header.odt
133
130
  - fixtures/loop.odt
134
131
  - fixtures/loop_table.odt