|
3 | 3 |
|
4 | 4 | lib: |
5 | 5 |
|
6 | | -with lib; # Android stuff that might come in handy across multiple modules, profiles, etc |
7 | 6 | rec { |
8 | 7 | # Guess resource type. Should normally work fine, but can't detect color/dimension types |
9 | 8 | resourceTypeName = r: |
10 | | - if isBool r then "bool" |
11 | | - else if isInt r then "integer" |
12 | | - else if isString r then "string" |
13 | | - else if isList r then |
14 | | - (assert (length r != 0); # Cannot autodetect type of empty list |
15 | | - if isInt (head r) then "integer-array" |
16 | | - else if isString (head r) then "string-array" |
| 9 | + if lib.isBool r then "bool" |
| 10 | + else if lib.isInt r then "integer" |
| 11 | + else if lib.isString r then "string" |
| 12 | + else if lib.isList r then |
| 13 | + (assert (lib.length r != 0); # Cannot autodetect type of empty list |
| 14 | + if lib.isInt (lib.head r) then "integer-array" |
| 15 | + else if lib.isString (lib.head r) then "string-array" |
17 | 16 | else assert false; "Unknown type" |
18 | 17 | ) |
19 | 18 | else assert false; "Unknown type"; |
20 | 19 | resourceValueXML = value: type: { |
21 | | - bool = boolToString value; |
| 20 | + bool = lib.boolToString value; |
22 | 21 | color = value; # define our own specialized type for these? |
23 | 22 | dimension = value; |
24 | 23 | integer = toString value; |
25 | 24 | string = value; |
26 | | - integer-array = concatMapStringsSep "" (i: "<item>${toString i}</item>") value; |
27 | | - string-array = concatMapStringsSep "" (i: "<item>${i}</item>") value; |
| 25 | + integer-array = lib.concatMapStringsSep "" (i: "<item>${toString i}</item>") value; |
| 26 | + string-array = lib.concatMapStringsSep "" (i: "<item>${i}</item>") value; |
28 | 27 | # Ignoring other typed arrays for now |
29 | 28 | }.${type}; |
30 | 29 |
|
31 | 30 | resourceXML = name: value: let |
32 | 31 | resourceXMLEntity = name: value: type: ''<${type} name="${name}">${resourceValueXML value type}</${type}>''; |
33 | | - in if isAttrs value then |
| 32 | + in if lib.isAttrs value then |
34 | 33 | # Submodule with manually specified resource type |
35 | 34 | resourceXMLEntity name value.value value.type |
36 | 35 | else |
|
40 | 39 | configXML = resources: '' |
41 | 40 | <?xml version="1.0" encoding="utf-8"?> |
42 | 41 | <resources> |
43 | | - ${concatStringsSep "\n" (mapAttrsToList resourceXML resources)} |
| 42 | + ${lib.concatStringsSep "\n" (lib.mapAttrsToList resourceXML resources)} |
44 | 43 | </resources> |
45 | 44 | ''; |
46 | 45 |
|
|
0 commit comments