Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #26

Merged
merged 9 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new extension for File
  • Loading branch information
KS1019 committed Mar 3, 2022
commit f79819e1a08e88f2a7b23a66ea5ff374b1798777
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let package = Package(
"SwiftyTextTable",
"Extensions",
]),
.target(name: "Models"),
.target(name: "Extensions"),
.target(name: "Models", dependencies: ["Extensions", "Files"]),
.target(name: "Extensions", dependencies: ["Files"]),
.testTarget(
name: "HondanaTests",
dependencies: ["Commands", "AssertSwiftCLI"]),
Expand Down
10 changes: 5 additions & 5 deletions Sources/Commands/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ enum Utils {
case .hondanaDir:
let folder = try Folder(path: Constants.hondanaDirURL + Constants.bookmarkletsURL)
let jsFiles = folder.files.filter { $0.extension == "js" }
return try jsFiles
.map {
(uuid: $0.nameExcludingExtension.components(separatedBy: "+").first!, title: $0.nameExcludingExtension.components(separatedBy: "+")[1], url: try $0.readAsString(encodedAs: .utf8).withJSPrefix.minified)
return jsFiles
.compactMap {
Bookmarklet(file: $0)
}
case .plist:
let file = try Folder(path: Constants.hondanaDirURL).file(named: "Bookmarks.plist")
Expand All @@ -57,7 +57,7 @@ enum Utils {
$0.URLString!.hasPrefix("javascript")
}
.map {
(uuid: $0.WebBookmarkUUID, title: $0.URIDictionary!.title, url: $0.URLString!.withoutJSPrefix.unminified)
Bookmarklet(bookmark: $0)
}

return bookmarklets
Expand Down Expand Up @@ -99,7 +99,7 @@ enum Utils {
return arr
}
.map { (arr: [String]) in
(uuid: "", title: arr[2], url: arr[1])
Bookmarklet(uuid: "", title: arr[2], url: arr[1])
}

return bookmarklets
Expand Down
7 changes: 7 additions & 0 deletions Sources/Extensions/Files+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Files

extension File {
var isBookmarklet: Bool {
self.extension == "js" && ((try? self.readAsString()) ?? "").hasPrefix("javascript") && self.nameExcludingExtension.contains("+")
}
}