Skip to content

Commit

Permalink
✨ (ContentKit): List sample activities
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 15, 2024
1 parent e933e61 commit 885be4a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Modules/ContentKit/Sources/ContentKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,39 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import Foundation
import LogKit
import Yams

let log = LogKit.createLoggerFor(module: "ContentKit")

// MARK: - ContentKit

public enum ContentKit {}
public enum ContentKit {
public static func listSampleActivities() -> [Activity]? {
let bundle = Bundle.module
let files = bundle.paths(forResourcesOfType: "activity.yml", inDirectory: nil)

var activities: [Activity] = []

for file in files {
let data = try? String(contentsOfFile: file, encoding: .utf8)

guard let data else {
log.error("Error reading file: \(file)")
continue
}

let activity = try? YAMLDecoder().decode(Activity.self, from: data)

guard let activity else {
log.error("Error decoding file: \(file)")
continue
}

activities.append(activity)
}

return activities.sorted { $0.name < $1.name }
}
}

0 comments on commit 885be4a

Please sign in to comment.