class AndroidXml::Setup

Constants

ALL
ROOT

Public Class Methods

all(&block) click to toggle source
# File lib/android-xml/setup.rb, line 47
def all(&block)
  tag(ALL, &block)
end
all_tag() click to toggle source
# File lib/android-xml/setup.rb, line 43
def all_tag
  tags[ALL]
end
defaults(attrs) click to toggle source
# File lib/android-xml/setup.rb, line 83
def defaults(attrs)
  tags[@context][:defaults].merge!(Tag.flatten_attrs(attrs))
end
rename(attrs) click to toggle source
# File lib/android-xml/setup.rb, line 73
def rename(attrs)
  if attrs.is_a?(Hash)
    attrs.each do |attr_name, attr_rename|
      tags[@context][:attrs][attr_name.to_s] = attr_rename.to_s
    end
  else
    tags[@context][:attrs][attrs.to_s] = attrs.to_s
  end
end
reset() click to toggle source
# File lib/android-xml/setup.rb, line 30
def reset
  @tab = nil
  @tags = nil
end
root(&block) click to toggle source
# File lib/android-xml/setup.rb, line 39
def root(&block)
  tag(ROOT, &block)
end
root_tag() click to toggle source
# File lib/android-xml/setup.rb, line 35
def root_tag
  tags[ROOT]
end
setup(&block) click to toggle source
# File lib/android-xml/setup.rb, line 8
def setup(&block)
  instance_exec(&block)
end
tab() click to toggle source
# File lib/android-xml/setup.rb, line 26
def tab
  @tab ||= '    '
end
tabs(value) click to toggle source
# File lib/android-xml/setup.rb, line 12
def tabs(value)
  @tab = value
end
tag(*names, &block) click to toggle source
# File lib/android-xml/setup.rb, line 51
def tag(*names, &block)
  context_was = @context

  names.each do |name|
    if name.is_a?(Hash)
      @context = nil
      name.each do |shortcut, tag_name|
        raise "There can be only one key-value pair" if @context

        @context = shortcut.to_s
        tags[@context][:rename] = tag_name.to_s
      end
    else
      @context = name.to_s
    end

    instance_exec(&block)
  end

  @context = context_was
end
tags() click to toggle source
# File lib/android-xml/setup.rb, line 16
def tags
  @tags ||= Hash.new do |hash, key|
    hash[key] = {
      attrs: {},
      defaults: {},
      rename: nil,
    }
  end
end