MCPcopy Index your code
hub / github.com/rilldata/rill / parseThemeRef

Method parseThemeRef

runtime/parser/parse_explore.go:305–334  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
305func (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}

Callers 3

parseExploreMethod · 0.95
parseCanvasMethod · 0.95

Calls 4

parseThemeYAMLMethod · 0.95
ErrorfMethod · 0.65
IsZeroMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected