lib/xmlss/writer.rb in xmlss-1.0.0.rc.4 vs lib/xmlss/writer.rb in xmlss-1.0.0
- old
+ new
@@ -2,13 +2,10 @@
require 'stringio'
module Xmlss
class Writer
- class Markup; end
- class AttrsHash; end
-
# Xmlss uses Undies to stream its xml markup
# The Undies writer is responsible for driving the Undies API to generate
# the xmlss xml markup for the workbook.
# Because order doesn't matter when defining style and worksheet elements,
# the writer has to buffer the style and worksheet markup separately,
@@ -190,82 +187,78 @@
# write the table container
worksheets_markup.element("Table", nil, {})
end
- end
+ # utility classes
+ class AttrsHash
+ attr_reader :raw
+ def initialize
+ @raw = Hash.new
+ end
- class Writer::AttrsHash
+ def value(k, v)
+ # ignore any nil-value or empty string attrs
+ @raw["#{Xmlss::Writer::SHEET_NS}:#{k}"] = v if v && v != ''
+ self
+ end
- attr_reader :raw
-
- def initialize
- @raw = Hash.new
+ def bool(k, v)
+ # write truthy values as '1', otherwise ignore
+ @raw["#{Xmlss::Writer::SHEET_NS}:#{k}"] = 1 if v
+ self
+ end
end
- def value(k, v)
- # ignore any nil-value or empty string attrs
- @raw["#{Xmlss::Writer::SHEET_NS}:#{k}"] = v if v && v != ''
- self
- end
+ class Markup
+ attr_reader :template, :push_count, :pop_count
- def bool(k, v)
- # write truthy values as '1', otherwise ignore
- @raw["#{Xmlss::Writer::SHEET_NS}:#{k}"] = 1 if v
- self
- end
+ def initialize(opts={})
+ @markup = ""
+ @template = Undies::Template.new(Undies::IO.new(@markup, opts))
+ @push_count = 0
+ @pop_count = 0
+ end
- end
+ def raw(markup)
+ @template.raw(
+ Undies::Template.escape_html(markup).gsub(/(\r|\n)+/, Xmlss::Writer::LB)
+ )
+ end
- class Writer::Markup
+ def element(name, data, attrs)
+ @template.__open_element(name, data, attrs)
+ end
- attr_reader :template, :push_count, :pop_count
+ def inline_element(name, attrs)
+ @template.__closed_element(name, attrs)
+ end
- def initialize(opts={})
- @markup = ""
- @template = Undies::Template.new(Undies::IO.new(@markup, opts))
- @push_count = 0
- @pop_count = 0
- end
+ def push
+ @push_count += 1
+ @template.__push
+ end
- def raw(markup)
- @template.raw(
- Undies::Template.escape_html(markup).gsub(/(\r|\n)+/, Xmlss::Writer::LB)
- )
- end
+ def pop
+ @pop_count += 1
+ @template.__pop
+ end
- def element(name, data, attrs)
- @template.__open_element(name, data, attrs)
- end
-
- def inline_element(name, attrs)
- @template.__closed_element(name, attrs)
- end
-
- def push
- @push_count += 1
- @template.__push
- end
-
- def pop
- @pop_count += 1
- @template.__pop
- end
-
- def flush
- while @push_count > @pop_count
- pop
+ def flush
+ while @push_count > @pop_count
+ pop
+ end
+ @template.__flush
+ self
end
- @template.__flush
- self
- end
- def empty?; @markup.empty?; end
+ def empty?; @markup.empty?; end
- def to_s
- @markup.to_s
+ def to_s
+ @markup.to_s
+ end
end
end
end