parseThemeRef parses a theme from a YAML node. It accepts either a reference to a theme by name or an inline definition of a theme. It returns either a theme name or a theme spec, not both.
(n *yaml.Node)
| 303 | // It accepts either a reference to a theme by name or an inline definition of a theme. |
| 304 | // It returns either a theme name or a theme spec, not both. |
| 305 | func (p *Parser) parseThemeRef(n *yaml.Node) (string, *runtimev1.ThemeSpec, error) { |
| 306 | if n == nil || n.IsZero() { |
| 307 | return "", nil, nil |
| 308 | } |
| 309 | |
| 310 | switch n.Kind { |
| 311 | case yaml.ScalarNode: // It's the name of an existing theme |
| 312 | var name string |
| 313 | err := n.Decode(&name) |
| 314 | if err != nil { |
| 315 | return "", nil, err |
| 316 | } |
| 317 | return name, nil, nil |
| 318 | case yaml.MappingNode: // It's an inline definition of a new theme |
| 319 | tmp := &ThemeYAML{} |
| 320 | err := n.Decode(tmp) |
| 321 | if err != nil { |
| 322 | return "", nil, err |
| 323 | } |
| 324 | |
| 325 | spec, err := p.parseThemeYAML(tmp) |
| 326 | if err != nil { |
| 327 | return "", nil, err |
| 328 | } |
| 329 | |
| 330 | return "", spec, nil |
| 331 | default: |
| 332 | return "", nil, fmt.Errorf("invalid theme: should be a string or mapping, got kind %q", n.Kind) |
| 333 | } |
| 334 | } |
no test coverage detected