android-xml 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d506adcceb4029ba73f444e1bfb5c31f67c95df0
4
- data.tar.gz: 84898757fcdcf17cacc66d4960a5935b99ab9274
3
+ metadata.gz: 74fdc8cf167a00e6fc913368b39b225d0d4d0c1c
4
+ data.tar.gz: e50d23184c0a996f2b5d9557d468e97d4e7dd001
5
5
  SHA512:
6
- metadata.gz: b27e7d59f2d2c4158380e5a4241dd99040b1b970dd5885c0c684563ac1e29264b624f0f343c84736016527cb6cc0619917f0388577c4b35a4050ac8756feca7f
7
- data.tar.gz: 9f09c2c75c8b22a14fb1fbf138dee0e1bd4a9ea121cf461c1a4062fe452f16e08b6d99136a9f3658ebd5987120e2fa745e15367db8043de19e5714217f54ada6
6
+ metadata.gz: 3cf9021c429ed0baa13e54e82f4c7f5c973b2ea5954da51a88222d3f8f0151d764593a913443350937a67631c9ff2306ee6d2c8ff554594921741709afddddc9
7
+ data.tar.gz: 5230c0bb21226467546661037a8899016fb87fde53b752798ea9462760c5fcda8d72c7ead82d01d6b413188dc513b150a33f18ad9fbfc59861edb8d23bbe7aba
data/README.md CHANGED
@@ -17,6 +17,7 @@ end
17
17
 
18
18
  AndroidXml.write_all
19
19
  AndroidXml.clean_up 'res/'
20
+ AndroidXml.missing_strings?
20
21
  ```
21
22
 
22
23
  > ruby generate_xml.rb
@@ -81,9 +82,12 @@ end
81
82
  # strings.
82
83
  AndroidXml.write_all
83
84
  AndroidXml.clean_up 'res/'
85
+ # Outputs any missing string tags (looks for @string/name attributes and
86
+ # <string name="name"> tags)
87
+ AndroidXml.missing_strings?
84
88
  ```
85
89
 
86
- # Helpers
90
+ # Setup / Helpers
87
91
 
88
92
  Here's how we create the main_action helper, or if you need to specify that some
89
93
  attributes don't need the `android:` prefix.
@@ -129,14 +133,16 @@ often have big chunks that are reusable. Let's say you have a button that is
129
133
  in a FrameLayout, and centered at the bottom:
130
134
 
131
135
  ```ruby
136
+ # create a <Button> tag
132
137
  close_button = AndroidXml.Button(
138
+ id: '@+id/close_button',
133
139
  layout_width: 'wrap_content',
134
140
  layout_height: 'wrap_content',
135
- id: '@+id/cheat_button',
136
141
  layout_gravity: 'bottom|center',
137
- text: '@string/cheat_button'
142
+ text: '@string/close_button'
138
143
  )
139
144
 
145
+ # and include it in a layout
140
146
  AndroidXml.file('res/layout/some_activity.xml') do
141
147
  RelativeLayout(...) do
142
148
  # ...
@@ -145,8 +151,6 @@ AndroidXml.file('res/layout/some_activity.xml') do
145
151
  end
146
152
  ```
147
153
 
148
- Note: so far, this could also be accomplished using a [Helper](#helpers):
149
-
150
154
  You can `clone` a tag and make changes to it:
151
155
 
152
156
  ```ruby
@@ -154,7 +158,57 @@ AndroidXml.file('res/layout-land/some_activity.xml') do
154
158
  RelativeLayout(...) do
155
159
  # ...
156
160
 
157
- include close_button(padding: '')
161
+ include close_button(padding: 8.dp)
162
+ end
163
+ end
164
+ ```
165
+
166
+ You can create a tag with sub nodes, too!
167
+
168
+ ```ruby
169
+ warning = AndroidXml.LinearLayout(
170
+ layout_width: 'match_parent',
171
+ layout_height: 'match_parent',
172
+ orientation: 'horizontal'
173
+ ) do
174
+ Image(padding: 24.dp, src: '@drawable/warning_icon')
175
+ TextView(layout_width: 'wrap_content',
176
+ layout_height: 'wrap_content',
177
+ text: '@string/warning_text')
178
+ end
179
+
180
+ AndroidXml.file('layout.xml') do
181
+ LinearLayout layout_width: 'match_parent',
182
+ layout_height: 'match_parent',
183
+ gravity: 'center',
184
+ orientation: 'vertical' do
185
+ include warning
186
+
187
+ # if you want to replace the contents:
188
+ include warning.clone do
189
+ Image(padding: 24.dp, src: '@drawable/error_icon')
190
+ TextView(layout_width: 'wrap_content',
191
+ layout_height: 'wrap_content',
192
+ text: '@string/error_text')
193
+ end
194
+ end
195
+ end
196
+ ```
197
+
198
+ Note: this could also be accomplished using `AndroidXml.setup`, but setup is
199
+ meant for global conventions. Layout-specific things should be included with
200
+ `include`, in my opinion. But, up to you:
201
+
202
+ ```ruby
203
+ AndroidXml.setup do
204
+ tag :close_button => 'Button' do
205
+ defaults id: '@+id/close_button',
206
+ layout_width: 'wrap_content',
207
+ layout_height: 'wrap_content',
208
+ layout_gravity: 'bottom|center',
209
+ text: '@string/close_button'
210
+ contents do
211
+ end
158
212
  end
159
213
  end
160
214
  ```
data/lib/android-xml.rb CHANGED
@@ -4,5 +4,6 @@ require_relative './android-xml/tag'
4
4
  require_relative './android-xml/file'
5
5
  require_relative './android-xml/defaults'
6
6
  require_relative './android-xml/exts'
7
+ require_relative './android-xml/string'
7
8
 
8
9
  AndroidXml.setup_defaults
@@ -56,6 +56,8 @@ module AndroidXml
56
56
  Setup.reset
57
57
  @files = nil
58
58
  @generated = nil
59
+ Tag.found_strings.clear
60
+ Tag.registered_strings.clear
59
61
  end
60
62
 
61
63
  def tag(tag_name, attrs=nil, &block)
@@ -1,13 +1,42 @@
1
+ require 'android-xml'
2
+
3
+
1
4
  module AndroidXml
2
5
 
3
6
  class Tag
4
7
 
8
+ class << self
9
+
10
+ def found_strings
11
+ @found_strings ||= []
12
+ end
13
+
14
+ def registered_strings
15
+ @registered_strings ||= []
16
+ end
17
+
18
+ end
19
+
5
20
  def string(attrs={}, &block)
6
21
  tag = Tag.new('string', attrs, &block)
22
+ string = attrs['name'] || attrs[:name]
23
+ raise "name is required in a <string> tag" unless string && ! string.empty?
24
+ Tag.registered_strings << (string)
7
25
  include tag
8
26
  tag
9
27
  end
10
28
 
11
29
  end
12
30
 
31
+ module_function
32
+
33
+ def missing_strings?
34
+ diff = Tag.found_strings - Tag.registered_strings
35
+ unless diff.empty?
36
+ diff.each do |name|
37
+ puts " string(name='#{name}') { '#{name}' }"
38
+ end
39
+ end
40
+ end
41
+
13
42
  end
@@ -67,6 +67,10 @@ module AndroidXml
67
67
  xml_key = "android:#{key}"
68
68
  end
69
69
 
70
+ if value =~ /^@string\/(\w+)$/
71
+ Tag.found_strings << $1
72
+ end
73
+
70
74
  if is_first
71
75
  output << " #{xml_key}=\"#{value}\""
72
76
  is_first = false
@@ -1,3 +1,3 @@
1
1
  module AndroidXml
2
- Version = '1.2.2'
2
+ Version = '1.2.3'
3
3
  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.2.2
4
+ version: 1.2.3
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-19 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec