MCPcopy Create free account
hub / github.com/rilldata/rill / parseThemeYAML

Method parseThemeYAML

runtime/parser/parse_theme.go:194–242  ·  view source on GitHub ↗
(tmp *ThemeYAML)

Source from the content-addressed store, hash-verified

192}
193
194func (p *Parser) parseThemeYAML(tmp *ThemeYAML) (*runtimev1.ThemeSpec, error) {
195 spec := &runtimev1.ThemeSpec{}
196
197 hasLegacyColors := tmp.Colors.Primary != "" || tmp.Colors.Secondary != ""
198 hasCSSProperties := tmp.Light != nil || tmp.Dark != nil
199
200 if hasLegacyColors && hasCSSProperties {
201 return nil, fmt.Errorf("cannot use both legacy color properties (primary, secondary) and the new CSS property simultaneously")
202 }
203
204 if hasLegacyColors {
205 if tmp.Colors.Primary != "" {
206 pc, err := csscolorparser.Parse(tmp.Colors.Primary)
207 if err != nil {
208 return nil, fmt.Errorf("invalid primary color: %w", err)
209 }
210 spec.PrimaryColor = toThemeColor(pc)
211 spec.PrimaryColorRaw = tmp.Colors.Primary
212 }
213
214 if tmp.Colors.Secondary != "" {
215 sc, err := csscolorparser.Parse(tmp.Colors.Secondary)
216 if err != nil {
217 return nil, fmt.Errorf("invalid secondary color: %w", err)
218 }
219 spec.SecondaryColor = toThemeColor(sc)
220 spec.SecondaryColorRaw = tmp.Colors.Secondary
221 }
222
223 return spec, nil
224 }
225
226 var err error
227 if tmp.Light != nil {
228 spec.Light, err = tmp.Light.validate()
229 if err != nil {
230 return nil, fmt.Errorf("invalid light theme: %w", err)
231 }
232 }
233
234 if tmp.Dark != nil {
235 spec.Dark, err = tmp.Dark.validate()
236 if err != nil {
237 return nil, fmt.Errorf("invalid dark theme: %w", err)
238 }
239 }
240
241 return spec, nil
242}
243
244func toThemeColor(c csscolorparser.Color) *runtimev1.Color {
245 return &runtimev1.Color{

Callers 2

parseThemeRefMethod · 0.95
parseThemeMethod · 0.95

Calls 4

toThemeColorFunction · 0.85
ParseMethod · 0.80
ErrorfMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected