energon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +7 -0
- data/README +31 -0
- data/lib/energon/document.rb +105 -0
- data/lib/energon/excel_document.rb +138 -0
- data/lib/energon/od_document.rb +90 -0
- data/lib/energon/open_document_helper.rb +65 -0
- data/lib/energon/open_xml_helper.rb +210 -0
- data/lib/energon/parser.rb +262 -0
- data/lib/energon/word_document.rb +94 -0
- data/lib/energon.rb +24 -0
- data/rakefile.rb +59 -0
- data/test/test_document.rb +150 -0
- data/test/test_excel_document.rb +36 -0
- data/test/test_oo_document.rb +49 -0
- data/test/test_open_document_helper.rb +55 -0
- data/test/test_open_xml_helper.rb +95 -0
- data/test/test_word_document.rb +36 -0
- metadata +86 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'energon'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'rexml/document'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'zip/zipfilesystem'
|
9
|
+
|
10
|
+
include Zip
|
11
|
+
include Woa::Energon
|
12
|
+
|
13
|
+
class TestOpenDocumentHelper < Test::Unit::TestCase
|
14
|
+
|
15
|
+
|
16
|
+
def test_save
|
17
|
+
|
18
|
+
['helper.odt', 'helper.ods'].each do |file|
|
19
|
+
FileUtils.cp("test/opendocument/#{file}", file)
|
20
|
+
|
21
|
+
openxml = OpenDocumentHelper.new(file)
|
22
|
+
document = openxml.content
|
23
|
+
3.times { document.root.add_element('RubyAndTheRubyOnRailsFrameworkRocks') }
|
24
|
+
openxml.save(document)
|
25
|
+
openxml.write
|
26
|
+
|
27
|
+
zip_orig = ZipFile.open("test/opendocument/#{file}")
|
28
|
+
zip_new = ZipFile.open(file)
|
29
|
+
|
30
|
+
xml_orig = REXML::Document.new(zip_orig.file.new('content.xml'))
|
31
|
+
xml_new = REXML::Document.new(zip_new.file.new('content.xml'))
|
32
|
+
|
33
|
+
elements_orig = REXML::XPath.match(xml_orig, '//RubyAndTheRubyOnRailsFrameworkRocks')
|
34
|
+
elements_new = REXML::XPath.match(xml_new , '//RubyAndTheRubyOnRailsFrameworkRocks')
|
35
|
+
|
36
|
+
assert_equal(0, elements_orig.size)
|
37
|
+
assert_equal(3, elements_new.size)
|
38
|
+
|
39
|
+
elements_orig = REXML::XPath.match(xml_orig, '//*')
|
40
|
+
elements_new = REXML::XPath.match(xml_new , '//*')
|
41
|
+
|
42
|
+
assert_equal(elements_orig.size + 3, elements_new.size)
|
43
|
+
|
44
|
+
zip_orig.close
|
45
|
+
zip_new.close
|
46
|
+
|
47
|
+
FileUtils.rm(file) rescue nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_not_a_odt_file
|
52
|
+
FileUtils.cp('test/openxml/excel_template.xlsx', 'helper.ods')
|
53
|
+
assert_raises(InvalidODFDocument) {OpenDocumentHelper.new('helper.ods')}
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'energon'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'rexml/document'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'zip/zipfilesystem'
|
9
|
+
|
10
|
+
include Zip
|
11
|
+
include Woa::Energon
|
12
|
+
|
13
|
+
class TestOpenXmlHelper < Test::Unit::TestCase
|
14
|
+
|
15
|
+
# verify that all the documents are the same xml files
|
16
|
+
def test_new_word
|
17
|
+
openxml1 = OpenXmlHelper.new_word('test/openxml/word_template.docx')
|
18
|
+
openxml2 = OpenXmlHelper.new('test/openxml/word_template.docx', OpenXmlHelper::TypeWord)
|
19
|
+
documents1 = openxml1.documents
|
20
|
+
documents2 = openxml2.documents
|
21
|
+
assert_equal_documents(documents1, documents2)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_wrong_word_type
|
25
|
+
assert_nothing_raised { OpenXmlHelper.new_word('test/openxml/word_template.docx') }
|
26
|
+
assert_raise(InvalidOpenXmlDocument) { OpenXmlHelper.new_word('test/openxml/excel_template.xlsx') }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_wrong_excel_type
|
30
|
+
assert_nothing_raised { OpenXmlHelper.new_excel('test/openxml/excel_template.xlsx') }
|
31
|
+
assert_raise(InvalidOpenXmlDocument) { OpenXmlHelper.new_excel('test/openxml/word_template.docx') }
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_number_of_documents
|
35
|
+
# xl/workbook.xml
|
36
|
+
# xl/worksheets/sheet1.xml
|
37
|
+
# xl/worksheets/sheet2.xml
|
38
|
+
# xl/worksheets/sheet3.xml
|
39
|
+
# xl/worksheets/sheet4.xml
|
40
|
+
openxml = OpenXmlHelper.new_excel('test/openxml/excel_template.xlsx')
|
41
|
+
assert_equal(5, openxml.documents.size)
|
42
|
+
|
43
|
+
# word/document.xml
|
44
|
+
openxml = OpenXmlHelper.new_word('test/openxml/word_template.docx')
|
45
|
+
assert_equal(1, openxml.documents.size)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_save
|
49
|
+
FileUtils.cp('test/openxml/word_template.docx', 'word.docx')
|
50
|
+
|
51
|
+
openxml = OpenXmlHelper.new_word('word.docx')
|
52
|
+
document = openxml.documents.first
|
53
|
+
3.times { document.root.add_element('RubyAndTheRubyOnRailsFrameworkRocks') }
|
54
|
+
openxml.save(document)
|
55
|
+
openxml.write
|
56
|
+
|
57
|
+
zip_orig = ZipFile.open('test/openxml/word_template.docx')
|
58
|
+
zip_new = ZipFile.open('word.docx')
|
59
|
+
|
60
|
+
xml_orig = REXML::Document.new(zip_orig.file.new('word/document.xml'))
|
61
|
+
xml_new = REXML::Document.new(zip_new.file.new('word/document.xml'))
|
62
|
+
|
63
|
+
elements_orig = REXML::XPath.match(xml_orig, '//RubyAndTheRubyOnRailsFrameworkRocks')
|
64
|
+
elements_new = REXML::XPath.match(xml_new , '//RubyAndTheRubyOnRailsFrameworkRocks')
|
65
|
+
|
66
|
+
assert_equal(0, elements_orig.size)
|
67
|
+
assert_equal(3, elements_new.size)
|
68
|
+
|
69
|
+
elements_orig = REXML::XPath.match(xml_orig, '//*')
|
70
|
+
elements_new = REXML::XPath.match(xml_new , '//*')
|
71
|
+
|
72
|
+
assert_equal(elements_orig.size + 3, elements_new.size)
|
73
|
+
|
74
|
+
zip_orig.close
|
75
|
+
zip_new.close
|
76
|
+
|
77
|
+
FileUtils.rm('word.docx') rescue nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_shared_strings
|
81
|
+
openxml = OpenXmlHelper.new_word('test/openxml/word_template.docx')
|
82
|
+
assert_equal(nil, openxml.shared_strings)
|
83
|
+
|
84
|
+
openxml = OpenXmlHelper.new_excel('test/openxml/excel_template.xlsx')
|
85
|
+
assert_instance_of(REXML::Document, openxml.shared_strings)
|
86
|
+
end
|
87
|
+
|
88
|
+
# ############################################
|
89
|
+
# private
|
90
|
+
# ############################################
|
91
|
+
def assert_equal_documents(documents1, documents2)
|
92
|
+
assert_equal(documents2.size, documents1.size)
|
93
|
+
documents1.size.times {|i| assert_equal(documents1[i].to_s, documents2[i].to_s) }
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'energon'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rexml/document'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'ostruct'
|
8
|
+
include Woa::Energon
|
9
|
+
|
10
|
+
class TestWordDocument < Test::Unit::TestCase
|
11
|
+
def test_1
|
12
|
+
FileUtils.cp('test/openxml/word_template.docx', 'word.docx')
|
13
|
+
word = WordDocument.new('word.docx')
|
14
|
+
word.add_value(:title, "Woa Title!")
|
15
|
+
word.add_value(:foo, "Woa Foo!")
|
16
|
+
word.add_value(:bar, "Woa Bar!")
|
17
|
+
word.add_value(:date, Time.now)
|
18
|
+
word.add_value(:table_name, "Woa! Table Name!!")
|
19
|
+
|
20
|
+
elements = []
|
21
|
+
customers = []
|
22
|
+
5.times do |i|
|
23
|
+
element = OpenStruct.new
|
24
|
+
element.login = "login (#{i})"
|
25
|
+
element.password = "******** (#{i})"
|
26
|
+
elements << element
|
27
|
+
customer = OpenStruct.new
|
28
|
+
customer.name = "name (#{i})"
|
29
|
+
customers << customer
|
30
|
+
end
|
31
|
+
|
32
|
+
word.add_value('user', elements)
|
33
|
+
word.add_value('customer', customers)
|
34
|
+
word.close
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: energon
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-03-22 00:00:00 +01:00
|
8
|
+
summary: Report engine outputting Word/Excel OpenXML documents
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: energon@woa.hu
|
12
|
+
homepage: http://www.woa.hu
|
13
|
+
rubyforge_project:
|
14
|
+
description: Energon is a report engine written in ruby. It allows you to create complex and reliable reports from your templates. Both templates and output documents are based on OpenXML format. Energon supports currently Text, Word and Excel documents.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Woa! Kft
|
31
|
+
files:
|
32
|
+
- lib/energon.rb
|
33
|
+
- lib/energon/document.rb
|
34
|
+
- lib/energon/excel_document.rb
|
35
|
+
- lib/energon/od_document.rb
|
36
|
+
- lib/energon/open_document_helper.rb
|
37
|
+
- lib/energon/open_xml_helper.rb
|
38
|
+
- lib/energon/parser.rb
|
39
|
+
- lib/energon/word_document.rb
|
40
|
+
- test/test_document.rb
|
41
|
+
- test/test_excel_document.rb
|
42
|
+
- test/test_oo_document.rb
|
43
|
+
- test/test_open_document_helper.rb
|
44
|
+
- test/test_open_xml_helper.rb
|
45
|
+
- test/test_word_document.rb
|
46
|
+
- README
|
47
|
+
- MIT-LICENSE
|
48
|
+
- rakefile.rb
|
49
|
+
test_files:
|
50
|
+
- test/test_document.rb
|
51
|
+
- test/test_excel_document.rb
|
52
|
+
- test/test_oo_document.rb
|
53
|
+
- test/test_open_document_helper.rb
|
54
|
+
- test/test_open_xml_helper.rb
|
55
|
+
- test/test_word_document.rb
|
56
|
+
rdoc_options:
|
57
|
+
- --main
|
58
|
+
- README
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
requirements:
|
66
|
+
- rubyzip, 0.9.1 or greater
|
67
|
+
- activesupport, 1.3.1 or greater
|
68
|
+
dependencies:
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubyzip
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.9.1
|
77
|
+
version:
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: active_support
|
80
|
+
version_requirement:
|
81
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.1
|
86
|
+
version:
|