xmlss 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xmlss (0.4.0)
4
+ xmlss (0.4.1)
5
5
  enumeration (~> 1.3)
6
- undies (~> 2.1)
6
+ undies (~> 2.2)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  enumeration (1.3.1)
18
18
  rake (0.9.2)
19
19
  ruby-prof (0.10.8)
20
- undies (2.1.0)
20
+ undies (2.2.0)
21
21
 
22
22
  PLATFORMS
23
23
  ruby
@@ -1,8 +1,8 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3
3
  <Styles>
4
+
4
5
  </Styles>
5
-
6
6
  <Worksheet ss:Name="first">
7
7
  <Table>
8
8
  <Column />
@@ -15,7 +15,7 @@ ExampleWorkbook.new("simple") do
15
15
  row {
16
16
 
17
17
  # put data into the row (infer type)
18
- [1, "text", 123.45, "0001267", "$45.23"].each do |data_value|
18
+ [1, "text", 123.45, "<>&'\"/", "$45.23"].each do |data_value|
19
19
  cell { data data_value }
20
20
  end
21
21
 
@@ -1,8 +1,8 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3
3
  <Styles>
4
+
4
5
  </Styles>
5
-
6
6
  <Worksheet ss:Name="1 row, 5 columns">
7
7
  <Table>
8
8
  <Column />
@@ -21,7 +21,7 @@
21
21
  <Data ss:Type="Number">123.45</Data>
22
22
  </Cell>
23
23
  <Cell>
24
- <Data ss:Type="String">0001267</Data>
24
+ <Data ss:Type="String">&lt;&gt;&amp;&#x27;&quot;&#x2F;</Data>
25
25
  </Cell>
26
26
  <Cell>
27
27
  <Data ss:Type="String">$45.23</Data>
@@ -21,7 +21,6 @@
21
21
  <Font ss:Color="#FFFFFF" />
22
22
  </Style>
23
23
  </Styles>
24
-
25
24
  <Worksheet ss:Name="styles">
26
25
  <Table>
27
26
  <Column />
@@ -16,9 +16,9 @@ ExampleWorkbook.new("text") do
16
16
  row {
17
17
  cell(:style_id => "general_text") {
18
18
  data %{
19
- A blob of text
20
- with line breaks
21
- and leading space}
19
+ A blob of <text>
20
+ with line breaks, /escaped/ characters
21
+ & "leading" 'space'}
22
22
  }
23
23
  }
24
24
  end
@@ -6,13 +6,12 @@
6
6
  <NumberFormat ss:Format="@" />
7
7
  </Style>
8
8
  </Styles>
9
-
10
9
  <Worksheet ss:Name="text">
11
10
  <Table>
12
11
  <Column />
13
12
  <Row>
14
13
  <Cell ss:StyleID="general_text">
15
- <Data ss:Type="String">&#13;&#10;A blob of text&#13;&#10;with line breaks&#13;&#10; and leading space</Data>
14
+ <Data ss:Type="String">&#13;&#10;A blob of &lt;text&gt;&#13;&#10;with line breaks, &#x2F;escaped&#x2F; characters&#13;&#10; &amp; &quot;leading&quot; &#x27;space&#x27;</Data>
16
15
  </Cell>
17
16
  </Row>
18
17
  </Table>
@@ -5,8 +5,6 @@ module Xmlss; end
5
5
  module Xmlss::Element
6
6
  class Data
7
7
 
8
- LB = "&#13;&#10;"
9
-
10
8
  include Enumeration
11
9
  enum :type, {
12
10
  :number => "Number",
@@ -34,8 +32,6 @@ module Xmlss::Element
34
32
  case self.value
35
33
  when ::Date, ::Time, ::DateTime
36
34
  self.value.strftime("%Y-%m-%dT%H:%M:%S")
37
- when ::String, ::Symbol
38
- self.value.to_s.gsub(/(\r|\n)+/, LB)
39
35
  else
40
36
  self.value.to_s
41
37
  end
@@ -7,6 +7,7 @@ module Xmlss
7
7
  XML_NS = "xmlns"
8
8
  SHEET_NS = "ss"
9
9
  NS_URI = "urn:schemas-microsoft-com:office:spreadsheet"
10
+ LB = "&#13;&#10;"
10
11
 
11
12
  # The Undies writer is responsible for driving the Undies API to generate
12
13
  # the xmlss xml markup for the workbook.
@@ -140,7 +141,9 @@ module Xmlss
140
141
 
141
142
  def data(data, &block)
142
143
  @worksheets_t._Data(self.class.attributes(data, :type)) {
143
- @worksheets_t.__ data.xml_value
144
+ @worksheets_t.__ Undies::Template.
145
+ escape_html(data.xml_value).
146
+ gsub(/(\r|\n)+/, LB)
144
147
  }
145
148
  end
146
149
 
@@ -1,3 +1,3 @@
1
1
  module Xmlss
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -5,13 +5,14 @@ require 'xmlss/element/worksheet'
5
5
  module Xmlss
6
6
  class Workbook
7
7
 
8
+ # TODO: (writer, data={}, &build)
8
9
  def initialize(opts={}, &build)
9
10
  # (don't pollute workbook scope that the build may run in)
10
11
 
11
12
  # apply :data options to workbook scope
12
13
  data = (opts || {})[:data] || {}
13
14
  if (data.keys.map(&:to_s) & self.public_methods.map(&:to_s)).size > 0
14
- raise ArgumentError, "data conflicts with template public methods."
15
+ raise ArgumentError, "data conflicts with workbook public methods."
15
16
  end
16
17
  metaclass = class << self; self; end
17
18
  data.each {|key, value| metaclass.class_eval { define_method(key){value} }}
@@ -29,9 +29,6 @@ module Xmlss::Element
29
29
  should "generate it's xml value" do
30
30
  assert_equal "12", Data.new(12).xml_value
31
31
  assert_equal "string", Data.new("string").xml_value
32
- assert_equal "line#{Data::LB}break", Data.new("line\nbreak").xml_value
33
- assert_equal "return#{Data::LB}break", Data.new("return\rbreak").xml_value
34
- assert_equal "returnline#{Data::LB}break", Data.new("returnline\r\nbreak").xml_value
35
32
  assert_equal "2011-03-01T00:00:00", Data.new(DateTime.parse('2011/03/01')).xml_value
36
33
  assert_equal "2011-03-01T00:00:00", Data.new(Date.parse('2011/03/01')).xml_value
37
34
  time = Time.now
@@ -67,21 +64,4 @@ module Xmlss::Element
67
64
 
68
65
  end
69
66
 
70
- class WhitespaceDataTest < DataTest
71
- desc "dealing with line breaks and leading space"
72
- subject do
73
- Data.new(%s{
74
- Should
75
- honor
76
- this
77
- })
78
- end
79
-
80
- should "honor them when generating xml" do
81
- reg = /#{Data::LB}Should#{Data::LB}\s{2}honor#{Data::LB}\s{4}this#{Data::LB}/
82
- assert_match reg, subject.xml_value
83
- end
84
-
85
- end
86
-
87
67
  end
@@ -211,14 +211,53 @@ class Xmlss::UndiesWriter
211
211
  )
212
212
  end
213
213
 
214
- should "write data markup w/ line breaks" do
214
+ should "write data markup w/ \\n line breaks" do
215
+ subject.data(Xmlss::Element::Data.new("line\nbreak", :type => :string))
216
+ subject.flush
217
+
218
+ assert_equal "<Data ss:Type=\"String\">line#{Xmlss::UndiesWriter::LB}break</Data>", subject.element_markup
219
+ end
220
+
221
+ should "write data markup w/ \\r line breaks" do
222
+ subject.data(Xmlss::Element::Data.new("line\rbreak", :type => :string))
223
+ subject.flush
224
+
225
+ assert_equal "<Data ss:Type=\"String\">line#{Xmlss::UndiesWriter::LB}break</Data>", subject.element_markup
226
+ end
227
+
228
+ should "write data markup w/ \\r\\n line breaks" do
229
+ subject.data(Xmlss::Element::Data.new("line\r\nbreak", :type => :string))
230
+ subject.flush
231
+
232
+ assert_equal "<Data ss:Type=\"String\">line#{Xmlss::UndiesWriter::LB}break</Data>", subject.element_markup
233
+ end
234
+
235
+ should "write data markup w/ \\n\\r line breaks" do
236
+ subject.data(Xmlss::Element::Data.new("line\n\rbreak", :type => :string))
237
+ subject.flush
238
+
239
+ assert_equal "<Data ss:Type=\"String\">line#{Xmlss::UndiesWriter::LB}break</Data>", subject.element_markup
240
+ end
241
+
242
+ should "write data markup w/ line breaks and leading space" do
215
243
  subject.data(Xmlss::Element::Data.new(%s{
216
- Hello World
217
- }, :type => :string))
244
+ Should
245
+ honor
246
+ this}, :type => :string))
247
+ subject.flush
248
+
249
+ assert_equal(
250
+ "<Data ss:Type=\"String\">#{Xmlss::UndiesWriter::LB}Should#{Xmlss::UndiesWriter::LB} honor#{Xmlss::UndiesWriter::LB} this</Data>",
251
+ subject.element_markup
252
+ )
253
+ end
254
+
255
+ should "write data markup w/ escaped values" do
256
+ subject.data(Xmlss::Element::Data.new("some\n&<>'\"/\ndata"))
218
257
  subject.flush
219
258
 
220
259
  assert_equal(
221
- "<Data ss:Type=\"String\">&#13;&#10; Hello World&#13;&#10; </Data>",
260
+ "<Data ss:Type=\"String\">some&#13;&#10;&amp;&lt;&gt;&#x27;&quot;&#x2F;&#13;&#10;data</Data>",
222
261
  subject.element_markup
223
262
  )
224
263
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency("bundler", ["~> 1.0"])
21
21
  s.add_development_dependency("assert", ["~> 0.6"])
22
- s.add_dependency("undies", ["~> 2.1"])
22
+ s.add_dependency("undies", ["~> 2.2"])
23
23
  s.add_dependency("enumeration", ["~> 1.3"])
24
24
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
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: 2012-01-10 00:00:00 Z
18
+ date: 2012-02-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -55,11 +55,11 @@ dependencies:
55
55
  requirements:
56
56
  - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 1
58
+ hash: 7
59
59
  segments:
60
60
  - 2
61
- - 1
62
- version: "2.1"
61
+ - 2
62
+ version: "2.2"
63
63
  version_requirements: *id003
64
64
  name: undies
65
65
  - !ruby/object:Gem::Dependency