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

APIs modularization #98

Merged
merged 20 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
**/.DS_Store
**/xcuserdata/
BowPlayground
/.build

## SPM
.build
Package.resolved
truizlop marked this conversation as resolved.
Show resolved Hide resolved
.swiftpm
bin-cli
swiftpm

## Jekyll
_site
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
- PROJECT="./project/nef.xcodeproj"
- JOB="XCODE"
- DEST="arch=x86_64"
- SCHEME="Core"
- SCHEME="CoreTests"
- SDK="macosx"
- ACTION="test"

Expand Down
41 changes: 26 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ import PackageDescription
let package = Package(
name: "nef",
platforms: [
.macOS(.v10_13),
.macOS(.v10_14),
],
products: [
.library(name: "nef", targets: ["nef"]),
.library(name: "nef",
targets: ["nef",
"NefCore",
"NefModels",
"NefMarkdown",
"NefJekyll",
"NefCarbon"]),
],
dependencies: [
.package(url: "https://github.com/bow-swift/bow", from: "0.6.0"),
],
targets: [
.testTarget(name: "CoreTests", dependencies: ["Core"], path: "project/Tests/CoreTests"),
.target(name: "Core", dependencies: ["NefModels"], path: "project/Core"),

.target(name: "NefModels", path: "project/Component/NefModels"),
.target(name: "NefCarbon", dependencies: ["Core"], path: "project/Component/NefCarbon"),
.target(name: "NefJekyll", dependencies: ["Core"], path: "project/Component/NefJekyll"),
.target(name: "NefMarkdown", dependencies: ["Core"], path: "project/Component/NefMarkdown"),
.target(name: "nef", dependencies: ["NefMarkdown", "NefJekyll", "NefCarbon", "NefModels"], path: "project/Component/nef"),

.target(name: "Common", path: "project/UI/Common"),
.target(name: "Markdown", dependencies: ["Core", "Common", "NefMarkdown"], path: "project/UI/Markdown"),
.target(name: "Jekyll", dependencies: ["Core", "Common", "NefJekyll"], path: "project/UI/Jekyll"),
.target(name: "Carbon", dependencies: ["Core", "Common", "NefCarbon"], path: "project/UI/Carbon"),
.target(name: "NefModels", path: "project/Component/NefModels", publicHeadersPath: "Support Files"),
.target(name: "NefCore", dependencies: ["NefModels"], path: "project/Core", publicHeadersPath: "Support Files"),
.target(name: "NefMarkdown", dependencies: ["NefCore"], path: "project/Component/NefMarkdown", publicHeadersPath: "Support Files"),
.target(name: "NefJekyll", dependencies: ["NefCore"], path: "project/Component/NefJekyll", publicHeadersPath: "Support Files"),
.target(name: "NefCarbon", dependencies: ["NefModels", "NefCore"], path: "project/Component/NefCarbon", publicHeadersPath: "Support Files"),

.target(name: "nef",
dependencies: ["Bow", "BowEffects",
"NefCore",
"NefModels",
"NefMarkdown",
"NefJekyll",
"NefCarbon"],
path: "project/Component/nef",
publicHeadersPath: "Support Files"),
]
)
6 changes: 3 additions & 3 deletions bin/nef
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ playground() {
version=""
branch=""
podfile=""
carfile=""
cartfile=""

while [ "$1" != "" ]; do
case $2 in
Expand All @@ -334,7 +334,7 @@ playground() {
--bow-version ) shift; version=$1 ;;
--bow-branch ) shift; branch=$1 ;;
--podfile ) shift; podfile=$1 ;;
--carfile ) shift; carfile=$1 ;;
--cartfile ) shift; cartfile=$1 ;;

--use-cache) printHelpCompile; exit 1 ;;

Expand All @@ -359,7 +359,7 @@ playground() {
if [ "${#version}" -gt 0 ]; then
nef-playground --name "$projectName" --platform "$platform" --bow-version "$version"
else
nef-playground --name "$projectName" --platform "$platform" --bow-branch "$branch" --podfile "$podfile" --carfile "$carfile"
nef-playground --name "$projectName" --platform "$platform" --bow-branch "$branch" --podfile "$podfile" --cartfile "$cartfile"
fi

nefc install "$projectName.app"
Expand Down
4 changes: 3 additions & 1 deletion bin/nefc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ buildCarthage() {
[ $platformIOS -eq 1 ] && platform="iOS" || platform="osx"

cd "$cartfilePath"
rm "Cartfile.resolved" 1>/dev/null 2>/dev/null

if [ "$flag" = "$COMPILE_CACHED_DEPENDENCIES" ]; then
carthage bootstrap --cache-builds --platform $platform 1> "$log" 2>&1
else
Expand Down Expand Up @@ -267,7 +269,7 @@ buildProject() {
schemeName=$(schemeNameFromProject "$project")
sdk=$(sdkForWorkspaceAndScheme "$projectPath/$workspace" "$schemeName")
log="$logPath/$workspaceName.log"

echo -ne "${reset}Building ${green}$workspaceName${normal} ($schemeName) ..."

needBuildProject=$(shouldBuildWorkspace "$workspace" "$flag")
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefCarbon/App/CarbonAppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import AppKit
import Core
import NefCore

class CarbonAppDelegate: NSObject, NSApplicationDelegate {
private let main: (CarbonDownloader) -> Void
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefCarbon/App/CarbonApplication.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import AppKit
import Core
import NefCore

public class CarbonApplication {
private static let app = NSApplication.shared
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefCarbon/App/CarbonAssembler.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import AppKit
import Core
import NefCore

public class CarbonAssembler: CarbonProvider, CarbonAppDelegateAssembler {
public init() {}
Expand Down
6 changes: 3 additions & 3 deletions project/Component/NefCarbon/App/CarbonSyncDownloader.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import Foundation
import Core
import NefCore
import NefModels

class CarbonSyncDownloader: CarbonDownloader, CarbonViewDelegate {
Expand All @@ -20,8 +20,8 @@ class CarbonSyncDownloader: CarbonDownloader, CarbonViewDelegate {
}

// MARK: delegate <CarbonDownloader>
func carbon(withConfiguration configuration: Carbon, filename: String) -> Result<String, CarbonError> {
guard let view = view else { return .failure(CarbonError(filename: filename, snippet: configuration.code, error: .notFound)) }
func carbon(withConfiguration configuration: CarbonModel, filename: String) -> Result<String, CarbonError> {
guard let view = view else { return .failure(CarbonError(filename: filename, snippet: configuration.code, cause: .notFound)) }

run {
let filename = self.multiFiles ? "\(filename)-\(self.counter)" : filename
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefCarbon/App/CarbonViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NefModels

public enum CarbonViewer {

public static func urlRequest(from carbon: Carbon) -> URLRequest {
public static func urlRequest(from carbon: CarbonModel) -> URLRequest {
let backgroundColorItem = URLQueryItem(name: "bg", value: "\(carbon.style.background)")
let themeItem = URLQueryItem(name: "t", value: carbon.style.theme.rawValue)
let windowsThemeItem = URLQueryItem(name: "wt", value: "none")
Expand Down
12 changes: 6 additions & 6 deletions project/Component/NefCarbon/App/CarbonWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NefModels
/// Carbon view definition
public protocol CarbonView: NSView {
var carbonDelegate: CarbonViewDelegate? { get set }
func load(carbon: Carbon, filename: String)
func load(carbon: CarbonModel, filename: String)
}

public protocol CarbonViewDelegate: class {
Expand All @@ -20,7 +20,7 @@ public protocol CarbonViewDelegate: class {
class CarbonWebView: WKWebView, WKNavigationDelegate, CarbonView {

private var filename: String?
private var carbon: Carbon?
private var carbon: CarbonModel?
private var isCached: Bool = false
weak var carbonDelegate: CarbonViewDelegate?

Expand All @@ -33,7 +33,7 @@ class CarbonWebView: WKWebView, WKNavigationDelegate, CarbonView {
fatalError("init(coder:) has not been implemented")
}

func load(carbon: Carbon, filename: String) {
func load(carbon: CarbonModel, filename: String) {
self.filename = filename
self.carbon = carbon
isCached ? launchCachedRequest() : buildCache()
Expand All @@ -42,7 +42,7 @@ class CarbonWebView: WKWebView, WKNavigationDelegate, CarbonView {
// MARK: private methods
private func buildCache() {
let style = CarbonStyle(background: .bow, theme: .dracula, size: .x5, fontType: .firaCode, lineNumbers: true, watermark: true)
let carbon = Carbon(code: "", style: style)
let carbon = CarbonModel(code: "", style: style)
let request = CarbonViewer.urlRequest(from: carbon)
launch(carbonRequest: request)
}
Expand All @@ -62,7 +62,7 @@ class CarbonWebView: WKWebView, WKNavigationDelegate, CarbonView {

private func screenshot() {
guard let filename = filename, let code = carbon?.code else { didFailLoadingCarbonWebView(); return }
let screenshotError = CarbonError(filename: filename, snippet: code, error: .invalidSnapshot)
let screenshotError = CarbonError(filename: filename, snippet: code, cause: .invalidSnapshot)
let scale = CGFloat(carbon?.style.size.rawValue ?? 1)

setZoom(in: self, scale: scale)
Expand Down Expand Up @@ -100,7 +100,7 @@ class CarbonWebView: WKWebView, WKNavigationDelegate, CarbonView {
}

private func didFailLoadingCarbonWebView() {
let error = CarbonError(filename: filename ?? "", snippet: carbon?.code ?? "", error: .notFound)
let error = CarbonError(filename: filename ?? "", snippet: carbon?.code ?? "", cause: .notFound)
carbonDelegate?.didFailLoadCarbon(error: error)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import Foundation
import Core
import NefCore
import NefModels

/// Renders a page into multiple Carbon images.
Expand All @@ -25,6 +25,6 @@ public func renderCarbon(downloader: CarbonDownloader, code content: String, sty
///
/// - Parameter carbon: configuration
/// - Returns: URL request to carbon.now.sh
public func carbonURLRequest(from carbon: Carbon) -> URLRequest {
public func carbonURLRequest(from carbon: CarbonModel) -> URLRequest {
return CarbonViewer.urlRequest(from: carbon)
}
2 changes: 0 additions & 2 deletions project/Component/NefCarbon/Support Files/NefCarbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ FOUNDATION_EXPORT double NefCarbonVersionNumber;
FOUNDATION_EXPORT const unsigned char NefCarbonVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <NefCarbon/PublicHeader.h>


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import Foundation
import Core
import NefCore

/// Renders a page into Jekyll format.
///
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefJekyll/Support Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 47 Degrees. All rights reserved.</string>
<string>Copyright © 2019 The nef Authors.</string>
</dict>
</plist>
2 changes: 0 additions & 2 deletions project/Component/NefJekyll/Support Files/NefJekyll.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ FOUNDATION_EXPORT double NefJekyllVersionNumber;
FOUNDATION_EXPORT const unsigned char NefJekyllVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <NefJekyll/PublicHeader.h>


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2019 The nef Authors.

import Foundation
import Core
import NefCore

/// Renders a page into Markdown format.
///
Expand Down
2 changes: 1 addition & 1 deletion project/Component/NefMarkdown/Support Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 47 Degrees. All rights reserved.</string>
<string>Copyright © 2019 The nef Authors.</string>
</dict>
</plist>
2 changes: 0 additions & 2 deletions project/Component/NefMarkdown/Support Files/NefMarkdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ FOUNDATION_EXPORT double NefMarkdownVersionNumber;
FOUNDATION_EXPORT const unsigned char NefMarkdownVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <NefMarkdown/PublicHeader.h>


19 changes: 14 additions & 5 deletions project/Component/NefModels/CarbonModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Foundation

public struct Carbon: Codable, Equatable {
public struct CarbonModel: Codable, Equatable {
public let code: String
public let style: CarbonStyle

Expand Down Expand Up @@ -121,16 +121,16 @@ extension CarbonStyle.Color {
public struct CarbonError: Error {
public let filename: String
public let snippet: String
public let error: CarbonErrorOption
public let cause: CarbonError.Cause

public init(filename: String, snippet: String, error: CarbonErrorOption) {
public init(filename: String, snippet: String, cause: CarbonError.Cause) {
self.filename = filename
self.snippet = snippet
self.error = error
self.cause = cause
}

// MARK: Error options
public enum CarbonErrorOption: CustomStringConvertible {
public enum Cause: Error, CustomStringConvertible {
case notFound
case invalidSnapshot

Expand Down Expand Up @@ -168,6 +168,15 @@ extension CarbonStyle.Color {
guard let value = CarbonStyle.Color.all[string.lowercased()] else { return nil }
self = value
}

public var hex: String {
let opacity = UInt8(255 * a)
return "\(r.hex)\(g.hex)\(b.hex)\(opacity.hex)"
}
}

private extension UInt8 {
var hex: String { String(format: "%02X", self) }
}

// MARK: Helpers
Expand Down
1 change: 0 additions & 1 deletion project/Component/NefModels/Support Files/NefModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ FOUNDATION_EXPORT const unsigned char NefModelsVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <NefModels/PublicHeader.h>


Loading