Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorials: Map Module #820

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions source/tutorials/module-system/module-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,20 +742,23 @@ 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.
Notice here 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.
brianmcgillion marked this conversation as resolved.
Show resolved Hide resolved

## Functions as submodule arguments

Expand Down Expand Up @@ -876,7 +879,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 +932,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 Down Expand Up @@ -963,15 +966,16 @@ in {
config = {
requestParams = let
attrForLocation = loc:
"$(geocode ${lib.escapeShellArg 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;
in "path=\"${lib.concatStringsSep "|" attributes}\"";
in
builtins.map paramForPath config.map.paths;
};
}
```
Expand Down Expand Up @@ -1127,9 +1131,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
Loading