class ZAML

Constants

EXTENDED_CHARS_RE
HI_BIT_CHARS
HI_BIT_CHARS_RE
NUM_RE
SIMPLE_STRING_RE
VERSION
ZAML_ESCAPES

Attributes

indent[RW]
result[RW]
valign[RW]

line up simple value tokens at this vertical column

Public Class Methods

dump(stuff, where='', options={}) click to toggle source

Class Methods

# File lib/icss/serialization/zaml.rb, line 25
def self.dump(stuff, where='', options={})
  z = self.new(options)
  stuff.to_zaml(z)
  where << z.to_s
end
new(options={}) click to toggle source

Instance Methods

# File lib/icss/serialization/zaml.rb, line 34
def initialize(options={})
  reset!
  self.valign = options[:valign]
end
padding(nlines) click to toggle source
# File lib/icss/serialization/zaml.rb, line 111
def self.padding(nlines)
  Padding.new(nlines)
end

Public Instance Methods

emit(s) click to toggle source
# File lib/icss/serialization/zaml.rb, line 68
def emit(s)
  @result << s
  @recent_nl = false unless s.kind_of?(Label)
  self.to_s
end
first_time_only(obj) { || ... } click to toggle source
# File lib/icss/serialization/zaml.rb, line 88
def first_time_only(obj)
  if label = Label.for(obj)
    emit(label.reference)
  else
    if @structured_key_prefix and not obj.is_a? String
      emit(@structured_key_prefix)
      @structured_key_prefix = nil
    end
    emit(new_label_for(obj))
    yield
  end
  self.to_s
end
inspect() click to toggle source
# File lib/icss/serialization/zaml.rb, line 105
def inspect
  res = to_s.inspect
  res = res[0..29]+"..."+res[-20..-1] if res.length > 50
  %Q{\#<ZAML ind=#{@indent.inspect} pfx=#{@structured_key_prefix} result='#{res}'>}
end
nested(tail=' ') { || ... } click to toggle source

for all code within the block, the cursor supplies

# File lib/icss/serialization/zaml.rb, line 48
def nested(tail='  ')
  old_indent = @indent
  # @indent    = "#{@indent || "\n"}#{tail}"
  @indent    = @indent ? "#{@indent}#{tail}" : "\n"
  yield
  @indent    = old_indent
end
new_label_for(obj) click to toggle source
# File lib/icss/serialization/zaml.rb, line 85
def new_label_for(obj)
  Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"}  " : ' ')
end
nl(s='') click to toggle source
# File lib/icss/serialization/zaml.rb, line 73
def nl(s='')
  emit(@indent || "\n") unless @recent_nl
  emit(s)
  @recent_nl = true
end
no_comment(elt) { || ... } click to toggle source
# File lib/icss/serialization/zaml.rb, line 115
def no_comment(elt)
  if elt.is_a?(ZAML::Comment) || elt.is_a?(ZAML::Padding)
    elt.to_zaml(self)
  else
    yield
  end
end
prefix_structured_keys(x) { || ... } click to toggle source
# File lib/icss/serialization/zaml.rb, line 78
def prefix_structured_keys(x)
  @structured_key_prefix = x
  yield
  nl unless @structured_key_prefix
  @structured_key_prefix = nil
end
reset!() click to toggle source
# File lib/icss/serialization/zaml.rb, line 39
def reset!
  @result = []
  @indent = nil
  @structured_key_prefix = nil
  Label.counter_reset
  emit('--- ')
end
to_s() click to toggle source
# File lib/icss/serialization/zaml.rb, line 102
def to_s
  @result.join.tap{|s| s << "\n" if s[-1..-1] != "\n" }
end
vpad(sep, key) click to toggle source
# File lib/icss/serialization/zaml.rb, line 56
def vpad(sep, key)
  return emit("#{sep} ") unless valign
  if    key.is_a?(Symbol)  then str = key.inspect
  elsif key.is_a?(String)  then str = key
  elsif key.is_a?(Numeric) then str = key.to_s
  else  return emit("#{sep} ") ; end
  keylen = ((@indent||"\n").length - 1) + str.length + sep.length
  vlen   = valign - keylen
  pad  = (vlen > 1) ? (" "*vlen) : " "
  emit(sep+pad)
end