Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 6 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
2  .gitignore
@@ -1,4 +1,4 @@
pkg
doc
*.gem
-test/*result.odt
+test/result/*.odt
View
2  lib/odf-report/nested.rb
@@ -18,6 +18,8 @@ def get_fields_with_values(data_item)
def get_collection_from_item(item, collection_field)
+ return item[collection_field] if item.is_a?(Hash)
+
if collection_field.is_a?(Array)
tmp = item.dup
collection_field.each do |f|
View
4 lib/odf-report/section.rb
@@ -80,9 +80,7 @@ def replace!(doc, row = nil)
def find_section_node(doc)
- prefix = @parent ? "" : "//"
-
- sections = doc.xpath("#{prefix}text:section[@text:name='#{@name}']")
+ sections = doc.xpath(".//text:section[@text:name='#{@name}']")
sections.empty? ? nil : sections.first
View
19 lib/odf-report/table.rb
@@ -3,7 +3,7 @@ module ODFReport
class Table
include HashGsub, Nested
- attr_accessor :fields, :rows, :name, :collection_field, :data, :header, :parent
+ attr_accessor :fields, :rows, :name, :collection_field, :data, :header, :parent, :tables
def initialize(opts)
@name = opts[:name]
@@ -12,6 +12,7 @@ def initialize(opts)
@parent = opts[:parent]
@fields = {}
+ @tables = []
@template_rows = []
@header = opts[:header] || false
@@ -27,6 +28,14 @@ def add_column(name, field=nil, &block)
end
end
+ def add_table(table_name, collection_field, opts={}, &block)
+ opts.merge!(:name => table_name, :collection_field => collection_field, :parent => self)
+ tab = Table.new(opts)
+ @tables << tab
+
+ yield(tab)
+ end
+
def populate!(row)
@collection = get_collection_from_item(row, @collection_field) if row
end
@@ -45,6 +54,10 @@ def replace!(doc, row = nil)
replace_values!(new_node, data_item)
+ @tables.each do |t|
+ t.replace!(new_node, data_item)
+ end
+
table.add_child(new_node)
end
@@ -83,9 +96,7 @@ def template_length
def find_table_node(doc)
- prefix = @parent ? "" : "//"
-
- tables = doc.xpath("#{prefix}table:table[@table:name='#{@name}']")
+ tables = doc.xpath(".//table:table[@table:name='#{@name}']")
tables.empty? ? nil : tables.first
View
4 odf-report.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{odf-report}
- s.version = "0.4.1"
+ s.version = "0.4.3"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Sandro Duarte"]
- s.date = %q{2011-10-03}
+ s.date = %q{2011-12-27}
s.description = %q{Generates ODF files, given a template (.odt) and data, replacing tags}
s.email = %q{sandrods@gmail.com}
s.extra_rdoc_files = ["lib/odf-report.rb", "README.textile"]
View
BIN  test/test_nested_tables.odt
Binary file not shown
View
39 test/test_nested_tables.rb
@@ -0,0 +1,39 @@
+require '../lib/odf-report'
+require 'ostruct'
+
+class Item
+ attr_accessor :name, :sid, :children
+ def initialize(_name, _sid, _children=[])
+ @name=_name
+ @sid=_sid
+ @children=_children
+ end
+end
+
+items = []
+items << Item.new("LOST", '007', %w(sawyer juliet hurley locke jack freckles))
+items << Item.new("ALIAS", '302', %w(sidney sloane jack michael marshal))
+items << Item.new("GREY'S ANATOMY", '220', %w(meredith christina izzie alex george))
+items << Item.new("BREAKING BAD", '556', %w(pollos gus mike heisenberg))
+
+report = ODFReport::Report.new("test_nested_tables.odt") do |r|
+
+ r.add_field("TAG_01", Time.now)
+ r.add_field("TAG_02", "TAG-2 -> New tag")
+
+ r.add_table("TABLE_MAIN", items) do |s|
+
+ s.add_column('NAME') { |i| i.name }
+
+ s.add_column('SID', :sid)
+
+ s.add_table('TABLE_S1', :children, :header=>true) do |t|
+ t.add_column('NAME1') { |item| "-> #{item}" }
+ t.add_column('INV') { |item| item.to_s.reverse.upcase }
+ end
+
+ end
+
+end
+
+report.generate("./result/test_nested_tables.odt")
View
BIN  test/test_sections.odt
Binary file not shown
View
2  test/test_sections.rb
@@ -36,4 +36,4 @@ def initialize(_name, _sid, _children=[])
end
-report.generate("test_sections_result.odt")
+report.generate("./result/test_sections.odt")
View
2  test/test_sub_sections.rb
@@ -54,4 +54,4 @@ def initialize(_name, _sid, _children=[], _subs=[])
end
-report.generate("test_sub_sections_result.odt")
+report.generate("./result/test_sub_sections.odt")
View
2  test/test_tables.rb
@@ -39,4 +39,4 @@
end
-report.generate("test_tables_result.odt")
+report.generate("./result/test_tables.odt")

No commit comments for this range

Something went wrong with that request. Please try again.