odf-report 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/odf-report.rb +5 -5
- data/lib/odf-report/report.rb +14 -12
- data/odf-report.gemspec +2 -2
- metadata +4 -12
data/lib/odf-report.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'zip/zipfilesystem'
|
3
3
|
require 'fileutils'
|
4
|
-
require 'odf-report/file_ops'
|
5
|
-
require 'odf-report/hash_gsub'
|
6
|
-
require 'odf-report/section'
|
7
|
-
require 'odf-report/table'
|
8
|
-
require 'odf-report/report'
|
4
|
+
require File.expand_path('../odf-report/file_ops',__FILE__)
|
5
|
+
require File.expand_path('../odf-report/hash_gsub',__FILE__)
|
6
|
+
require File.expand_path('../odf-report/section',__FILE__)
|
7
|
+
require File.expand_path('../odf-report/table',__FILE__)
|
8
|
+
require File.expand_path('../odf-report/report',__FILE__)
|
data/lib/odf-report/report.rb
CHANGED
@@ -11,6 +11,7 @@ class Report
|
|
11
11
|
@values = {}
|
12
12
|
@tables = []
|
13
13
|
@images = {}
|
14
|
+
@image_names_replacements = {}
|
14
15
|
@sections = []
|
15
16
|
|
16
17
|
@tmp_dir = Dir.tmpdir + "/" + random_filename(:prefix=>'odt_')
|
@@ -68,7 +69,7 @@ class Report
|
|
68
69
|
|
69
70
|
replace_fields!(txt)
|
70
71
|
replace_tables!(txt)
|
71
|
-
|
72
|
+
find_image_name_matches(txt)
|
72
73
|
replace_sections!(txt)
|
73
74
|
|
74
75
|
end
|
@@ -77,9 +78,13 @@ class Report
|
|
77
78
|
|
78
79
|
unless @images.empty?
|
79
80
|
image_dir_name = "Pictures"
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
FileUtils.mkdir(File.join("#{@tmp_dir}", image_dir_name))
|
82
|
+
@image_names_replacements.each_pair do |path, template_image|
|
83
|
+
template_image_path = File.join(image_dir_name, template_image)
|
84
|
+
update_file_from_zip(new_file, template_image_path) do |content|
|
85
|
+
content.replace File.read(path)
|
86
|
+
end
|
87
|
+
end
|
83
88
|
end
|
84
89
|
|
85
90
|
new_file
|
@@ -108,20 +113,17 @@ private
|
|
108
113
|
|
109
114
|
end
|
110
115
|
|
111
|
-
def
|
116
|
+
def find_image_name_matches(content)
|
112
117
|
@images.each_pair do |image_name, path|
|
113
|
-
#
|
114
|
-
new_path = File.join("Pictures", File.basename(path))
|
115
|
-
#Search for the image
|
118
|
+
#Search for the image placeholder path
|
116
119
|
image_rgx = Regexp.new("draw:name=\"#{image_name}\".*?><draw:image.*?xlink:href=\"([^\s]*)\" .*?/></draw:frame>")
|
117
120
|
content_match = content.match(image_rgx)
|
118
121
|
if content_match
|
119
|
-
|
120
|
-
|
122
|
+
placeholder_path = content_match[1]
|
123
|
+
@image_names_replacements[path] = File.basename(placeholder_path)
|
121
124
|
end
|
122
125
|
end
|
123
126
|
end
|
124
|
-
|
125
127
|
end
|
126
128
|
|
127
|
-
end
|
129
|
+
end
|
data/odf-report.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{odf-report}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sandro Duarte"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2011-01-24}
|
10
10
|
s.description = %q{Generates ODF files, given a template (.odt) and data, replacing tags}
|
11
11
|
s.email = %q{sandrods@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["lib/odf-report.rb", "README.textile"]
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odf-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Sandro Duarte
|
@@ -15,24 +14,21 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-24 00:00:00 -02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rubyzip
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
27
|
segments:
|
31
28
|
- 0
|
32
29
|
version: "0"
|
33
30
|
- - ">="
|
34
31
|
- !ruby/object:Gem::Version
|
35
|
-
hash: 51
|
36
32
|
segments:
|
37
33
|
- 0
|
38
34
|
- 9
|
@@ -76,20 +72,16 @@ rdoc_options:
|
|
76
72
|
require_paths:
|
77
73
|
- lib
|
78
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
75
|
requirements:
|
81
76
|
- - ">="
|
82
77
|
- !ruby/object:Gem::Version
|
83
|
-
hash: 3
|
84
78
|
segments:
|
85
79
|
- 0
|
86
80
|
version: "0"
|
87
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
82
|
requirements:
|
90
83
|
- - ">="
|
91
84
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 11
|
93
85
|
segments:
|
94
86
|
- 1
|
95
87
|
- 2
|
@@ -97,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
89
|
requirements: []
|
98
90
|
|
99
91
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.3.
|
92
|
+
rubygems_version: 1.3.6
|
101
93
|
signing_key:
|
102
94
|
specification_version: 2
|
103
95
|
summary: Generates ODF files, given a template (.odt) and data, replacing tags
|