23 fix only whitespaces + conditional attributes

This commit is contained in:
Christoph Walther
2023-10-31 21:52:24 +01:00
parent 4e23903b31
commit 027c9e4234
3 changed files with 51 additions and 10 deletions

View File

@@ -33,14 +33,16 @@ func (icalModel IcalModel) EmitICal() goics.Componenter {
s.AddProperty(k, v)
k, v = goics.FormatDateTime("DTSTART;TZID=Europe/Berlin", event.Start.Time().Local().In(europeTime))
s.AddProperty(k, v)
s.AddProperty("SUMMARY", replaceNameIfUserDefined(&event, icalModel.Mapping))
s.AddProperty("DESCRIPTION", generateDescription(event))
s.AddProperty("LOCATION", event.Rooms)
addPropertyIfNotEmpty(s, "SUMMARY", replaceNameIfUserDefined(&event, icalModel.Mapping))
addPropertyIfNotEmpty(s, "DESCRIPTION", generateDescription(event))
addPropertyIfNotEmpty(s, "LOCATION", event.Rooms)
c.AddComponent(s)
}
return c
}
// replaceNameIfUserDefined replaces the name of the event with the user defined name if it is not empty
// all contained template strings will be replaced with the corresponding values from the event
func replaceNameIfUserDefined(event *model.Event, mapping []model.FeedCollection) string {
for _, mapEntry := range mapping {
if mapEntry.Name == event.Name && !functions.OnlyWhitespace(mapEntry.UserDefinedName) {
@@ -50,6 +52,14 @@ func replaceNameIfUserDefined(event *model.Event, mapping []model.FeedCollection
return event.Name
}
// AddPropertyIfNotEmpty adds a property to the component if the value is not empty
// or contains only whitespaces
func addPropertyIfNotEmpty(component *goics.Component, key string, value string) {
if !functions.OnlyWhitespace(value) {
component.AddProperty(key, value)
}
}
func generateDescription(event model.Event) string {
var description string