android-xml 1.2.2 → 1.2.3
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/README.md +60 -6
 - data/lib/android-xml.rb +1 -0
 - data/lib/android-xml/main.rb +2 -0
 - data/lib/android-xml/string.rb +29 -0
 - data/lib/android-xml/tag.rb +4 -0
 - data/lib/android-xml/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 74fdc8cf167a00e6fc913368b39b225d0d4d0c1c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e50d23184c0a996f2b5d9557d468e97d4e7dd001
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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/ 
     | 
| 
      
 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
    
    
    
        data/lib/android-xml/main.rb
    CHANGED
    
    
    
        data/lib/android-xml/string.rb
    CHANGED
    
    | 
         @@ -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
         
     | 
    
        data/lib/android-xml/tag.rb
    CHANGED
    
    
    
        data/lib/android-xml/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-06-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rspec
         
     |