xmlss 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/examples/example_workbook.rb +2 -2
- data/examples/simple.rb +1 -1
- data/examples/styles.rb +1 -1
- data/examples/text.rb +1 -1
- data/lib/xmlss/version.rb +1 -1
- data/lib/xmlss/workbook.rb +4 -2
- data/lib/xmlss/xml.rb +5 -0
- data/test/thing.rb +4 -0
- data/test/xml_test.rb +20 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -8,10 +8,10 @@ class ExampleWorkbook < Xmlss::Workbook
|
|
8
8
|
build
|
9
9
|
end
|
10
10
|
|
11
|
-
def to_file
|
11
|
+
def to_file(*options)
|
12
12
|
# write this workbooks xml data to a file
|
13
13
|
File.open("examples/#{self.name}.xml", "w") do |file|
|
14
|
-
file.write self.to_xml
|
14
|
+
file.write self.to_xml(*options)
|
15
15
|
end
|
16
16
|
puts "... ready - open in Excel or whatever..."
|
17
17
|
end
|
data/examples/simple.rb
CHANGED
data/examples/styles.rb
CHANGED
data/examples/text.rb
CHANGED
data/lib/xmlss/version.rb
CHANGED
data/lib/xmlss/workbook.rb
CHANGED
@@ -36,13 +36,15 @@ module Xmlss
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def to_xml
|
39
|
+
def to_xml(*options)
|
40
40
|
xml_builder do |builder|
|
41
41
|
build_node(builder, {
|
42
42
|
Xmlss::XML_NS => Xmlss::NS_URI,
|
43
43
|
"#{Xmlss::XML_NS}:#{Xmlss::SHEET_NS}" => Xmlss::NS_URI
|
44
44
|
})
|
45
|
-
end.
|
45
|
+
end.
|
46
|
+
to_xml({:save_with => xml_save_with(*options)}).
|
47
|
+
gsub(/#{Xmlss::Data::LB.gsub(/&/, "&")}/, Xmlss::Data::LB)
|
46
48
|
end
|
47
49
|
|
48
50
|
end
|
data/lib/xmlss/xml.rb
CHANGED
@@ -31,6 +31,11 @@ module Xmlss
|
|
31
31
|
end
|
32
32
|
end
|
33
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
|
+
|
34
39
|
def build_attributes(attrs={})
|
35
40
|
(xml[:attributes] || []).inject({}) do |xattrs, a|
|
36
41
|
xattrs.merge(if !(xv = Xmlss.xmlify(self.send(a))).nil?
|
data/test/thing.rb
CHANGED
data/test/xml_test.rb
CHANGED
@@ -25,7 +25,8 @@ module Xmlss
|
|
25
25
|
before do
|
26
26
|
subject.xml = {
|
27
27
|
:node => :thing,
|
28
|
-
:attributes => [:one, :two, :three]
|
28
|
+
:attributes => [:one, :two, :three],
|
29
|
+
:children => [:child_nodes]
|
29
30
|
}
|
30
31
|
subject.one = true
|
31
32
|
subject.two = "two"
|
@@ -40,6 +41,24 @@ module Xmlss
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
44
|
+
should "build with no whitespace formatting by default" do
|
45
|
+
assert_equal(
|
46
|
+
"<?xml version=\"1.0\"?>\n<Thing ss:One=\"1\" ss:Two=\"two\"><Nodes/></Thing>\n",
|
47
|
+
::Nokogiri::XML::Builder.new do |builder|
|
48
|
+
subject.build_node(builder)
|
49
|
+
end.to_xml({:save_with => subject.xml_save_with})
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "build with whitespace formatting if specified" do
|
54
|
+
assert_equal(
|
55
|
+
"<?xml version=\"1.0\"?>\n<Thing ss:One=\"1\" ss:Two=\"two\">\n <Nodes/>\n</Thing>\n",
|
56
|
+
::Nokogiri::XML::Builder.new do |builder|
|
57
|
+
subject.build_node(builder)
|
58
|
+
end.to_xml({:save_with => subject.xml_save_with(:format)})
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
43
62
|
should "generate build attributes based on it's own attributes" do
|
44
63
|
assert_nothing_raised do
|
45
64
|
subject.send :build_attributes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-19 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|