diff --git a/README.md b/README.md index b39efae..fd5322c 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,6 @@ import Sugar This package contains a lot of misc. functionality that might not fit into it's own package or that would best to get PR'ed into Vapor. Some examples of what this package contains: -### Mutable Leaf tag config - -To allow third party packages to register their own Leaf tags, Sugar comes with a `MutableLeafTagConfig`. - #### How to use it in a package To have your package register the tags to the shared config, you can do the following: diff --git a/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfig.swift b/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfig.swift deleted file mode 100644 index bb327aa..0000000 --- a/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfig.swift +++ /dev/null @@ -1,30 +0,0 @@ -import Leaf -import Vapor - -/// Service that can be used to add tags from multiple sources which can then be registered at once -/// on `Leaf`s `LeafTagConfig`. -/// This is a workaround for not being able to mutate `Leaf`'s `LeafTagConfig`. -/// - See: https://github.com/vapor/leaf/pull/113. -public final class MutableLeafTagConfig: Service { - var storage: [String: TagRenderer] = [:] -} - -extension MutableLeafTagConfig { - /// Register multiple tags using the keys as their names. - /// - /// - Parameter list: Map of names to tags. - public func use(_ list: [String: TagRenderer]) { - for (name, tag) in list { - storage[name] = tag - } - } - - /// Register a single tag. - /// - /// - Parameters: - /// - tag: the tag to register. - /// - name: the name for the tag to use in template files. - public func use(_ tag: TagRenderer, as name: String) { - storage[name] = tag - } -} diff --git a/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfigProvider.swift b/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfigProvider.swift deleted file mode 100644 index f40a63c..0000000 --- a/Sources/Sugar/Helpers/Leaf/MutableLeafTagConfigProvider.swift +++ /dev/null @@ -1,28 +0,0 @@ -import Leaf - -/// Provider that transfers the leaf tags from the `MutableLeafTagConfig` to `Leaf`'s -/// `LeafTagConfig`. -/// This is a workaround for not being able to mutate `Leaf`'s `LeafTagConfig`. -/// - See: https://github.com/vapor/leaf/pull/113. -public final class MutableLeafTagConfigProvider: Provider { - /// Creates an `MutableLeafTagConfigProvider`. - public init() {} - - /// See `Provider.register`. - public func register(_ services: inout Services) throws { - // register LeafProvider here to ensure it does not override our `LeafTagConfig`. - try services.register(LeafProvider()) - services.register(MutableLeafTagConfig()) - services.register { container -> LeafTagConfig in - let mutableConfig: MutableLeafTagConfig = try container.make() - var config = LeafTagConfig.default() - config.use(mutableConfig.storage) - return config - } - } - - /// See `Provider.didBoot`. - public func didBoot(_ container: Container) throws -> Future { - return .done(on: container) - } -}