Skip to content

Commit

Permalink
fix: There is no reason for Reader to have the generic type M any longer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrenskers committed Feb 21, 2025
1 parent bc4d411 commit 17daf71
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 140 deletions.
4 changes: 2 additions & 2 deletions Sources/Saga/ProcessingStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import PathKit

internal class ProcessStep<M: Metadata> {
let folder: Path?
let readers: [Reader<M>]
let readers: [Reader]
let filter: (Item<M>) -> Bool
let itemProcessor: ((Item<M>) async -> Void)?
let writers: [Writer<M>]
var items: [Item<M>]

init(folder: Path?, readers: [Reader<M>], itemProcessor: ((Item<M>) async -> Void)?, filter: @escaping (Item<M>) -> Bool, writers: [Writer<M>]) {
init(folder: Path?, readers: [Reader], itemProcessor: ((Item<M>) async -> Void)?, filter: @escaping (Item<M>) -> Bool, writers: [Writer<M>]) {
self.folder = folder
self.readers = readers
self.itemProcessor = itemProcessor
Expand Down
20 changes: 6 additions & 14 deletions Sources/Saga/Reader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,21 @@ import PathKit
/// ```swift
/// public extension Reader {
/// static func myMarkdownReader() -> Self {
/// Reader(supportedExtensions: ["md", "markdown"], convert: { absoluteSource, relativeSource, relativeDestination in
/// Reader(supportedExtensions: ["md", "markdown"], convert: { absoluteSource in
/// let content: String = try absoluteSource.read()
///
/// // Somehow turn `content` into an ``Item``, and return it:
/// let item = Item(
/// relativeSource: ...,
/// relativeDestination: ...,
/// title: ...,
/// rawContent: ...,
/// body: ...,
/// date: ...,
/// lastModified: ...,
/// metadata: ...
/// )
/// // Parse `content` markdown
/// // ...
///
/// return item
/// // and return the parts:
/// return (title: "...", body: "...", frontmatter: [:])
/// })
/// }
/// }
/// ```
///
/// > Note: Instead of constructing your own `Reader` from scratch for your website, you should probably install one such as [SagaParsleyMarkdownReader](https://github.com/loopwerk/SagaParsleyMarkdownReader), [SagaPythonMarkdownReader](https://github.com/loopwerk/SagaPythonMarkdownReader), or [SagaInkMarkdownReader](https://github.com/loopwerk/SagaInkMarkdownReader).
public struct Reader<M: Metadata> {
public struct Reader {
/// Which file extensions can be handled by this reader? For example `md` or `rst`.
var supportedExtensions: [String]

Expand Down
2 changes: 1 addition & 1 deletion Sources/Saga/Saga.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class Saga {
/// - writers: The writers that will be used by this step.
/// - Returns: The Saga instance itself, so you can chain further calls onto it.
@discardableResult
public func register<M: Metadata>(folder: Path? = nil, metadata: M.Type = EmptyMetadata.self, readers: [Reader<M>], itemProcessor: ((Item<M>) async -> Void)? = nil, filter: @escaping ((Item<M>) -> Bool) = { _ in true }, itemWriteMode: ItemWriteMode = .moveToSubfolder, writers: [Writer<M>]) throws -> Self {
public func register<M: Metadata>(folder: Path? = nil, metadata: M.Type = EmptyMetadata.self, readers: [Reader], itemProcessor: ((Item<M>) async -> Void)? = nil, filter: @escaping ((Item<M>) -> Bool) = { _ in true }, itemWriteMode: ItemWriteMode = .moveToSubfolder, writers: [Writer<M>]) throws -> Self {
let step = ProcessStep(folder: folder, readers: readers, itemProcessor: itemProcessor, filter: filter, writers: writers)
self.processSteps.append(
.init(
Expand Down
62 changes: 6 additions & 56 deletions docs/data/documentation/saga/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,40 +80,6 @@
{
"kind" : "identifier",
"text" : "Reader"
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "genericParameter",
"text" : "M"
},
{
"kind" : "text",
"text" : "> "
},
{
"kind" : "keyword",
"text" : "where"
},
{
"kind" : "text",
"text" : " "
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : " : "
},
{
"identifier" : "doc:\/\/Saga\/documentation\/Saga\/Metadata",
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:4Saga8MetadataP",
"text" : "Metadata"
}
]
}
Expand Down Expand Up @@ -170,22 +136,14 @@
"code" : [
"public extension Reader {",
" static func myMarkdownReader() -> Self {",
" Reader(supportedExtensions: [\"md\", \"markdown\"], convert: { absoluteSource, relativeSource, relativeDestination in",
" Reader(supportedExtensions: [\"md\", \"markdown\"], convert: { absoluteSource in",
" let content: String = try absoluteSource.read()",
"",
" \/\/ Somehow turn `content` into an ``Item``, and return it:",
" let item = Item(",
" relativeSource: ...,",
" relativeDestination: ...,",
" title: ...,",
" rawContent: ...,",
" body: ...,",
" date: ...,",
" lastModified: ...,",
" metadata: ...",
" )",
" \/\/ Parse `content` markdown",
" \/\/ ...",
"",
" return item",
" \/\/ and return the parts:",
" return (title: \"...\", body: \"...\", frontmatter: [:])",
" })",
" }",
"}"
Expand Down Expand Up @@ -544,15 +502,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">."
"text" : "."
},
{
"kind" : "typeIdentifier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"kind" : "symbol",
"metadata" : {
"externalID" : "s:4Saga6ReaderV19supportedExtensions7convertACyxGSaySSG_SSSg5title_SS4bodySDyS2SGSg11frontmattert7PathKit0I0VYaKctcfc",
"externalID" : "s:4Saga6ReaderV19supportedExtensions7convertACSaySSG_SSSg5title_SS4bodySDyS2SGSg11frontmattert7PathKit0I0VYaKctcfc",
"fragments" : [
{
"kind" : "identifier",
Expand Down Expand Up @@ -61,15 +61,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">."
"text" : "."
},
{
"kind" : "typeIdentifier",
Expand Down Expand Up @@ -151,15 +143,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">."
"text" : "."
},
{
"identifier" : "doc:\/\/Saga\/documentation\/Saga\/Reader\/Converter",
Expand Down Expand Up @@ -369,15 +353,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">."
"text" : "."
},
{
"kind" : "typeIdentifier",
Expand Down
10 changes: 1 addition & 9 deletions docs/data/documentation/saga/saga.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">], "
"text" : "], "
},
{
"kind" : "externalParam",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"kind" : "symbol",
"metadata" : {
"externalID" : "s:4SagaAAC8register6folder8metadata7readers13itemProcessor6filter0F9WriteMode7writersABXD7PathKit0L0VSg_xmSayAA6ReaderVyxGGyAA4ItemCyxGYacSgSbAUcAA0oiJ0OSayAA6WriterVyxGGtKAA8MetadataRzlF",
"externalID" : "s:4SagaAAC8register6folder8metadata7readers13itemProcessor6filter0F9WriteMode7writersABXD7PathKit0L0VSg_xmSayAA6ReaderVGyAA4ItemCyxGYacSgSbATcAA0oiJ0OSayAA6WriterVyxGGtKAA8MetadataRzlF",
"fragments" : [
{
"kind" : "keyword",
Expand Down Expand Up @@ -93,15 +93,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">], "
"text" : "], "
},
{
"kind" : "externalParam",
Expand Down Expand Up @@ -336,15 +328,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">], "
"text" : "], "
},
{
"kind" : "externalParam",
Expand Down Expand Up @@ -1029,15 +1013,7 @@
},
{
"kind" : "text",
"text" : "<"
},
{
"kind" : "typeIdentifier",
"text" : "M"
},
{
"kind" : "text",
"text" : ">], "
"text" : "], "
},
{
"kind" : "externalParam",
Expand Down
4 changes: 2 additions & 2 deletions docs/index/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
{
"path" : "\/documentation\/saga\/reader\/init(supportedextensions:convert:)",
"title" : "init(supportedExtensions: [String], convert: Reader<M>.Converter)",
"title" : "init(supportedExtensions: [String], convert: Reader.Converter)",
"type" : "init"
},
{
Expand Down Expand Up @@ -232,7 +232,7 @@
},
{
"path" : "\/documentation\/saga\/saga\/register(folder:metadata:readers:itemprocessor:filter:itemwritemode:writers:)",
"title" : "func register<M>(folder: Path?, metadata: M.Type, readers: [Reader<M>], itemProcessor: ((Item<M>) async -> Void)?, filter: ((Item<M>) -> Bool), itemWriteMode: ItemWriteMode, writers: [Writer<M>]) throws -> Self",
"title" : "func register<M>(folder: Path?, metadata: M.Type, readers: [Reader], itemProcessor: ((Item<M>) async -> Void)?, filter: ((Item<M>) -> Bool), itemWriteMode: ItemWriteMode, writers: [Writer<M>]) throws -> Self",
"type" : "method"
},
{
Expand Down

0 comments on commit 17daf71

Please sign in to comment.