ExpandTemplate replaces placeholder tokens in the config template with platform-appropriate paths derived from confpath.
(configs string, confpath string)
| 20 | // ExpandTemplate replaces placeholder tokens in the config template with |
| 21 | // platform-appropriate paths derived from confpath. |
| 22 | func ExpandTemplate(configs string, confpath string) string { |
| 23 | community, personal, work := cheatsheetDirs(confpath) |
| 24 | |
| 25 | // substitute paths |
| 26 | configs = strings.ReplaceAll(configs, "COMMUNITY_PATH", community) |
| 27 | configs = strings.ReplaceAll(configs, "PERSONAL_PATH", personal) |
| 28 | configs = strings.ReplaceAll(configs, "WORK_PATH", work) |
| 29 | |
| 30 | // locate and set a default pager |
| 31 | configs = strings.ReplaceAll(configs, "PAGER_PATH", config.Pager()) |
| 32 | |
| 33 | // locate and set a default editor |
| 34 | if editor, err := config.Editor(); err == nil { |
| 35 | configs = strings.ReplaceAll(configs, "EDITOR_PATH", editor) |
| 36 | } |
| 37 | |
| 38 | return configs |
| 39 | } |
| 40 | |
| 41 | // CommentCommunity comments out the community cheatpath block in the config |
| 42 | // template. This is used when the community cheatsheets directory won't exist |
no test coverage detected