android-xml 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/android-xml/setup.rb +1 -1
- data/lib/android-xml/tag.rb +52 -52
- data/lib/android-xml/version.rb +1 -1
- data/spec/setup_spec.rb +50 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 116b00e3b218d57210b245664cdba74ad0547f0c
|
4
|
+
data.tar.gz: 5ab7355d8a8a2f23c9c2761a9605d9278ba17fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a20f4da341b687a4e74aaa756090a24327bb71ac7ab977c2ee03c85b8598a6e0edbc2a371a234c8e63ee9bf686681558979069996e389235808cd0f0b55378c7
|
7
|
+
data.tar.gz: a1b3d59da9a73fc2ea24d80460f94898420fbfb585a2322fea6ec3e543b54e66e154781546bc299af392fe8e2c15fca4c8099ba8a94d6106152334e24896c62f
|
data/lib/android-xml/setup.rb
CHANGED
data/lib/android-xml/tag.rb
CHANGED
@@ -3,43 +3,7 @@ module AndroidXml
|
|
3
3
|
class Tag
|
4
4
|
attr_accessor :is_root
|
5
5
|
|
6
|
-
def
|
7
|
-
@buffer = []
|
8
|
-
@attrs = {}.merge(flatten_attrs(attrs))
|
9
|
-
@raw_tag = tag.to_s
|
10
|
-
|
11
|
-
if rename = Setup.tags[tag.to_s][:rename]
|
12
|
-
@tag = rename
|
13
|
-
else
|
14
|
-
@tag = tag.to_s.gsub('_', '-')
|
15
|
-
end
|
16
|
-
|
17
|
-
@generate = block
|
18
|
-
end
|
19
|
-
|
20
|
-
def method_missing(method_name, attrs={}, &block)
|
21
|
-
tag = Tag.new(method_name, attrs, &block)
|
22
|
-
include tag
|
23
|
-
tag
|
24
|
-
end
|
25
|
-
|
26
|
-
def clone(attrs={}, &block)
|
27
|
-
block ||= @generate
|
28
|
-
Tag.new(@tag, @attrs.merge(flatten_attrs(attrs)), &block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def include(tag, &block)
|
32
|
-
if tag.is_a?(Tag)
|
33
|
-
if block_given?
|
34
|
-
tag = tag.clone(&block)
|
35
|
-
end
|
36
|
-
@buffer << tag
|
37
|
-
else
|
38
|
-
super
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def flatten_attrs(attrs, prefix='')
|
6
|
+
def self.flatten_attrs(attrs, prefix='')
|
43
7
|
flattened = {}
|
44
8
|
attrs.each do |key, value|
|
45
9
|
key = "#{prefix}#{key}"
|
@@ -53,21 +17,7 @@ module AndroidXml
|
|
53
17
|
flattened
|
54
18
|
end
|
55
19
|
|
56
|
-
def
|
57
|
-
attrs = {}
|
58
|
-
|
59
|
-
attrs.merge!(Setup.all_tag[:defaults])
|
60
|
-
if is_root
|
61
|
-
attrs.merge!(Setup.root_tag[:defaults])
|
62
|
-
end
|
63
|
-
|
64
|
-
attrs.merge!(Setup.tags[@raw_tag][:defaults])
|
65
|
-
attrs.merge!(@attrs)
|
66
|
-
|
67
|
-
format_attrs(@tag, attrs, whitespace)
|
68
|
-
end
|
69
|
-
|
70
|
-
def format_attrs(tag, attrs, whitespace)
|
20
|
+
def self.format_attrs(tag, attrs, whitespace)
|
71
21
|
output = ''
|
72
22
|
is_first = true
|
73
23
|
attrs.each do |key, value|
|
@@ -117,6 +67,56 @@ module AndroidXml
|
|
117
67
|
value
|
118
68
|
end
|
119
69
|
|
70
|
+
def initialize(tag, attrs={}, &block)
|
71
|
+
@buffer = []
|
72
|
+
@attrs = {}.merge(Tag.flatten_attrs(attrs))
|
73
|
+
@raw_tag = tag.to_s
|
74
|
+
|
75
|
+
if rename = Setup.tags[tag.to_s][:rename]
|
76
|
+
@tag = rename
|
77
|
+
else
|
78
|
+
@tag = tag.to_s.gsub('_', '-')
|
79
|
+
end
|
80
|
+
|
81
|
+
@generate = block
|
82
|
+
end
|
83
|
+
|
84
|
+
def method_missing(method_name, attrs={}, &block)
|
85
|
+
tag = Tag.new(method_name, attrs, &block)
|
86
|
+
include tag
|
87
|
+
tag
|
88
|
+
end
|
89
|
+
|
90
|
+
def clone(attrs={}, &block)
|
91
|
+
block ||= @generate
|
92
|
+
Tag.new(@tag, @attrs.merge(Tag.flatten_attrs(attrs)), &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
def include(tag, &block)
|
96
|
+
if tag.is_a?(Tag)
|
97
|
+
if block_given?
|
98
|
+
tag = tag.clone(&block)
|
99
|
+
end
|
100
|
+
@buffer << tag
|
101
|
+
else
|
102
|
+
super
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def generate_attrs(whitespace)
|
107
|
+
attrs = {}
|
108
|
+
|
109
|
+
attrs.merge!(Setup.all_tag[:defaults])
|
110
|
+
if is_root
|
111
|
+
attrs.merge!(Setup.root_tag[:defaults])
|
112
|
+
end
|
113
|
+
|
114
|
+
attrs.merge!(Setup.tags[@raw_tag][:defaults])
|
115
|
+
attrs.merge!(@attrs)
|
116
|
+
|
117
|
+
Tag.format_attrs(@tag, attrs, whitespace)
|
118
|
+
end
|
119
|
+
|
120
120
|
def generate(tab='')
|
121
121
|
whitespace = "#{tab} #{' ' * @tag.length}"
|
122
122
|
output = "#{tab}<#{@tag}#{generate_attrs(whitespace)}"
|
data/lib/android-xml/version.rb
CHANGED
data/spec/setup_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'android-xml'
|
2
|
+
|
3
|
+
|
4
|
+
describe 'Android menu files' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
AndroidXml.reset
|
8
|
+
AndroidXml.setup do
|
9
|
+
tag :application do
|
10
|
+
defaults screenOrientation: 'portrait', allowBackup: false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should include defaults' do
|
16
|
+
xml = AndroidXml.file('tmp/test.xml') do
|
17
|
+
application
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(xml.to_s).to eql <<-XML
|
21
|
+
<!-- Do not edit this file. It was generated by AndroidXml. -->
|
22
|
+
<application android:screenOrientation="portrait"
|
23
|
+
android:allowBackup="false" />
|
24
|
+
XML
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should override defaults' do
|
28
|
+
xml = AndroidXml.file('tmp/test.xml') do
|
29
|
+
application allowBackup: true
|
30
|
+
end
|
31
|
+
|
32
|
+
expect(xml.to_s).to eql <<-XML
|
33
|
+
<!-- Do not edit this file. It was generated by AndroidXml. -->
|
34
|
+
<application android:screenOrientation="portrait"
|
35
|
+
android:allowBackup="true" />
|
36
|
+
XML
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should remove nil values' do
|
40
|
+
xml = AndroidXml.file('tmp/test.xml') do
|
41
|
+
application screenOrientation: nil
|
42
|
+
end
|
43
|
+
|
44
|
+
expect(xml.to_s).to eql <<-XML
|
45
|
+
<!-- Do not edit this file. It was generated by AndroidXml. -->
|
46
|
+
<application android:allowBackup="false" />
|
47
|
+
XML
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: android-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- spec/factory_spec.rb
|
55
55
|
- spec/generate_spec.rb
|
56
56
|
- spec/inc_tag_spec.rb
|
57
|
+
- spec/setup_spec.rb
|
57
58
|
- spec/string_spec.rb
|
58
59
|
- spec/write_to_file_spec.rb
|
59
60
|
homepage: https://github.com/colinta/android-xml
|
@@ -91,5 +92,6 @@ test_files:
|
|
91
92
|
- spec/factory_spec.rb
|
92
93
|
- spec/generate_spec.rb
|
93
94
|
- spec/inc_tag_spec.rb
|
95
|
+
- spec/setup_spec.rb
|
94
96
|
- spec/string_spec.rb
|
95
97
|
- spec/write_to_file_spec.rb
|