Class: AndroidXml::Setup
- Inherits:
-
Object
- Object
- AndroidXml::Setup
- Defined in:
- lib/android-xml/setup.rb
Constant Summary collapse
- ROOT =
'__root_node_with_a_long_special_name__'
- ALL =
'__all_node_with_a_long_special_name__'
Class Method Summary collapse
- .all(&block) ⇒ Object
- .all_tag ⇒ Object
- .defaults(attrs) ⇒ Object
- .rename(attrs) ⇒ Object
- .reset ⇒ Object
- .root(&block) ⇒ Object
- .root_tag ⇒ Object
- .setup(&block) ⇒ Object
- .tab ⇒ Object
- .tabs(value) ⇒ Object
- .tag(*names, &block) ⇒ Object
- .tags ⇒ Object
Class Method Details
.all(&block) ⇒ Object
47 48 49 |
# File 'lib/android-xml/setup.rb', line 47 def all(&block) tag(ALL, &block) end |
.all_tag ⇒ Object
43 44 45 |
# File 'lib/android-xml/setup.rb', line 43 def all_tag [ALL] end |
.defaults(attrs) ⇒ Object
83 84 85 |
# File 'lib/android-xml/setup.rb', line 83 def defaults(attrs) [@context][:defaults].merge!(Tag.flatten_attrs(attrs)) end |
.rename(attrs) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/android-xml/setup.rb', line 73 def rename(attrs) if attrs.is_a?(Hash) attrs.each do |attr_name, attr_rename| [@context][:attrs][attr_name.to_s] = attr_rename.to_s end else [@context][:attrs][attrs.to_s] = attrs.to_s end end |
.reset ⇒ Object
30 31 32 33 |
# File 'lib/android-xml/setup.rb', line 30 def reset @tab = nil @tags = nil end |
.root(&block) ⇒ Object
39 40 41 |
# File 'lib/android-xml/setup.rb', line 39 def root(&block) tag(ROOT, &block) end |
.root_tag ⇒ Object
35 36 37 |
# File 'lib/android-xml/setup.rb', line 35 def root_tag [ROOT] end |
.setup(&block) ⇒ Object
8 9 10 |
# File 'lib/android-xml/setup.rb', line 8 def setup(&block) instance_exec(&block) end |
.tab ⇒ Object
26 27 28 |
# File 'lib/android-xml/setup.rb', line 26 def tab @tab ||= ' ' end |
.tabs(value) ⇒ Object
12 13 14 |
# File 'lib/android-xml/setup.rb', line 12 def tabs(value) @tab = value end |
.tag(*names, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 [@context][:rename] = tag_name.to_s end else @context = name.to_s end instance_exec(&block) end @context = context_was end |
.tags ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/android-xml/setup.rb', line 16 def @tags ||= Hash.new do |hash, key| hash[key] = { attrs: {}, defaults: {}, rename: nil, } end end |