Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
icons & converter
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Mar 3, 2022
1 parent 4a18d71 commit 6bdaed2
Show file tree
Hide file tree
Showing 290 changed files with 424 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ db.sqlite
/Tests/Public
/Tests/Resources
/docs
/out/*.swift
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "Fuzi",
"repositoryURL": "https://github.com/cezheng/Fuzi",
"state": {
"branch": null,
"revision": "f08c8323da21e985f3772610753bcfc652c2103f",
"version": "3.1.3"
}
},
{
"package": "swift-html",
"repositoryURL": "https://github.com/binarybirds/swift-html",
Expand Down
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/binarybirds/swift-html", from: "1.6.0"),
.package(url: "https://github.com/cezheng/Fuzi", from: "3.1.3"),
],
targets: [
.executableTarget(name: "Converter", dependencies: [
.product(name: "Fuzi", package: "Fuzi"),
]),

.target(name: "FeatherIcons", dependencies: [
.product(name: "SwiftSvg", package: "swift-html"),
]),
Expand Down
123 changes: 123 additions & 0 deletions Sources/Converter/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// File.swift
//
//
// Created by Tibor Bodecs on 2022. 03. 03..
//

import Fuzi
import Foundation

extension String {

var dashToCamel: String {
split(separator: "-").reduce("", { $0 + $1.capitalized }).capitalizingFirstLetter()
}

func capitalizingFirstLetter() -> String {
let first = String(prefix(1)).lowercased()
let other = String(dropFirst())
return first + other
}
}

let workUrl = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()

let inputUrl = workUrl.appendingPathComponent("svg")
let outputUrl = workUrl.appendingPathComponent("out")


let files = try FileManager.default.contentsOfDirectory(atPath: inputUrl.path)
for file in files {
let fileUrl = inputUrl.appendingPathComponent(file)

// let fileName = fileUrl.deletingPathExtension().lastPathComponent

// if fileName.dashToCamel == fileName {
// print("case \(fileName.dashToCamel)")
// }
// else {
// print("case \(fileName.dashToCamel) = \"\(fileName)\"")
// }

try generateDSL(fileUrl)
}


func generateDSL(_ fileUrl: URL) throws {
let fileName = fileUrl.deletingPathExtension().lastPathComponent.dashToCamel
var out = """
public extension Svg {
static var \(fileName): Svg {
"""

let xml = try String(contentsOf: fileUrl)

let document = try XMLDocument(string: xml)
if let root = document.root {
out += "\t\t.icon([\n"
for element in root.children {
guard let tag = element.tag else {
continue;
}
out += "\t\t\t"
switch tag {
case "polygon":
let points = element.attributes["points"]!.components(separatedBy: " ").joined(separator: ", ")
out += "Polygon([\(points)])"
case "polyline":
let points = element.attributes["points"]!.components(separatedBy: " ").joined(separator: ", ")
out += "Polyline([\(points)])"
case "path":
let d = element.attributes["d"]!
out += "Path(\"\(d)\")"
case "line":
let x1 = element.attributes["x1"]!
let y1 = element.attributes["y1"]!
let x2 = element.attributes["x2"]!
let y2 = element.attributes["y2"]!
out += "Line(x1: \(x1), y1: \(y1), x2: \(x2), y2: \(y2))"
case "rect":
let x = element.attributes["x"]!
let y = element.attributes["y"]!
let w = element.attributes["width"]!
let h = element.attributes["height"]!

out += "Rect(x: \(x), y: \(y), width: \(w), height: \(h)"
if let rx = element.attributes["rx"] {
out += ", rx: \(rx)"
}
if let ry = element.attributes["ry"] {
out += ", ry: \(ry)"
}
out += ")"
case "circle":
let cx = element.attributes["cx"]!
let cy = element.attributes["cy"]!
let r = element.attributes["r"]!
out += "Circle(cx: \(cx), cy: \(cy), r: \(r))"
case "ellipse":
let cx = element.attributes["cx"]!
let cy = element.attributes["cy"]!
let rx = element.attributes["rx"]!
let ry = element.attributes["ry"]!
out += "Ellipse(cx: \(cx), cy: \(cy), rx: \(rx), ry: \(ry))"
default:
fatalError("Unhandled tag: \(tag)")
}
out += ",\n"
}
out += "\t\t])"
}

out += "\n\t}\n}\n"

let file = "Svg+" + fileName + ".swift"
let outUrl = outputUrl.appendingPathComponent(file)
try out.write(to: outUrl, atomically: true, encoding: .utf8)
// print(out)
}
1 change: 1 addition & 0 deletions svg/activity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/airplay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/alert-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/alert-octagon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/alert-triangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/align-center.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/align-justify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/align-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/align-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/anchor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/aperture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/archive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-down-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-down-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-down-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-left-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-right-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-up-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-up-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-up-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/at-sign.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions svg/award.svg
1 change: 1 addition & 0 deletions svg/bar-chart-2.svg
1 change: 1 addition & 0 deletions svg/bar-chart.svg
1 change: 1 addition & 0 deletions svg/battery-charging.svg
1 change: 1 addition & 0 deletions svg/battery.svg
1 change: 1 addition & 0 deletions svg/bell-off.svg
1 change: 1 addition & 0 deletions svg/bell.svg
1 change: 1 addition & 0 deletions svg/bluetooth.svg
1 change: 1 addition & 0 deletions svg/bold.svg
1 change: 1 addition & 0 deletions svg/book-open.svg
1 change: 1 addition & 0 deletions svg/book.svg
1 change: 1 addition & 0 deletions svg/bookmark.svg
1 change: 1 addition & 0 deletions svg/box.svg
Loading

0 comments on commit 6bdaed2

Please sign in to comment.