xmlss 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xmlss (0.0.2)
4
+ xmlss (0.2.0)
5
5
  enumeration (~> 1.1.0)
6
6
  nokogiri (~> 1.4.0)
7
7
 
@@ -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
@@ -27,4 +27,4 @@ class Simple < ExampleWorkbook
27
27
 
28
28
  end
29
29
  end
30
- Simple.new.to_file
30
+ Simple.new.to_file(:format)
@@ -82,4 +82,4 @@ class Styles < ExampleWorkbook
82
82
  self.worksheets << wksht
83
83
  end
84
84
  end
85
- Styles.new.to_file
85
+ Styles.new.to_file(:format)
@@ -33,4 +33,4 @@ with line breaks
33
33
 
34
34
  end
35
35
  end
36
- Text.new.to_file
36
+ Text.new.to_file(:format)
@@ -1,3 +1,3 @@
1
1
  module Xmlss
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.to_xml.gsub(/#{Xmlss::Data::LB.gsub(/&/, "&amp;")}/, Xmlss::Data::LB)
45
+ end.
46
+ to_xml({:save_with => xml_save_with(*options)}).
47
+ gsub(/#{Xmlss::Data::LB.gsub(/&/, "&amp;")}/, Xmlss::Data::LB)
46
48
  end
47
49
 
48
50
  end
@@ -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?
@@ -2,4 +2,8 @@ class Thing
2
2
  attr_accessor :one, :two, :three, :xml
3
3
 
4
4
  include Xmlss::Xml
5
+
6
+ def child_nodes
7
+ Xmlss::ItemSet.new(:nodes, [])
8
+ end
5
9
  end
@@ -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: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.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-11 00:00:00 -05:00
18
+ date: 2011-04-19 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency