Skip to content

Commit

Permalink
Fix #68: Change SVGParser.parse signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ystrot committed Jan 26, 2017
1 parent 78cbcb7 commit 58b95f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
22 changes: 9 additions & 13 deletions Source/svg/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ open class SVGParser {

/// Parse an SVG file identified by the specified bundle, name and file extension.
/// - returns: Root node of the corresponding Macaw scene.
open class func parse(bundle: Bundle, path: String, ofType: String = "svg") -> Node? {
guard let path = bundle.path(forResource: path, ofType: ofType) else {
return .none
}
do {
let text = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
return SVGParser.parse(text: text)
} catch _ {
return .none
}
open class func parse(bundle: Bundle, path: String, ofType: String = "svg") throws -> Node {
guard let fullPath = bundle.path(forResource: path, ofType: ofType) else {
throw SVGParserError.noSuchFile(path: "\(path).\(ofType)")
}
let text = try String(contentsOfFile: fullPath, encoding: String.Encoding.utf8)
return try SVGParser.parse(text: text)
}

/// Parse an SVG file identified by the specified name and file extension.
/// - returns: Root node of the corresponding Macaw scene.
open class func parse(path: String, ofType: String = "svg") -> Node? {
return SVGParser.parse(bundle: Bundle.main, path: path, ofType: ofType)
open class func parse(path: String, ofType: String = "svg") throws -> Node {
return try SVGParser.parse(bundle: Bundle.main, path: path, ofType: ofType)
}

/// Parse the specified content of an SVG file.
/// - returns: Root node of the corresponding Macaw scene.
open class func parse(text: String) -> Node {
open class func parse(text: String) throws -> Node {
return SVGParser(text).parse()
}

Expand Down
11 changes: 11 additions & 0 deletions Source/svg/SVGParserError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// SVGParserError.swift
// Pods
//
// Created by Yuri Strot on 1/26/17.
//
//

enum SVGParserError : Error {
case noSuchFile(path: String)
}
2 changes: 1 addition & 1 deletion Source/svg/SVGView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class SVGView: MacawView {
}

fileprivate func parseSVG() {
svgNode = SVGParser.parse(path: fileName ?? "")
svgNode = try? SVGParser.parse(path: fileName ?? "")
}

fileprivate func render() {
Expand Down

0 comments on commit 58b95f3

Please sign in to comment.