odf-report 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +2 -1
- data/Gemfile +4 -0
- data/README.textile +3 -15
- data/Rakefile +1 -0
- data/lib/odf-report.rb +4 -1
- data/lib/odf-report/file.rb +19 -54
- data/lib/odf-report/images.rb +12 -5
- data/lib/odf-report/parser/default.rb +90 -0
- data/lib/odf-report/report.rb +33 -12
- data/lib/odf-report/section.rb +16 -2
- data/lib/odf-report/table.rb +2 -0
- data/lib/odf-report/text.rb +43 -0
- data/lib/odf-report/version.rb +2 -2
- data/odf-report.gemspec +9 -6
- data/test/templates/test_fields_inside_text.odt +0 -0
- data/test/{test_nested_tables.odt → templates/test_nested_tables.odt} +0 -0
- data/test/{test_sections.odt → templates/test_sections.odt} +0 -0
- data/test/{test_sub_sections.odt → templates/test_sub_sections.odt} +0 -0
- data/test/templates/test_table_headers.odt +0 -0
- data/test/{test_tables.odt → templates/test_tables.odt} +0 -0
- data/test/templates/test_text.odt +0 -0
- data/test/test_fields_inside_text.rb +37 -0
- data/test/test_nested_tables.rb +2 -2
- data/test/test_sections.rb +2 -2
- data/test/test_sub_sections.rb +2 -2
- data/test/test_table_headers.rb +39 -0
- data/test/test_tables.rb +2 -2
- data/test/test_text.rb +48 -0
- metadata +73 -24
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Mzc3ZTFmODBhMzEzZjQ1MzdmMjIyMDE3OTBlMmZjMTE0MTYxODI3MA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDY1OGI3MTRhY2Q1OTI1YjdkYzgyYjhiYjIwMDZhMjA0NzhmZjc0ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZGEzNjBjYzhhZWMzMGFmNTIyYjdiYTdlNTFlMjA1ZDQyNWMwMWNiODQ3YTg1
|
10
|
+
YTk0OGJhZDYzZTA5NGUxZDFjMmIzMGM1NzVlNDgzZDRhNjVkMGFjNTJiN2Fj
|
11
|
+
MmI4ZTkwN2M3YzZhYjkzMTA2NmVlNzVkOWQyYjA1OWRjZTNmYzk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2Q1Yzk4NGZiMmY3OTg0OWE2NWYyMWYzOTUyYjVlNDI3YWUxYzRiZDZmYjJh
|
14
|
+
MTBlMGUzYzQwZDhiZTBhOGE1ZTAxN2VjMjljZWE2MWFjZTUwM2E4ODhiZmZl
|
15
|
+
ZTljNWU3Mzc0YTkwZjk0OWQ1YWEwNDUzOWFlNGM4MmUxNmYyOTQ=
|
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -2,19 +2,6 @@ h1. ODF-REPORT
|
|
2
2
|
|
3
3
|
Gem for generating .odt files by making strings, images, tables and sections replacements in a previously created .odt file.
|
4
4
|
|
5
|
-
|
6
|
-
h2. NEW!
|
7
|
-
|
8
|
-
<pre>
|
9
|
-
ODF-REPORT have been internally refactored. It now uses Nokogiri for parsing the documents, instead of Regex.
|
10
|
-
|
11
|
-
This provides for a much greater flexibility. As a result, it was possible to implement nested sections and tables.
|
12
|
-
|
13
|
-
Now sections can be nested inside sections, with fields, tables and others sections
|
14
|
-
|
15
|
-
And now, tables can also be nested inside tables.
|
16
|
-
</pre>
|
17
|
-
|
18
5
|
h2. INSTALL
|
19
6
|
|
20
7
|
(sudo) gem install odf-report
|
@@ -109,7 +96,7 @@ end
|
|
109
96
|
|
110
97
|
h3. Sections
|
111
98
|
|
112
|
-
Sometimes, you have to repeat a whole chunk of a document, in a structure a lot more complex than a table. Now you can make a Section in your template and use it in this situations. Creating a
|
99
|
+
Sometimes, you have to repeat a whole chunk of a document, in a structure a lot more complex than a table. Now you can make a Section in your template and use it in this situations. Creating a Section in OpenOffice is as easy as select menu *Insert* and then *Section...*, and then choose a name for it.
|
113
100
|
|
114
101
|
*Section* 's are lot like Tables, in the sense that you can pass a collection and have that section repeated for each member of the collection. *But*, Sections can have anything inside it, even Tables *and nested Sections*, as long as you pass the appropriate data structure.
|
115
102
|
|
@@ -176,6 +163,7 @@ def print
|
|
176
163
|
|
177
164
|
@ticket = Ticket.find(params[:id])
|
178
165
|
|
166
|
+
# For Rails 3 or latest replace #{RAILS_ROOT} to #{Rails.root}
|
179
167
|
report = ODFReport::Report.new("#{RAILS_ROOT}/app/reports/ticket.odt") do |r|
|
180
168
|
|
181
169
|
r.add_field(:id, @ticket.id.to_s)
|
@@ -236,4 +224,4 @@ h3. THE FUTURE
|
|
236
224
|
|
237
225
|
Well, this is my first attempt. This gem was extracted from an actual project we developed internally, to fulfill our specific needs.
|
238
226
|
|
239
|
-
That said, I would really appreciate any input you can come up with. Critics, suggestions, bug reports are welcome and will be thoroughly examined.
|
227
|
+
That said, I would really appreciate any input you can come up with. Critics, suggestions, bug reports are welcome and will be thoroughly examined.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/odf-report.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'zip
|
2
|
+
require 'zip'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'nokogiri'
|
5
5
|
|
6
|
+
require File.expand_path('../odf-report/parser/default', __FILE__)
|
7
|
+
|
6
8
|
require File.expand_path('../odf-report/images', __FILE__)
|
7
9
|
require File.expand_path('../odf-report/field', __FILE__)
|
10
|
+
require File.expand_path('../odf-report/text', __FILE__)
|
8
11
|
require File.expand_path('../odf-report/file', __FILE__)
|
9
12
|
require File.expand_path('../odf-report/fields', __FILE__)
|
10
13
|
require File.expand_path('../odf-report/nested', __FILE__)
|
data/lib/odf-report/file.rb
CHANGED
@@ -1,82 +1,47 @@
|
|
1
1
|
module ODFReport
|
2
|
-
|
3
2
|
class File
|
4
3
|
|
5
|
-
attr_accessor :
|
4
|
+
attr_accessor :data, :output_stream
|
6
5
|
|
7
6
|
def initialize(template)
|
8
|
-
|
9
7
|
raise "Template [#{template}] not found." unless ::File.exists? template
|
10
|
-
|
11
8
|
@template = template
|
12
|
-
@tmp_dir = ::File.join(Dir.tmpdir, random_filename(:prefix=>'odt_'))
|
13
|
-
Dir.mkdir(@tmp_dir) unless ::File.exists? @tmp_dir
|
14
9
|
end
|
15
10
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
FileUtils.cp(@template, @tmp_dir)
|
22
|
-
@path = "#{@tmp_dir}/#{::File.basename(@template)}"
|
11
|
+
def update_content
|
12
|
+
@buffer = Zip::OutputStream.write_buffer do |out|
|
13
|
+
@output_stream = out
|
14
|
+
yield self
|
23
15
|
end
|
24
16
|
end
|
25
17
|
|
26
|
-
def
|
18
|
+
def update_files(*content_files, &block)
|
27
19
|
|
28
|
-
|
20
|
+
Zip::File.open(@template) do |file|
|
29
21
|
|
30
|
-
|
22
|
+
file.each do |entry|
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
24
|
+
unless entry.directory?
|
39
25
|
|
40
|
-
|
26
|
+
data = entry.get_input_stream.read
|
41
27
|
|
42
|
-
|
28
|
+
if content_files.include?(entry.name)
|
29
|
+
yield data
|
30
|
+
end
|
43
31
|
|
44
|
-
|
32
|
+
@output_stream.put_next_entry(entry.name)
|
33
|
+
@output_stream.write data
|
34
|
+
end
|
45
35
|
|
46
|
-
cont = "#{@tmp_dir}/#{content_file}"
|
47
|
-
|
48
|
-
z.extract(content_file, cont)
|
49
|
-
|
50
|
-
txt = ''
|
51
|
-
|
52
|
-
::File.open(cont, "r") do |f|
|
53
|
-
txt = f.read
|
54
|
-
end
|
55
|
-
|
56
|
-
yield(txt)
|
57
|
-
|
58
|
-
::File.open(cont, "w") do |f|
|
59
|
-
f.write(txt)
|
60
36
|
end
|
61
37
|
|
62
|
-
z.replace(content_file, cont)
|
63
38
|
end
|
64
39
|
|
65
40
|
end
|
66
41
|
|
67
|
-
def
|
68
|
-
|
69
|
-
:length => 24, :prefix => '', :suffix => '',
|
70
|
-
:verify => true, :attempts => 10}.merge(opts)
|
71
|
-
opts[:attempts].times do
|
72
|
-
filename = ''
|
73
|
-
opts[:length].times { filename << opts[:chars][rand(opts[:chars].size)] }
|
74
|
-
filename = opts[:prefix] + filename + opts[:suffix]
|
75
|
-
return filename unless opts[:verify] && ::File.exists?(filename)
|
76
|
-
end
|
77
|
-
nil
|
42
|
+
def data
|
43
|
+
@buffer.string
|
78
44
|
end
|
79
45
|
|
80
46
|
end
|
81
|
-
|
82
|
-
end
|
47
|
+
end
|
data/lib/odf-report/images.rb
CHANGED
@@ -19,18 +19,25 @@ module ODFReport
|
|
19
19
|
|
20
20
|
return if @images.empty?
|
21
21
|
|
22
|
-
FileUtils.mkdir(::File.join(file.tmp_dir, IMAGE_DIR_NAME))
|
23
|
-
|
24
22
|
@image_names_replacements.each_pair do |path, template_image|
|
25
23
|
|
26
|
-
file.
|
27
|
-
|
28
|
-
end
|
24
|
+
file.output_stream.put_next_entry(template_image)
|
25
|
+
file.output_stream.write ::File.read(path)
|
29
26
|
|
30
27
|
end
|
31
28
|
|
32
29
|
end # replace_images
|
33
30
|
|
31
|
+
# newer versions of LibreOffice can't open files with duplicates image names
|
32
|
+
def avoid_duplicate_image_names(content)
|
33
|
+
|
34
|
+
nodes = content.xpath("//draw:frame[@draw:name]")
|
35
|
+
|
36
|
+
nodes.each_with_index do |node, i|
|
37
|
+
node.attribute('name').value = "pic_#{i}"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
34
41
|
|
35
42
|
end
|
36
43
|
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module ODFReport
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
|
5
|
+
|
6
|
+
# Default HTML parser
|
7
|
+
#
|
8
|
+
# sample HTML
|
9
|
+
#
|
10
|
+
# <p> first paragraph </p>
|
11
|
+
# <p> second <strong>paragraph</strong> </p>
|
12
|
+
# <blockquote>
|
13
|
+
# <p> first <em>quote paragraph</em> </p>
|
14
|
+
# <p> first quote paragraph </p>
|
15
|
+
# <p> first quote paragraph </p>
|
16
|
+
# </blockquote>
|
17
|
+
# <p> third <strong>paragraph</strong> </p>
|
18
|
+
#
|
19
|
+
# <p style="margin: 100px"> fourth <em>paragraph</em> </p>
|
20
|
+
# <p style="margin: 120px"> fifth paragraph </p>
|
21
|
+
# <p> sixth <strong>paragraph</strong> </p>
|
22
|
+
#
|
23
|
+
|
24
|
+
class Default
|
25
|
+
|
26
|
+
attr_accessor :paragraphs
|
27
|
+
|
28
|
+
def initialize(text, template_node)
|
29
|
+
@text = text
|
30
|
+
@paragraphs = []
|
31
|
+
@template_node = template_node
|
32
|
+
|
33
|
+
parse
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse
|
37
|
+
xml = @template_node.parse(@text)
|
38
|
+
|
39
|
+
xml.css("p", "h1", "h2").each do |p|
|
40
|
+
|
41
|
+
style = check_style(p)
|
42
|
+
text = parse_formatting(p.inner_html)
|
43
|
+
|
44
|
+
add_paragraph(text, style)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_paragraph(text, style)
|
49
|
+
|
50
|
+
node = @template_node.dup
|
51
|
+
|
52
|
+
node['text:style-name'] = style if style
|
53
|
+
node.children = text
|
54
|
+
|
55
|
+
@paragraphs << node
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def parse_formatting(text)
|
61
|
+
text.strip!
|
62
|
+
text.gsub!(/<strong>(.+?)<\/strong>/) { "<text:span text:style-name=\"bold\">#{$1}<\/text:span>" }
|
63
|
+
text.gsub!(/<em>(.+?)<\/em>/) { "<text:span text:style-name=\"italic\">#{$1}<\/text:span>" }
|
64
|
+
text.gsub!(/<u>(.+?)<\/u>/) { "<text:span text:style-name=\"underline\">#{$1}<\/text:span>" }
|
65
|
+
text.gsub!("\n", "")
|
66
|
+
text
|
67
|
+
end
|
68
|
+
|
69
|
+
def check_style(node)
|
70
|
+
style = nil
|
71
|
+
|
72
|
+
if node.name =~ /h\d/i
|
73
|
+
style = "title"
|
74
|
+
|
75
|
+
elsif node.parent && node.parent.name == "blockquote"
|
76
|
+
style = "quote"
|
77
|
+
|
78
|
+
elsif node['style'] =~ /margin/
|
79
|
+
style = "quote"
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
style
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/lib/odf-report/report.rb
CHANGED
@@ -3,12 +3,13 @@ module ODFReport
|
|
3
3
|
class Report
|
4
4
|
include Fields, Images
|
5
5
|
|
6
|
-
attr_accessor :fields, :tables, :images, :sections, :file
|
6
|
+
attr_accessor :fields, :tables, :images, :sections, :file, :texts
|
7
7
|
|
8
8
|
def initialize(template_name, &block)
|
9
9
|
|
10
10
|
@file = ODFReport::File.new(template_name)
|
11
11
|
|
12
|
+
@texts = []
|
12
13
|
@fields = []
|
13
14
|
@tables = []
|
14
15
|
@images = {}
|
@@ -23,7 +24,12 @@ class Report
|
|
23
24
|
opts = {:name => field_tag, :value => value}
|
24
25
|
field = Field.new(opts, &block)
|
25
26
|
@fields << field
|
27
|
+
end
|
26
28
|
|
29
|
+
def add_text(field_tag, value='', &block)
|
30
|
+
opts = {:name => field_tag, :value => value}
|
31
|
+
text = Text.new(opts)
|
32
|
+
@texts << text
|
27
33
|
end
|
28
34
|
|
29
35
|
def add_table(table_name, collection, opts={}, &block)
|
@@ -48,25 +54,34 @@ class Report
|
|
48
54
|
|
49
55
|
def generate(dest = nil)
|
50
56
|
|
51
|
-
@file.
|
57
|
+
@file.update_content do |file|
|
58
|
+
|
59
|
+
file.update_files('content.xml', 'styles.xml') do |txt|
|
52
60
|
|
53
|
-
|
61
|
+
parse_document(txt) do |doc|
|
54
62
|
|
55
|
-
|
63
|
+
replace_texts!(doc)
|
64
|
+
replace_fields!(doc)
|
56
65
|
|
57
|
-
|
58
|
-
|
59
|
-
replace_tables!(doc)
|
66
|
+
replace_sections!(doc)
|
67
|
+
replace_tables!(doc)
|
60
68
|
|
61
|
-
|
69
|
+
find_image_name_matches(doc)
|
70
|
+
avoid_duplicate_image_names(doc)
|
71
|
+
|
72
|
+
end
|
62
73
|
|
63
74
|
end
|
64
75
|
|
65
|
-
|
76
|
+
replace_images(file)
|
66
77
|
|
67
|
-
|
78
|
+
end
|
68
79
|
|
69
|
-
|
80
|
+
if dest
|
81
|
+
::File.open(dest, "w") {|f| f.write(@file.data) }
|
82
|
+
else
|
83
|
+
@file.data
|
84
|
+
end
|
70
85
|
|
71
86
|
end
|
72
87
|
|
@@ -75,13 +90,19 @@ private
|
|
75
90
|
def parse_document(txt)
|
76
91
|
doc = Nokogiri::XML(txt)
|
77
92
|
yield doc
|
78
|
-
txt.replace(doc.
|
93
|
+
txt.replace(doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML))
|
79
94
|
end
|
80
95
|
|
81
96
|
def replace_fields!(content)
|
82
97
|
field_replace!(content)
|
83
98
|
end
|
84
99
|
|
100
|
+
def replace_texts!(content)
|
101
|
+
@texts.each do |text|
|
102
|
+
text.replace!(content)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
85
106
|
def replace_tables!(content)
|
86
107
|
@tables.each do |table|
|
87
108
|
table.replace!(content)
|
data/lib/odf-report/section.rb
CHANGED
@@ -12,6 +12,7 @@ module ODFReport
|
|
12
12
|
@parent = opts[:parent]
|
13
13
|
|
14
14
|
@fields = []
|
15
|
+
@texts = []
|
15
16
|
|
16
17
|
@tables = []
|
17
18
|
@sections = []
|
@@ -24,6 +25,13 @@ module ODFReport
|
|
24
25
|
|
25
26
|
end
|
26
27
|
|
28
|
+
def add_text(name, data_field=nil, &block)
|
29
|
+
opts = {:name => name, :data_field => data_field}
|
30
|
+
field = Text.new(opts, &block)
|
31
|
+
@texts << field
|
32
|
+
|
33
|
+
end
|
34
|
+
|
27
35
|
def add_table(table_name, collection_field, opts={}, &block)
|
28
36
|
opts.merge!(:name => table_name, :collection_field => collection_field, :parent => self)
|
29
37
|
tab = Table.new(opts)
|
@@ -55,7 +63,9 @@ module ODFReport
|
|
55
63
|
@collection.each do |data_item|
|
56
64
|
new_section = template.dup
|
57
65
|
|
58
|
-
|
66
|
+
@texts.each do |t|
|
67
|
+
t.replace!(new_section, data_item)
|
68
|
+
end
|
59
69
|
|
60
70
|
@tables.each do |t|
|
61
71
|
t.replace!(new_section, data_item)
|
@@ -65,6 +75,8 @@ module ODFReport
|
|
65
75
|
s.replace!(new_section, data_item)
|
66
76
|
end
|
67
77
|
|
78
|
+
replace_fields!(new_section, data_item)
|
79
|
+
|
68
80
|
section.before(new_section)
|
69
81
|
|
70
82
|
end
|
@@ -85,4 +97,6 @@ module ODFReport
|
|
85
97
|
|
86
98
|
end
|
87
99
|
|
88
|
-
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
data/lib/odf-report/table.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module ODFReport
|
2
|
+
|
3
|
+
class Text < Field
|
4
|
+
|
5
|
+
attr_accessor :parser
|
6
|
+
|
7
|
+
def replace!(doc, data_item = nil)
|
8
|
+
|
9
|
+
return unless node = find_text_node(doc)
|
10
|
+
|
11
|
+
text_value = get_value(data_item)
|
12
|
+
|
13
|
+
@parser = Parser::Default.new(text_value, node)
|
14
|
+
|
15
|
+
@parser.paragraphs.each do |p|
|
16
|
+
node.before(p)
|
17
|
+
end
|
18
|
+
|
19
|
+
node.remove
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def find_text_node(doc)
|
26
|
+
texts = doc.xpath(".//text:p[text()='#{to_placeholder}']")
|
27
|
+
if texts.empty?
|
28
|
+
texts = doc.xpath(".//text:p/text:span[text()='#{to_placeholder}']")
|
29
|
+
if texts.empty?
|
30
|
+
texts = nil
|
31
|
+
else
|
32
|
+
texts = texts.first.parent
|
33
|
+
end
|
34
|
+
else
|
35
|
+
texts = texts.first
|
36
|
+
end
|
37
|
+
|
38
|
+
texts
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/lib/odf-report/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module ODFReport
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.5.0"
|
3
|
+
end
|
data/odf-report.gemspec
CHANGED
@@ -10,16 +10,19 @@ Gem::Specification.new do |s|
|
|
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.has_rdoc = false
|
13
|
-
s.homepage = %q{
|
13
|
+
s.homepage = %q{http://sandrods.github.com/odf-report/}
|
14
14
|
s.rubygems_version = %q{1.3.7}
|
15
15
|
s.summary = %q{Generates ODF files, given a template (.odt) and data, replacing tags}
|
16
16
|
|
17
|
-
s.files = `git ls-files`.split("\
|
18
|
-
s.
|
19
|
-
s.
|
17
|
+
s.files = `git ls-files -z`.split("\x0")
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.
|
23
|
-
s.
|
22
|
+
s.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
|
25
|
+
s.add_runtime_dependency('rubyzip', "~> 1.1.0")
|
26
|
+
s.add_runtime_dependency('nokogiri', ">= 1.5.0")
|
24
27
|
|
25
28
|
end
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
File without changes
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require '../lib/odf-report'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
html = <<-HTML
|
7
|
+
<p>Uniquely promote installed base total linkage via emerging deliverables com [EVENTO_TEXTO_CARTA], unleash cross-media collaboration <strong>[FUNCAO]</strong> [EVENTO_NOME].</p>
|
8
|
+
|
9
|
+
<p>Progressively fashion diverse portals nº <strong>[NUMERO_SECAO]</strong> do local <strong>[NOME_LOCAL]</strong>, situado na <strong>[ENDERECO_LOCAL]</strong> methodologies </p>
|
10
|
+
|
11
|
+
<p>Assertively orchestrate market positioning bandwidth rather than fully researched total linkage. Interactively architect granular e-markets via clicks-and-mortar ROI. Uniquely aggregate compelling.</p>
|
12
|
+
|
13
|
+
<p>Compellingly facilitate functionalized interfaces before wireless models. Compellingly morph parallel systems whereas combinado com o artigo 63, § 2º da Lei nº 9.504/97, abaixo mencionados:</p>
|
14
|
+
|
15
|
+
<p style="margin-left:1.76cm;"><em>Art. 120 - § 1º Compellingly envisioneer high standards in niches without best-of-breed leadership. Phosfluorescently unleash go forward methodologies after bricks-and-clicks niches. Authoritatively. </em></p>
|
16
|
+
|
17
|
+
<p style="margin-left:1.76cm;"><em>Art. 63 - [...] § 2º Enthusiastically parallel task user friendly functionalities whereas exceptional leadership. </em></p>
|
18
|
+
|
19
|
+
<p>Credibly enable multifunctional strategic theme areas and premium communities.</p>
|
20
|
+
|
21
|
+
HTML
|
22
|
+
|
23
|
+
|
24
|
+
report = ODFReport::Report.new("./templates/test_fields_inside_text.odt") do |r|
|
25
|
+
|
26
|
+
r.add_text(:body, html)
|
27
|
+
|
28
|
+
r.add_field('EVENTO_TEXTO_CARTA', Faker::Lorem.sentence)
|
29
|
+
r.add_field('FUNCAO', Faker::Lorem.word)
|
30
|
+
r.add_field('EVENTO_NOME', Faker::Company.name)
|
31
|
+
|
32
|
+
r.add_field('NUMERO_SECAO', Faker::Number.number(3))
|
33
|
+
r.add_field('NOME_LOCAL', Faker::Company.name)
|
34
|
+
r.add_field('ENDERECO_LOCAL', Faker::Address.street_address)
|
35
|
+
end
|
36
|
+
|
37
|
+
report.generate("./result/test_fields_inside_text.odt")
|
data/test/test_nested_tables.rb
CHANGED
@@ -16,7 +16,7 @@ items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal
|
|
16
16
|
items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george))
|
17
17
|
items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
|
18
18
|
|
19
|
-
report = ODFReport::Report.new("test_nested_tables.odt") do |r|
|
19
|
+
report = ODFReport::Report.new("./templates/test_nested_tables.odt") do |r|
|
20
20
|
|
21
21
|
r.add_field("TAG_01", Time.now)
|
22
22
|
r.add_field("TAG_02", "TAG-2 -> New tag")
|
@@ -36,4 +36,4 @@ report = ODFReport::Report.new("test_nested_tables.odt") do |r|
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
report.generate("./result/test_nested_tables.odt")
|
39
|
+
report.generate("./result/test_nested_tables.odt")
|
data/test/test_sections.rb
CHANGED
@@ -16,7 +16,7 @@ items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal
|
|
16
16
|
items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george))
|
17
17
|
items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
|
18
18
|
|
19
|
-
report = ODFReport::Report.new("test_sections.odt") do |r|
|
19
|
+
report = ODFReport::Report.new("./templates/test_sections.odt") do |r|
|
20
20
|
|
21
21
|
r.add_field("TAG_01", Time.now)
|
22
22
|
r.add_field("TAG_02", "TAG-2 -> New tag")
|
@@ -36,4 +36,4 @@ report = ODFReport::Report.new("test_sections.odt") do |r|
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
report.generate("./result/test_sections.odt")
|
39
|
+
report.generate("./result/test_sections.odt")
|
data/test/test_sub_sections.rb
CHANGED
@@ -27,7 +27,7 @@ items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal
|
|
27
27
|
items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george), subs2)
|
28
28
|
items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
|
29
29
|
|
30
|
-
report = ODFReport::Report.new("test_sub_sections.odt") do |r|
|
30
|
+
report = ODFReport::Report.new("./templates/test_sub_sections.odt") do |r|
|
31
31
|
|
32
32
|
r.add_field("TAG_01", Time.now)
|
33
33
|
r.add_field("TAG_02", "TAG-2 -> New tag")
|
@@ -54,4 +54,4 @@ report = ODFReport::Report.new("test_sub_sections.odt") do |r|
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
-
report.generate("./result/test_sub_sections.odt")
|
57
|
+
report.generate("./result/test_sub_sections.odt")
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require '../lib/odf-report'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'faker'
|
4
|
+
|
5
|
+
class Item
|
6
|
+
attr_accessor :name, :mail
|
7
|
+
def initialize(_name, _mail)
|
8
|
+
@name=_name
|
9
|
+
@mail=_mail
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
items = []
|
14
|
+
50.times do
|
15
|
+
|
16
|
+
items << Item.new(Faker::Name.name, Faker::Internet.email)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
report = ODFReport::Report.new("./templates/test_table_headers.odt") do |r|
|
21
|
+
|
22
|
+
r.add_table("TABLE_01", items, :header => true) do |s|
|
23
|
+
s.add_column(:name)
|
24
|
+
s.add_column(:mail)
|
25
|
+
end
|
26
|
+
|
27
|
+
r.add_table("TABLE_02", items, :header => true) do |s|
|
28
|
+
s.add_column(:name)
|
29
|
+
s.add_column(:mail)
|
30
|
+
end
|
31
|
+
|
32
|
+
r.add_table("TABLE_03", items) do |s|
|
33
|
+
s.add_column(:name)
|
34
|
+
s.add_column(:mail)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
report.generate("./result/test_table_headers.odt")
|
data/test/test_tables.rb
CHANGED
@@ -15,7 +15,7 @@ col2 << OpenStruct.new({:name=>"luiz garcia", 'idx'=>"88", :address=>"address
|
|
15
15
|
|
16
16
|
col3, col4, col5 = [], [], []
|
17
17
|
|
18
|
-
report = ODFReport::Report.new("test_tables.odt") do |r|
|
18
|
+
report = ODFReport::Report.new("./templates/test_tables.odt") do |r|
|
19
19
|
|
20
20
|
r.add_field("HEADER_FIELD", "This field was in the HEADER")
|
21
21
|
|
@@ -59,4 +59,4 @@ report = ODFReport::Report.new("test_tables.odt") do |r|
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
report.generate("./result/test_tables.odt")
|
62
|
+
report.generate("./result/test_tables.odt")
|
data/test/test_text.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require '../lib/odf-report'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'faker'
|
4
|
+
|
5
|
+
class Item
|
6
|
+
attr_accessor :name, :text
|
7
|
+
def initialize(_name, _text)
|
8
|
+
@name=_name
|
9
|
+
@text=_text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
items = []
|
14
|
+
4.times do
|
15
|
+
|
16
|
+
text = <<-HTML
|
17
|
+
<p>#{Faker::Lorem.sentence} <em>#{Faker::Lorem.sentence}</em> #{Faker::Lorem.sentence}</p>
|
18
|
+
<p>#{Faker::Lorem.sentence} <strong>#{Faker::Lorem.paragraph}</strong> #{Faker::Lorem.paragraph}</p>
|
19
|
+
<p>#{Faker::Lorem.paragraph}</p>
|
20
|
+
<blockquote>
|
21
|
+
<p>#{Faker::Lorem.paragraph(10)}</p>
|
22
|
+
<p>#{Faker::Lorem.paragraph}</p>
|
23
|
+
</blockquote>
|
24
|
+
<p style="margin: 150px">#{Faker::Lorem.paragraph(15)}</p>
|
25
|
+
<p>#{Faker::Lorem.paragraph}</p>
|
26
|
+
HTML
|
27
|
+
|
28
|
+
items << Item.new(Faker::Name.name, text)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
item = items.pop
|
33
|
+
|
34
|
+
report = ODFReport::Report.new("./templates/test_text.odt") do |r|
|
35
|
+
|
36
|
+
r.add_field("TAG_01", Faker::Company.name)
|
37
|
+
r.add_field("TAG_02", Faker::Company.catch_phrase)
|
38
|
+
|
39
|
+
r.add_text(:main_text, item.text)
|
40
|
+
|
41
|
+
r.add_section("SECTION_01", items) do |s|
|
42
|
+
s.add_field(:name)
|
43
|
+
s.add_text(:text)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
report.generate("./result/test_text.odt")
|
metadata
CHANGED
@@ -1,38 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odf-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sandro Duarte
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
14
41
|
- !ruby/object:Gem::Dependency
|
15
42
|
name: rubyzip
|
16
|
-
requirement:
|
17
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
18
44
|
requirements:
|
19
45
|
- - ~>
|
20
46
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
47
|
+
version: 1.1.0
|
22
48
|
type: :runtime
|
23
49
|
prerelease: false
|
24
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.0
|
25
55
|
- !ruby/object:Gem::Dependency
|
26
56
|
name: nokogiri
|
27
|
-
requirement:
|
28
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
29
58
|
requirements:
|
30
|
-
- -
|
59
|
+
- - ! '>='
|
31
60
|
- !ruby/object:Gem::Version
|
32
61
|
version: 1.5.0
|
33
62
|
type: :runtime
|
34
63
|
prerelease: false
|
35
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.0
|
36
69
|
description: Generates ODF files, given a template (.odt) and data, replacing tags
|
37
70
|
email: sandrods@gmail.com
|
38
71
|
executables: []
|
@@ -40,62 +73,78 @@ extensions: []
|
|
40
73
|
extra_rdoc_files: []
|
41
74
|
files:
|
42
75
|
- .gitignore
|
76
|
+
- Gemfile
|
43
77
|
- MIT-LICENSE
|
44
78
|
- Manifest
|
45
79
|
- README.textile
|
80
|
+
- Rakefile
|
46
81
|
- lib/odf-report.rb
|
47
82
|
- lib/odf-report/field.rb
|
48
83
|
- lib/odf-report/fields.rb
|
49
84
|
- lib/odf-report/file.rb
|
50
85
|
- lib/odf-report/images.rb
|
51
86
|
- lib/odf-report/nested.rb
|
87
|
+
- lib/odf-report/parser/default.rb
|
52
88
|
- lib/odf-report/report.rb
|
53
89
|
- lib/odf-report/section.rb
|
54
90
|
- lib/odf-report/table.rb
|
91
|
+
- lib/odf-report/text.rb
|
55
92
|
- lib/odf-report/version.rb
|
56
93
|
- odf-report.gemspec
|
57
94
|
- test/piriapolis.jpg
|
58
95
|
- test/rails.png
|
59
|
-
- test/
|
96
|
+
- test/templates/test_fields_inside_text.odt
|
97
|
+
- test/templates/test_nested_tables.odt
|
98
|
+
- test/templates/test_sections.odt
|
99
|
+
- test/templates/test_sub_sections.odt
|
100
|
+
- test/templates/test_table_headers.odt
|
101
|
+
- test/templates/test_tables.odt
|
102
|
+
- test/templates/test_text.odt
|
103
|
+
- test/test_fields_inside_text.rb
|
60
104
|
- test/test_nested_tables.rb
|
61
|
-
- test/test_sections.odt
|
62
105
|
- test/test_sections.rb
|
63
|
-
- test/test_sub_sections.odt
|
64
106
|
- test/test_sub_sections.rb
|
65
|
-
- test/
|
107
|
+
- test/test_table_headers.rb
|
66
108
|
- test/test_tables.rb
|
67
|
-
|
109
|
+
- test/test_text.rb
|
110
|
+
homepage: http://sandrods.github.com/odf-report/
|
68
111
|
licenses: []
|
112
|
+
metadata: {}
|
69
113
|
post_install_message:
|
70
114
|
rdoc_options: []
|
71
115
|
require_paths:
|
72
116
|
- lib
|
73
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
118
|
requirements:
|
76
119
|
- - ! '>='
|
77
120
|
- !ruby/object:Gem::Version
|
78
121
|
version: '0'
|
79
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
123
|
requirements:
|
82
124
|
- - ! '>='
|
83
125
|
- !ruby/object:Gem::Version
|
84
126
|
version: '0'
|
85
127
|
requirements: []
|
86
128
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
129
|
+
rubygems_version: 2.2.2
|
88
130
|
signing_key:
|
89
|
-
specification_version:
|
131
|
+
specification_version: 4
|
90
132
|
summary: Generates ODF files, given a template (.odt) and data, replacing tags
|
91
133
|
test_files:
|
92
134
|
- test/piriapolis.jpg
|
93
135
|
- test/rails.png
|
94
|
-
- test/
|
136
|
+
- test/templates/test_fields_inside_text.odt
|
137
|
+
- test/templates/test_nested_tables.odt
|
138
|
+
- test/templates/test_sections.odt
|
139
|
+
- test/templates/test_sub_sections.odt
|
140
|
+
- test/templates/test_table_headers.odt
|
141
|
+
- test/templates/test_tables.odt
|
142
|
+
- test/templates/test_text.odt
|
143
|
+
- test/test_fields_inside_text.rb
|
95
144
|
- test/test_nested_tables.rb
|
96
|
-
- test/test_sections.odt
|
97
145
|
- test/test_sections.rb
|
98
|
-
- test/test_sub_sections.odt
|
99
146
|
- test/test_sub_sections.rb
|
100
|
-
- test/
|
147
|
+
- test/test_table_headers.rb
|
101
148
|
- test/test_tables.rb
|
149
|
+
- test/test_text.rb
|
150
|
+
has_rdoc: false
|