odf-report 0.5.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -13
  2. data/.github/workflows/gem-push.yml +40 -0
  3. data/.gitignore +2 -0
  4. data/.rspec +4 -0
  5. data/CHANGELOG.md +56 -0
  6. data/README.md +220 -0
  7. data/Rakefile +8 -0
  8. data/bin/odt-extract +10 -0
  9. data/bin/odt-viewer +18 -0
  10. data/lib/odf-report.rb +11 -9
  11. data/lib/odf-report/data_source.rb +65 -0
  12. data/lib/odf-report/field.rb +35 -36
  13. data/lib/odf-report/image.rb +57 -0
  14. data/lib/odf-report/nestable.rb +65 -0
  15. data/lib/odf-report/parser/default.rb +5 -4
  16. data/lib/odf-report/report.rb +29 -57
  17. data/lib/odf-report/section.rb +17 -80
  18. data/lib/odf-report/table.rb +52 -81
  19. data/lib/odf-report/template.rb +88 -0
  20. data/lib/odf-report/text.rb +2 -4
  21. data/lib/odf-report/version.rb +1 -1
  22. data/odf-report.gemspec +7 -4
  23. data/spec/fields_spec.rb +77 -0
  24. data/spec/images/image_1.jpg +0 -0
  25. data/spec/images/image_2.jpg +0 -0
  26. data/spec/images/image_3.jpg +0 -0
  27. data/{test → spec/images}/piriapolis.jpg +0 -0
  28. data/spec/images/placeholder.jpg +0 -0
  29. data/{test → spec/images}/rails.png +0 -0
  30. data/spec/images_spec.rb +159 -0
  31. data/spec/sections_spec.rb +51 -0
  32. data/spec/spec_helper.rb +43 -0
  33. data/spec/tables_spec.rb +39 -0
  34. data/spec/template_spec.rb +45 -0
  35. data/spec/templates/images.odt +0 -0
  36. data/spec/templates/specs.odt +0 -0
  37. data/test/fields_inside_text_test.rb +38 -0
  38. data/test/images_test.rb +32 -0
  39. data/test/nested_tables_test.rb +43 -0
  40. data/test/sections_test.rb +44 -0
  41. data/test/sub_sections_test.rb +58 -0
  42. data/test/table_headers_test.rb +41 -0
  43. data/test/tables_test.rb +67 -0
  44. data/test/templates/images/image_1.jpg +0 -0
  45. data/test/templates/images/image_2.jpg +0 -0
  46. data/test/templates/images/image_3.jpg +0 -0
  47. data/test/templates/images/placeholder.jpg +0 -0
  48. data/test/templates/images/placeholder.png +0 -0
  49. data/test/templates/piriapolis.jpg +0 -0
  50. data/test/templates/rails.png +0 -0
  51. data/test/templates/test_images.odt +0 -0
  52. data/test/templates/test_sub_sections.odt +0 -0
  53. data/test/templates/test_text.odt +0 -0
  54. data/test/test.rb +262 -0
  55. data/test/text_test.rb +56 -0
  56. metadata +151 -46
  57. data/README.textile +0 -225
  58. data/lib/odf-report/fields.rb +0 -40
  59. data/lib/odf-report/file.rb +0 -50
  60. data/lib/odf-report/images.rb +0 -44
  61. data/lib/odf-report/nested.rb +0 -34
  62. data/test/test_fields_inside_text.rb +0 -37
  63. data/test/test_nested_tables.rb +0 -39
  64. data/test/test_sections.rb +0 -39
  65. data/test/test_sub_sections.rb +0 -57
  66. data/test/test_table_headers.rb +0 -39
  67. data/test/test_tables.rb +0 -62
  68. data/test/test_text.rb +0 -48
@@ -0,0 +1,51 @@
1
+ RSpec.describe "Sections" do
2
+
3
+ before(:context) do
4
+ @itens = Item.get_list(3)
5
+
6
+ report = ODFReport::Report.new("spec/templates/specs.odt") do |r|
7
+
8
+ r.add_section('SECTION_01', @itens) do |t|
9
+ t.add_field(:s01_field_01, :id)
10
+ t.add_field(:s01_field_02, :name)
11
+ end
12
+
13
+ r.add_section('SECTION_02', []) do |t|
14
+ t.add_field(:s02_field_01, :id)
15
+ t.add_field(:s02_field_02, :name)
16
+ end
17
+
18
+ r.add_section('SECTION_03', nil) do |t|
19
+ t.add_field(:s03_field_01, :id)
20
+ t.add_field(:s03_field_02, :name)
21
+ end
22
+
23
+ end
24
+
25
+ report.generate("spec/result/specs.odt")
26
+
27
+ @data = Inspector.new("spec/result/specs.odt")
28
+
29
+ end
30
+
31
+ it "should render section with collection" do
32
+ @itens.each_with_index do |item, idx|
33
+ section = @data.xml.at_xpath(".//text:section[#{idx+1}]").to_s
34
+
35
+ expect(section).to match(item.id.to_s)
36
+ expect(section).to match(item.name)
37
+ end
38
+ end
39
+
40
+ it "should remove section with empty collection" do
41
+ section = @data.xml.at_css("text|section[@text|name='SECTION_02']")
42
+ expect(section).to be_nil
43
+ end
44
+
45
+ it "should remove section with nil collection" do
46
+ section = @data.xml.at_css("text|section[@text|name='SECTION_03']")
47
+ expect(section).to be_nil
48
+ end
49
+
50
+
51
+ end
@@ -0,0 +1,43 @@
1
+ require './lib/odf-report'
2
+ require 'faker'
3
+
4
+ I18n.enforce_available_locales = false
5
+
6
+ class Item
7
+ attr_accessor :id, :name, :subs
8
+ def initialize(_id, _name, _subs=[])
9
+ @name = _name
10
+ @id = _id
11
+ @subs = _subs
12
+ end
13
+
14
+ def self.get_list(quant = 3)
15
+ (1..quant).map do |i|
16
+ Item.new(Faker::Number.number(digits: 10), Faker::Name.name)
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ class Inspector
23
+
24
+ def initialize(file)
25
+ @content = nil
26
+ Zip::File.open(file) do |f|
27
+ @content = f.get_entry('content.xml').get_input_stream.read
28
+ end
29
+ end
30
+
31
+ def xml
32
+ @xml ||= Nokogiri::XML(@content)
33
+ end
34
+
35
+ def text
36
+ @text ||= xml.to_s
37
+ end
38
+
39
+ end
40
+
41
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
42
+ RSpec.configure do |config|
43
+ end
@@ -0,0 +1,39 @@
1
+ RSpec.describe "Tables" do
2
+
3
+ before(:context) do
4
+
5
+ report = ODFReport::Report.new("spec/templates/specs.odt") do |r|
6
+
7
+ r.add_table('TABLE_02', []) do |t|
8
+ t.add_column(:column_01, :id)
9
+ t.add_column(:column_02, :name)
10
+ end
11
+
12
+ r.add_table('TABLE_03', [], skip_if_empty: true) do |t|
13
+ t.add_column(:column_01, :id)
14
+ t.add_column(:column_02, :name)
15
+ end
16
+
17
+ end
18
+
19
+ report.generate("spec/result/specs.odt")
20
+
21
+ @data = Inspector.new("spec/result/specs.odt")
22
+
23
+ end
24
+
25
+ context "with Empty collection" do
26
+
27
+ it "should not remove table" do
28
+ table2 = @data.xml.xpath(".//table:table[@table:name='TABLE_02']")
29
+ expect(table2).not_to be_empty
30
+ end
31
+
32
+ it "should remove table if required" do
33
+ table3 = @data.xml.xpath(".//table:table[@table:name='TABLE_03']")
34
+ expect(table3).to be_empty
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,45 @@
1
+ RSpec.describe "Templates Types" do
2
+
3
+ before(:each) do
4
+
5
+ @field_01 = Faker::Company.name
6
+ @field_02 = Faker::Name.name
7
+
8
+ report.add_field(:field_01, @field_01)
9
+ report.add_field(:field_02, @field_02)
10
+
11
+ report.generate("spec/result/specs.odt")
12
+
13
+ @data = Inspector.new("spec/result/specs.odt")
14
+
15
+ end
16
+
17
+ context "template from file" do
18
+ let(:report) { ODFReport::Report.new("spec/templates/specs.odt") }
19
+
20
+ it "works" do
21
+
22
+ expect(@data.text).not_to match(/\[FIELD_01\]/)
23
+ expect(@data.text).not_to match(/\[FIELD_02\]/)
24
+
25
+ expect(@data.text).to match @field_01
26
+ expect(@data.text).to match @field_02
27
+
28
+ end
29
+ end
30
+
31
+ context "template from a String" do
32
+ let(:report) { ODFReport::Report.new(io: File.open("spec/templates/specs.odt").read) }
33
+
34
+ it "works" do
35
+
36
+ expect(@data.text).not_to match(/\[FIELD_01\]/)
37
+ expect(@data.text).not_to match(/\[FIELD_02\]/)
38
+
39
+ expect(@data.text).to match @field_01
40
+ expect(@data.text).to match @field_02
41
+
42
+ end
43
+ end
44
+
45
+ end
Binary file
Binary file
@@ -0,0 +1,38 @@
1
+ # coding: UTF-8
2
+ require './lib/odf-report'
3
+ require 'faker'
4
+
5
+
6
+ @html = <<-HTML
7
+ <p>Uniquely promote installed base total linkage via emerging deliverables com <strong>[EVENTO_TEXTO_CARTA]</strong>, 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
+
25
+ report = ODFReport::Report.new("test/templates/test_fields_inside_text.odt") do |r|
26
+
27
+ r.add_text(:body, @html)
28
+
29
+ r.add_field('EVENTO_TEXTO_CARTA', Faker::Lorem.sentence)
30
+ r.add_field('FUNCAO', Faker::Lorem.word)
31
+ r.add_field('EVENTO_NOME', Faker::Company.name)
32
+
33
+ r.add_field('NUMERO_SECAO', Faker::Number.number(3))
34
+ r.add_field('NOME_LOCAL', Faker::Company.name)
35
+ r.add_field('ENDERECO_LOCAL', Faker::Address.street_address)
36
+ end
37
+
38
+ report.generate("test/result/test_fields_inside_text.odt")
@@ -0,0 +1,32 @@
1
+ require './lib/odf-report'
2
+ require 'ostruct'
3
+ require 'launchy'
4
+
5
+
6
+ @data = []
7
+ @data << OpenStruct.new({ name: "IMG - [1, 1]", path: 'test/templates/images/image_1.jpg', path2: 'test/templates/images/image_1.jpg' })
8
+ @data << OpenStruct.new({ name: "IMG - [2, 1]", path: 'test/templates/images/image_2.jpg', path2: 'test/templates/images/image_1.jpg' })
9
+ @data << OpenStruct.new({ name: "IMG - [3, 2]", path: 'test/templates/images/image_3.jpg', path2: 'test/templates/images/image_2.jpg' })
10
+ @data << OpenStruct.new({ name: "IMG - [1, 3]", path: 'test/templates/images/image_1.jpg', path2: 'test/templates/images/image_3.jpg' })
11
+ @data << OpenStruct.new({ name: "IMG - [2, 2]", path: 'test/templates/images/image_2.jpg', path2: 'test/templates/images/image_2.jpg' })
12
+
13
+ report = ODFReport::Report.new("test/templates/test_images.odt") do |r|
14
+
15
+ r.add_image("graphics2", 'test/templates/rails.png')
16
+ r.add_image("graphics3", 'test/templates/piriapolis.jpg')
17
+
18
+ r.add_table('IMAGE_TABLE', @data) do |t|
19
+ t.add_column(:image_name, :name)
20
+ t.add_image('IMAGE_IN_TABLE', :path)
21
+ t.add_image('IMAGE_2', :path2)
22
+ end
23
+
24
+ r.add_section('SECTION', @data) do |t|
25
+ t.add_field(:image_name, :name)
26
+ t.add_image('IMAGE_IN_SECTION_1', :path)
27
+ t.add_image('IMAGE_IN_SECTION_2', :path2)
28
+ end
29
+
30
+ end
31
+
32
+ report.generate("test/result/test_images.odt")
@@ -0,0 +1,43 @@
1
+ # coding: UTF-8
2
+ require './lib/odf-report'
3
+ require 'faker'
4
+ require 'launchy'
5
+
6
+
7
+ class Item
8
+ attr_accessor :name, :sid, :children
9
+ def initialize(_name, _sid, _children=[])
10
+ @name=_name
11
+ @sid=_sid
12
+ @children=_children
13
+ end
14
+ end
15
+
16
+ @items = []
17
+ @items << Item.new("LOST", '007', %w(sawyer juliet hurley locke jack freckles))
18
+ @items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal))
19
+ @items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george))
20
+ @items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
21
+
22
+
23
+ report = ODFReport::Report.new("test/templates/test_nested_tables.odt") do |r|
24
+
25
+ r.add_field("TAG_01", Time.now)
26
+ r.add_field("TAG_02", "TAG-2 -> New tag")
27
+
28
+ r.add_table("TABLE_MAIN", @items) do |s|
29
+
30
+ s.add_column('NAME') { |i| i.name }
31
+
32
+ s.add_column('SID', :sid)
33
+
34
+ s.add_table('TABLE_S1', :children, :header=>true) do |t|
35
+ t.add_column('NAME1') { |item| "-> #{item}" }
36
+ t.add_column('INV') { |item| item.to_s.reverse.upcase }
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ report.generate("test/result/test_nested_tables.odt")
@@ -0,0 +1,44 @@
1
+ require './lib/odf-report'
2
+ require 'ostruct'
3
+ require 'faker'
4
+ require 'launchy'
5
+
6
+
7
+ class Item
8
+ attr_accessor :name, :sid, :children
9
+ def initialize(_name, _sid, _children=[])
10
+ @name=_name
11
+ @sid=_sid
12
+ @children=_children
13
+ end
14
+ end
15
+
16
+
17
+ @items = []
18
+ @items << Item.new("LOST", '007', %w(sawyer juliet hurley locke jack freckles))
19
+ @items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal))
20
+ @items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george))
21
+ @items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
22
+
23
+
24
+ report = ODFReport::Report.new("test/templates/test_sections.odt") do |r|
25
+
26
+ r.add_field("TAG_01", Time.now)
27
+ r.add_field("TAG_02", "TAG-2 -> New tag")
28
+
29
+ r.add_section("SECTION_01", @items) do |s|
30
+
31
+ s.add_field('NAME') { |i| i.name }
32
+
33
+ s.add_field('SID', :sid)
34
+
35
+ s.add_table('TABLE_S1', :children, :header=>true) do |t|
36
+ t.add_column('NAME1') { |item| "-> #{item}" }
37
+ t.add_column('INV') { |item| item.to_s.reverse.upcase }
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ report.generate("test/result/test_sections.odt")
@@ -0,0 +1,58 @@
1
+ require './lib/odf-report'
2
+ require 'ostruct'
3
+ require 'faker'
4
+ require 'launchy'
5
+
6
+
7
+ class Item
8
+ attr_accessor :name, :sid, :children, :subs
9
+ def initialize(_name, _sid, _children=[], _subs=[])
10
+ @name=_name
11
+ @sid=_sid
12
+ @children=_children
13
+ @subs=_subs
14
+ end
15
+ end
16
+
17
+
18
+
19
+ subs1 = []
20
+ subs1 << Item.new("SAWYER", 1, %w(Your bones don't break))
21
+ subs1 << Item.new("HURLEY", 2, %w(Your cells react to bacteria and viruses))
22
+ subs1 << Item.new("LOCKE", 3, %W(Do you see any Teletubbies in here))
23
+
24
+ subs2 = []
25
+ subs2 << Item.new("SLOANE", 21, %w(Praesent hendrerit lectus sit amet))
26
+ subs2 << Item.new("JACK", 22, %w(Donec nec est eget dolor laoreet))
27
+ subs2 << Item.new("MICHAEL", 23, %W(Integer elementum massa at nulla placerat varius))
28
+
29
+ @items = []
30
+ @items << Item.new("LOST", '007', [], subs1)
31
+ @items << Item.new("GREY'S ANATOMY", '220', nil)
32
+ @items << Item.new("ALIAS", '302', nil, subs2)
33
+ @items << Item.new("BREAKING BAD", '556', [])
34
+
35
+
36
+ report = ODFReport::Report.new("test/templates/test_sub_sections.odt") do |r|
37
+
38
+ r.add_field("TAG_01", Time.now)
39
+ r.add_field("TAG_02", "TAG-2 -> New tag")
40
+
41
+ r.add_section("SECTION_01", @items) do |s|
42
+
43
+ s.add_field('NAME') { |i| i.name }
44
+
45
+ s.add_field('SID', :sid)
46
+
47
+ s.add_section('SUB_01', :subs) do |r|
48
+ r.add_field("FIRST_NAME", :name)
49
+ r.add_table('IPSUM_TABLE', :children, :header => true) do |t|
50
+ t.add_column('IPSUM_ITEM') { |i| i }
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ report.generate("test/result/test_sub_sections.odt")
@@ -0,0 +1,41 @@
1
+ require './lib/odf-report'
2
+ require 'ostruct'
3
+ require 'faker'
4
+ require 'launchy'
5
+
6
+
7
+ class Item
8
+ attr_accessor :name, :mail
9
+ def initialize(_name, _mail)
10
+ @name=_name
11
+ @mail=_mail
12
+ end
13
+ end
14
+
15
+
16
+
17
+ @items = []
18
+ 50.times { @items << Item.new(Faker::Name.name, Faker::Internet.email) }
19
+
20
+
21
+
22
+ report = ODFReport::Report.new("test/templates/test_table_headers.odt") do |r|
23
+
24
+ r.add_table("TABLE_01", @items, :header => true) do |s|
25
+ s.add_column(:name)
26
+ s.add_column(:mail)
27
+ end
28
+
29
+ r.add_table("TABLE_02", @items, :header => true) do |s|
30
+ s.add_column(:name)
31
+ s.add_column(:mail)
32
+ end
33
+
34
+ r.add_table("TABLE_03", @items) do |s|
35
+ s.add_column(:name)
36
+ s.add_column(:mail)
37
+ end
38
+
39
+ end
40
+
41
+ report.generate("test/result/test_table_headers.odt")