xmlss 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -11
- data/README.rdoc +141 -107
- data/Rakefile +24 -1
- data/bench/profiler.rb +6 -0
- data/bench/profiler_runner.rb +43 -0
- data/examples/example_workbook.rb +8 -12
- data/examples/layout.rb +34 -60
- data/examples/layout.xml +66 -0
- data/examples/simple.rb +16 -21
- data/examples/simple.xml +32 -0
- data/examples/styles.rb +52 -56
- data/examples/styles.xml +50 -0
- data/examples/text.rb +18 -28
- data/examples/text.xml +20 -0
- data/lib/xmlss/{cell.rb → element/cell.rb} +4 -14
- data/lib/xmlss/{column.rb → element/column.rb} +2 -7
- data/lib/xmlss/{data.rb → element/data.rb} +7 -12
- data/lib/xmlss/{row.rb → element/row.rb} +2 -13
- data/lib/xmlss/{worksheet.rb → element/worksheet.rb} +7 -18
- data/lib/xmlss/style/alignment.rb +3 -10
- data/lib/xmlss/style/base.rb +6 -45
- data/lib/xmlss/style/border.rb +5 -5
- data/lib/xmlss/style/font.rb +2 -9
- data/lib/xmlss/style/interior.rb +2 -5
- data/lib/xmlss/style/number_format.rb +4 -7
- data/lib/xmlss/style/protection.rb +4 -7
- data/lib/xmlss/undies_writer.rb +172 -0
- data/lib/xmlss/version.rb +1 -1
- data/lib/xmlss/workbook.rb +97 -31
- data/lib/xmlss.rb +1 -28
- data/test/{cell_test.rb → element/cell_test.rb} +11 -35
- data/test/{column_test.rb → element/column_test.rb} +6 -12
- data/test/{data_test.rb → element/data_test.rb} +15 -10
- data/test/{row_test.rb → element/row_test.rb} +5 -35
- data/test/{worksheet_test.rb → element/worksheet_test.rb} +4 -30
- data/test/helper.rb +13 -30
- data/test/style/alignment_test.rb +13 -45
- data/test/style/base_test.rb +1 -106
- data/test/style/border_test.rb +12 -32
- data/test/style/font_test.rb +11 -43
- data/test/style/interior_test.rb +7 -27
- data/test/style/number_format_test.rb +5 -21
- data/test/style/protection_test.rb +2 -12
- data/test/undies_writer_test.rb +333 -0
- data/test/workbook_test.rb +89 -44
- data/xmlss.gemspec +2 -2
- metadata +37 -39
- data/lib/xmlss/item_set.rb +0 -17
- data/lib/xmlss/table.rb +0 -22
- data/lib/xmlss/xml.rb +0 -60
- data/test/item_set_test.rb +0 -27
- data/test/table_test.rb +0 -56
- data/test/xml_test.rb +0 -81
- data/test/xmlss_test.rb +0 -31
data/lib/xmlss/table.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'xmlss/item_set'
|
2
|
-
require 'xmlss/column'
|
3
|
-
require 'xmlss/row'
|
4
|
-
|
5
|
-
module Xmlss
|
6
|
-
class Table
|
7
|
-
|
8
|
-
include Xmlss::Xml
|
9
|
-
def xml
|
10
|
-
{ :node => :table,
|
11
|
-
:children => [:columns, :rows] }
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :columns, :rows
|
15
|
-
|
16
|
-
def initialize(attrs={})
|
17
|
-
self.columns = Xmlss::ItemSet.new(nil, attrs[:columns] || [])
|
18
|
-
self.rows = Xmlss::ItemSet.new(nil, attrs[:rows] || [])
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
data/lib/xmlss/xml.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
# common methods used for generating XML
|
4
|
-
module Xmlss
|
5
|
-
XML_NS = "xmlns"
|
6
|
-
SHEET_NS = "ss"
|
7
|
-
NS_URI = "urn:schemas-microsoft-com:office:spreadsheet"
|
8
|
-
|
9
|
-
module Xml
|
10
|
-
|
11
|
-
def xml_builder
|
12
|
-
::Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |builder|
|
13
|
-
yield(builder) if block_given?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def build_node(builder, attrs={})
|
18
|
-
unless xml && xml.kind_of?(::Hash)
|
19
|
-
raise ArgumentError, "no xml config provided"
|
20
|
-
end
|
21
|
-
if xml[:node] && !xml[:node].to_s.empty?
|
22
|
-
if xml[:value] && (v = self.send(xml[:value]).to_s)
|
23
|
-
builder.send(Xmlss.classify(xml[:node]), v, build_attributes(attrs))
|
24
|
-
else
|
25
|
-
builder.send(Xmlss.classify(xml[:node]), build_attributes(attrs)) do
|
26
|
-
build_children(builder)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
else
|
30
|
-
build_children(builder)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def xml_save_with(*options)
|
35
|
-
::Nokogiri::XML::Node::SaveOptions::AS_XML |
|
36
|
-
(options.include?(:format) ? ::Nokogiri::XML::Node::SaveOptions::FORMAT : 0)
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_attributes(attrs={})
|
40
|
-
(xml[:attributes] || []).inject({}) do |xattrs, a|
|
41
|
-
xattrs.merge(if !(xv = Xmlss.xmlify(self.send(a))).nil?
|
42
|
-
{"#{Xmlss::SHEET_NS}:#{Xmlss.classify(a)}" => xv}
|
43
|
-
else
|
44
|
-
{}
|
45
|
-
end)
|
46
|
-
end.merge(attrs)
|
47
|
-
end
|
48
|
-
private :build_attributes
|
49
|
-
|
50
|
-
def build_children(builder)
|
51
|
-
(xml[:children] || []).each do |c|
|
52
|
-
if (child = c.kind_of?(::Symbol) ? self.send(c) : c)
|
53
|
-
child.build_node(builder) if child.respond_to?(:build_node)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
private :build_children
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
data/test/item_set_test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "assert"
|
2
|
-
require 'xmlss/item_set'
|
3
|
-
|
4
|
-
module Xmlss
|
5
|
-
class ItemSetTest < Assert::Context
|
6
|
-
desc "Xmlss::ItemSet"
|
7
|
-
subject { ItemSet.new(:test) }
|
8
|
-
|
9
|
-
should have_reader :name
|
10
|
-
|
11
|
-
should "be an Array" do
|
12
|
-
assert_kind_of ::Array, subject
|
13
|
-
assert_respond_to :each, subject
|
14
|
-
assert_empty subject
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
class ItemSetXmlTest < ItemSetTest
|
20
|
-
desc "for generating XML"
|
21
|
-
|
22
|
-
should have_reader :xml
|
23
|
-
should_build_node
|
24
|
-
should_build_no_attributes_by_default(ItemSet)
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/test/table_test.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "assert"
|
2
|
-
require 'xmlss/table'
|
3
|
-
|
4
|
-
module Xmlss
|
5
|
-
class TableTest < Assert::Context
|
6
|
-
desc "Xmlss::Table"
|
7
|
-
before { @tbl = Table.new }
|
8
|
-
subject { @tbl }
|
9
|
-
|
10
|
-
should have_accessor :columns, :rows
|
11
|
-
|
12
|
-
should "set it's defaults" do
|
13
|
-
assert_equal [], subject.columns
|
14
|
-
assert_equal [], subject.rows
|
15
|
-
end
|
16
|
-
|
17
|
-
should "allow defining a rows/columns at init" do
|
18
|
-
tbl = Table.new({
|
19
|
-
:columns => [Column.new],
|
20
|
-
:rows => [Row.new]
|
21
|
-
})
|
22
|
-
|
23
|
-
assert_equal 1, tbl.columns.size
|
24
|
-
assert_kind_of Column, tbl.columns.first
|
25
|
-
assert_equal 1, tbl.rows.size
|
26
|
-
assert_kind_of Row, tbl.rows.first
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
class TableXmlTest < TableTest
|
32
|
-
desc "for generating XML"
|
33
|
-
should have_reader :xml
|
34
|
-
should_build_node
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
class TableRowsColsTest < TableTest
|
39
|
-
desc "when using rows/columns"
|
40
|
-
before do
|
41
|
-
subject.columns << Column.new
|
42
|
-
r = Row.new
|
43
|
-
r.cells << Cell.new
|
44
|
-
subject.rows << r
|
45
|
-
end
|
46
|
-
|
47
|
-
should "should build a table object" do
|
48
|
-
assert_equal 1, subject.columns.size
|
49
|
-
assert_kind_of Column, subject.columns.first
|
50
|
-
assert_equal 1, subject.rows.size
|
51
|
-
assert_kind_of Row, subject.rows.first
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/test/xml_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require "assert"
|
2
|
-
require 'test/thing'
|
3
|
-
|
4
|
-
module Xmlss
|
5
|
-
class XmlTest < Assert::Context
|
6
|
-
desc "Xmlss::Xml"
|
7
|
-
before { @thing = Thing.new }
|
8
|
-
subject { @thing }
|
9
|
-
|
10
|
-
should "should provide proper namespace constants" do
|
11
|
-
assert_equal "xmlns", Xmlss::XML_NS
|
12
|
-
assert_equal "ss", Xmlss::SHEET_NS
|
13
|
-
assert_equal "urn:schemas-microsoft-com:office:spreadsheet", Xmlss::NS_URI
|
14
|
-
end
|
15
|
-
|
16
|
-
should "bark if you use xml generation without configuring" do
|
17
|
-
assert_raises ArgumentError do
|
18
|
-
::Nokogiri::XML::Builder.new do |builder|
|
19
|
-
subject.build_node(builder)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
class XmlConfigTest < XmlTest
|
27
|
-
desc "with config"
|
28
|
-
before do
|
29
|
-
subject.xml = {
|
30
|
-
:node => :thing,
|
31
|
-
:attributes => [:one, :two, :three],
|
32
|
-
:children => [:child_nodes]
|
33
|
-
}
|
34
|
-
subject.one = true
|
35
|
-
subject.two = "two"
|
36
|
-
subject.three = ""
|
37
|
-
end
|
38
|
-
|
39
|
-
should "build it's node" do
|
40
|
-
assert_nothing_raised do
|
41
|
-
::Nokogiri::XML::Builder.new do |builder|
|
42
|
-
subject.build_node(builder)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
should "build with no whitespace formatting by default" do
|
48
|
-
assert_equal(
|
49
|
-
"<?xml version=\"1.0\"?>\n<Thing ss:One=\"1\" ss:Two=\"two\"><Nodes/></Thing>\n",
|
50
|
-
::Nokogiri::XML::Builder.new do |builder|
|
51
|
-
subject.build_node(builder)
|
52
|
-
end.to_xml({:save_with => subject.xml_save_with})
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "build with whitespace formatting if specified" do
|
57
|
-
assert_equal(
|
58
|
-
"<?xml version=\"1.0\"?>\n<Thing ss:One=\"1\" ss:Two=\"two\">\n <Nodes/>\n</Thing>\n",
|
59
|
-
::Nokogiri::XML::Builder.new do |builder|
|
60
|
-
subject.build_node(builder)
|
61
|
-
end.to_xml({:save_with => subject.xml_save_with(:format)})
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
should "generate build attributes based on it's own attributes" do
|
66
|
-
assert_nothing_raised do
|
67
|
-
subject.send :build_attributes
|
68
|
-
end
|
69
|
-
attrs = subject.send :build_attributes
|
70
|
-
|
71
|
-
assert_kind_of ::Hash, attrs
|
72
|
-
assert attrs.has_key?("#{Xmlss::SHEET_NS}:One")
|
73
|
-
assert_equal 1, attrs["#{Xmlss::SHEET_NS}:One"]
|
74
|
-
assert attrs.has_key?("#{Xmlss::SHEET_NS}:Two")
|
75
|
-
assert_equal 'two', attrs["#{Xmlss::SHEET_NS}:Two"]
|
76
|
-
assert !attrs.has_key?("#{Xmlss::SHEET_NS}:Three")
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
data/test/xmlss_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "assert"
|
2
|
-
|
3
|
-
class XmlssTest < Assert::Context
|
4
|
-
desc "Xmlss helpers"
|
5
|
-
subject { Xmlss }
|
6
|
-
|
7
|
-
should "be provided" do
|
8
|
-
assert_respond_to :classify, subject
|
9
|
-
assert_respond_to :xmlify, subject
|
10
|
-
end
|
11
|
-
|
12
|
-
should "classify underscored strings" do
|
13
|
-
assert_nothing_raised do
|
14
|
-
subject.send(:classify, 'poo')
|
15
|
-
end
|
16
|
-
assert_equal "Poo", subject.send(:classify, 'poo')
|
17
|
-
assert_equal "MorePoo", subject.send(:classify, 'more_poo')
|
18
|
-
end
|
19
|
-
|
20
|
-
should "filter values for use in XML" do
|
21
|
-
assert_nothing_raised do
|
22
|
-
subject.send(:xmlify, 'poo')
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal 1, subject.send(:xmlify, true)
|
26
|
-
assert_equal nil, subject.send(:xmlify, false)
|
27
|
-
assert_equal nil, subject.send(:xmlify, "")
|
28
|
-
assert_equal "poo", subject.send(:xmlify, 'poo')
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|