ollieatkinson / Guise

A tool to generate the Swift public interface for Frameworks and Libraries
MIT License
53 stars 5 forks source link

Remove Swift library from headers #6

Closed Sherlouk closed 6 years ago

Sherlouk commented 6 years ago

SwiftOnoneSupport

ollieatkinson commented 6 years ago

An idea here would be to create the ability to write custom post-generation text processors:

protocol TextProcessor {
  func process(input: String) throws -> String
}

struct RemoveSwiftOnoneSupport: TextProcessor {

  func process(input: String) throws -> String {
    return input.replacingOccurrences(of: "\nimport SwiftOnoneSupport", with: "")
  }

}

Then apply them to the generated source:

    var textProcessors: [TextProcessor] = [
      RemoveSwiftOnoneSupport()
    ]

    if options.noDocumentation {
      textProcessors.append(RemoveComments())
    }

    do {
      source = try textProcessors.reduce(source, { try $1.process(input: $0) })
    } catch {
      return .failure(.unexpectedError(error: error))
    }