Skip to content

Commit

Permalink
tutorials: Map Module (#820)
Browse files Browse the repository at this point in the history
* tutorial: Propagate previous geocode changes

Propagate the changes made in a previous code snippet to this code
snippet. Primarily fixing the poorly referenced ``${geocode``.

* tutorial: Fix requestParams for path.nix

Adjust the functionality to reference geocode correctly and
also to make sure of the correct escaping formats.

Signed-off-by: Brian McGillion <[email protected]>
Co-authored-by: Valentin Gagarin <[email protected]>
  • Loading branch information
brianmcgillion and fricklerhandwerk authored Dec 1, 2023
1 parent bd7f493 commit 2d62761
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions source/tutorials/module-system/module-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,20 +742,24 @@ In the `paramForMarker` function:

```{code-block} diff
:caption: marker.nix
paramForMarker = marker:
let
attributes =
- [
+ lib.optional
+ (marker.style.label != null)
+ "label:${marker.style.label}"
requestParams = let
+ paramForMarker = marker:
+ let
+ attributes =
+ lib.optional (marker.style.label != null)
+ "label:${marker.style.label}"
+ ++ [
"$(geocode ${
lib.escapeShellArg marker.location
})"
+ "$(${config.scripts.geocode}/bin/geocode ${
+ lib.escapeShellArg marker.location
+ })"
+ ];
+ in "markers=\"${lib.concatStringsSep "|" attributes}\"";
+ in
+ builtins.map paramForMarker config.map.markers;
```

Here, the label for each `marker` is only propagated to the CLI parameters if `marker.style.label` is set.
Note how we now create a unique `marker` for each user by concatenating the `label` and `location` attributes together, and assigning them to the `requestParams`.
The label for each `marker` is only propagated to the CLI parameters if `marker.style.label` is set.

## Functions as submodule arguments

Expand Down Expand Up @@ -876,7 +880,7 @@ Now add an entry to the `paramForMarker` list which makes use of the new option:
"label:${marker.style.label}"
++ [
+ "color:${marker.style.color}"
"$(geocode ${
"$(${config.scripts.geocode}/bin/geocode ${
lib.escapeShellArg marker.location
})"
```
Expand Down Expand Up @@ -929,7 +933,7 @@ Finally, add another `lib.optional` call to the `attributes` string, making use
+ "size:${size}"
++ [
"color:${marker.style.color}"
"$(geocode ${
"$(${config.scripts.geocode}/bin/geocode ${
```

## The `pathType` submodule
Expand All @@ -953,25 +957,26 @@ let
};
};
};
in {
in
{
options = {
map.paths = lib.mkOption {
type = lib.types.listOf pathType;
};
};
config = {
requestParams = let
attrForLocation = loc:
"$(geocode ${lib.escapeShellArg loc})";
paramForPath = path:
let
attributes =
builtins.map attrForLocation path.locations;
in "path=${
lib.concatStringsSep "\\|" attributes
}";
in builtins.map paramForPath config.map.paths;
requestParams =
let
attrForLocation = loc:
"$(${config.scripts.geocode}/bin/geocode ${lib.escapeShellArg loc})";
paramForPath = path:
let
attributes =
builtins.map attrForLocation path.locations;
in
''path="${lib.concatStringsSep "|" attributes}"'';
in
builtins.map paramForPath config.map.paths;
};
}
```
Expand Down Expand Up @@ -1127,9 +1132,7 @@ Finally, update the `attributes` list in `paramForPath`:
+ "weight:${toString path.style.weight}"
+ ]
+ ++ builtins.map attrForLocation path.locations;
in "path=${
lib.concatStringsSep "\\|" attributes
}";
in "path=\"${lib.concatStringsSep "|" attributes}\"";
```

## The `pathStyle` submodule
Expand Down

0 comments on commit 2d62761

Please sign in to comment.