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

Add SwiftPM support #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Highlightr.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Pod::Spec.new do |s|

s.source_files = 'Pod/Classes/**/*.{swift}'

s.resources = 'Pod/Assets/**/*.{css,js}'
s.resource = 'Assets/highlighter.bundle'

s.ios.frameworks = 'UIKit'
s.osx.frameworks = 'AppKit'
Expand Down
506 changes: 8 additions & 498 deletions Highlightr.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
name: "Highlightr",
platforms: [
.macOS(.v10_11),
.iOS(.v9),
.tvOS(.v9)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Highlightr",
targets: ["Highlightr"])
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Highlightr",
path: "Pod",
sources: ["Classes"],
resources: [ // require swift-tools-version:5.3
.copy("Assets/highlighter.bundle")
]
)
]
)
File renamed without changes.
2 changes: 2 additions & 0 deletions Pod/Classes/CodeAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation

#if os(OSX)
import AppKit
#else
import UIKit
#endif

/// Highlighting Delegate
Expand Down
15 changes: 7 additions & 8 deletions Pod/Classes/Highlightr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import Foundation
import JavaScriptCore

#if os(OSX)
import AppKit
#endif

/// Utility class for generating a highlighted NSAttributedString from a String.
open class Highlightr
{
Expand Down Expand Up @@ -53,8 +49,11 @@ open class Highlightr
let window = JSValue(newObjectIn: jsContext)
jsContext.setObject(window, forKeyedSubscript: "window" as NSString)

let bundle = Bundle(for: Highlightr.self)
self.bundle = bundle
#if SWIFT_PACKAGE
self.bundle = Bundle(path: Bundle.module.path(forResource: "highlighter", ofType: "bundle")!)!
#else
self.bundle = Bundle(path: Bundle(for: Highlightr.self).path(forResource: "highlighter", ofType: "bundle")!)!
#endif
guard let hgPath = highlightPath ?? bundle.path(forResource: "highlight.min", ofType: "js") else
{
return nil
Expand Down Expand Up @@ -89,7 +88,7 @@ open class Highlightr
@discardableResult
open func setTheme(to name: String) -> Bool
{
guard let defTheme = bundle.path(forResource: name+".min", ofType: "css") else
guard let defTheme = bundle.path(forResource: name+".min", ofType: "css", inDirectory: "styles") else
{
return false
}
Expand Down Expand Up @@ -156,7 +155,7 @@ open class Highlightr
*/
open func availableThemes() -> [String]
{
let paths = bundle.paths(forResourcesOfType: "css", inDirectory: nil) as [NSString]
let paths = bundle.paths(forResourcesOfType: "css", inDirectory: "styles") as [NSString]
var result = [String]()
for path in paths {
result.append(path.lastPathComponent.replacingOccurrences(of: ".min.css", with: ""))
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/Shims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation

#if os(OSX)
import AppKit
#else
import UIKit
#endif

#if swift(>=4.2)
Expand Down