Home

Awesome

<p align="center"> <img src="https://github.com/bow-swift/nef/workflows/Compile and test/badge.svg" alt="Build"> <img src="https://github.com/bow-swift/nef/workflows/Deploy docs/badge.svg" alt="Site"> <a href="https://github.com/bow-swift/nef"> <img src="https://img.shields.io/badge/platform-macOS+iPad-blueviolet" alt="Platforms"> </a> <img src="https://img.shields.io/badge/dependency%20manager-swiftpm-blueviolet" alt="dependency manager: Swift Package Manager"> <a href="https://gitter.im/bowswift/bow"> <img src="https://img.shields.io/badge/Gitter-nef-blueviolet.svg" alt="Gitter"> </a> </p>

nef, short for Nefertiti, mother of Ankhesenamun, is a toolset to ease the creation of documentation in the form of Xcode Playgrounds. It provides compile-time verification of documentation, exports it in Markdown format that can be consumed by Jekyll to generate websites, and export Carbon snippets for a given Xcode Playground.

nef is inspired by ΛNK for Kotlin and tut for Scala.

Features

💡 Eases the creation of Xcode Playgrounds with support for third party libraries.

💡 Compiles Xcode Playgrounds with support for 3rd-party libraries from the command line.

💡 Builds a Playground Book for iPad with external dependencies defined in a Swift Package.

💡 Generates Markdown project from nef Playground.

💡 Generates Markdown files that can be consumed from Jekyll to create a microsite.

💡 Export Carbon code snippets for a given nef Playground.

 

💻 Installation

📟 Using Homebrew (preferred)

➜ brew install nef

It will warn you if there is a missing dependency and will provide guidance to install it.

 

📦 Using Swift Package Manager

nef can be consumed as a library in your macOS project.

.package(url: "https://github.com/bow-swift/nef.git", from: "{version}")

It is an excellent option if you want to use all nef features in your macOS app, even to build new tooling on top of nef.

You can read more about how to use nef library in the nef site.

 

🔌 Using Xcode Editor Extension

Some of nef features can be used directly in Xcode as an Extension. You can install it directly from App Store or downloading the last binary from the releases section.

 

📲 Using your iPad

You can create Swift Playgrounds -together with third-party libraries- directly in your iPad using the app nef Playgrounds.

 

Using a GitHub badge

You can create a nef badge for your GitHub repository, and let users try your project in their iPads.

<img src="https://raw.githubusercontent.com/bow-swift/bow-art/master/badges/nef-playgrounds-badge.svg" alt="bow Playground" style="height:20px">

 

Usage

📃 Creating a nef Playground

Xcode Playgrounds are a nice tool for prototyping and trying new concepts. However, third party libraries support is a bit cumbersome to add. One of the goals of nef is to make the creation of an Xcode Playground easier with support for one or more libraries.

By default, nef can create an Xcode Playground with support for Bow, the Functional Programming companion library for Swift.

➜ nef playground
<p align="center"> <img src="assets/nef-playground.png" height="100"> </p>

And you can use the following option to specify the name for the nef Playground that you are creating:

➜ nef playground --output ~/Desktop --name LatestBowProject

It will create an Xcode project with support for the latest available version of Bow, named LatestBowProject in your ~/Desktop. If you open this nef playground, you will find an Xcode Playground where you can import Bow or any of its modules, and start trying some of its features.

By default, nef playground will be created for iOS platform. If you need to change it, you can use the --platform option.

➜ nef playground --platform osx

If you need to take advantage of nef in your Xcode Playgrounds, you can transform your Xcode Playground into a nef Playground using the following command:

➜ nef playground --playground <Xcode Playground>

Where <Xcode Playground> is the path to your Xcode Playground.

<details> <summary>📣 You can create a nef Playground compatible with any different Bow version, branch or commit; even third-party dependencies</summary>

Note: The next options are mutually exclusive.

➜ nef playground --name OldBowProject --bow-version 0.3.0

➜ nef playground --name BranchBowProject --bow-branch master

➜ nef playground --name CommitBowProject --bow-commit e70c739067be1f5700f8b692523e1bb8931c7236

Your Podfile, located in ./folder/dependencies:

target 'MyPodsProject' do
  platform :osx, '10.14'
  use_frameworks!

  pod 'Bow', '~> 0.3.0'
end
➜ nef playground --name MyPodsProject --podfile ./folder/dependencies/Podfile

Your Cartfile, located in ./folder/dependencies:

github "bow-swift/Bow"
➜ nef playground --name MyCarthageProject --cartfile ./folder/dependencies/Cartfile
</details>

 

🔨 Compiling a nef Playground

Xcode lets you check for correctness of your Xcode Playground and run it. However, Apple does not provide us commands to compile an Xcode Playground, as they do for building Xcode projects. It is particularly useful in Continuous Integration when you want to verify that your playgrounds are not broken when the libraries you depend on are updated. nef has an option to compile a nef Playground. To do this, you can run the following command:

➜ nef compile --project <nef playground>

If you need to transform your Xcode Playground into a nef Playground you can check Creating a nef Playground section.

Where <nef playground> is the path to nef Playground where your playgrounds are located. Also, you can use the following option with this command:

➜ nef compile --project <nef playground> --use-cache

You can also clean the result of the compilation:

➜ nef clean --project <nef playground>

 

📲 Creating a Playground Book

Swift Playgrounds is a revolutionary app that makes possible to write Swift code on an iPad. In the latest updates, Swift Playgrounds 3.x has added a new feature: UserModules; it lets you include swift code and make it available across multiple chapters like modules.

nef takes advantage of these new possibilities and advancements in Swift Package Manager to build a Playground Book with external dependencies from a Swift Package specification.

Given a Package.swift like the next one:

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "BowProject",
    products: [
        .library(name: "BowProject", targets: ["nef"])
    ],
    dependencies: [
        .package(url: "https://github.com/bow-swift/bow.git", from: "0.8.0"),
    ],
    targets: [
        .target(name: "nef", dependencies: ["Bow"])
    ]
)

you can run the following command:

➜ nef ipad --name PlaygroundName --package Package.swift --output ~/Desktop

It will create a Playground Book (PlaygroundName) with support for the external dependencies and save it in ~/Desktop

Options:

 

🔖 Generating a Markdown project

Xcode Playgrounds let you write comments in Markdown format using the symbols //: for single line comments, or /*: */ for multiline comments. Inside these comments, you can use any Markdown syntax; an example:

/*:
 # This is a heading 1

 This is regular text. *This is bold text*. [This is a link](http://bow-swift.io).
 */
protocol MyProtocol {}

//: ## This is a single line heading 2

It makes Xcode Playgrounds the proper tool to write an article with compilable examples. The command provided by nef to generate the Markdown files is:

➜ nef markdown --project <nef playground> --output <path>

Options:

 

🌐 Generating Markdown files for Jekyll

As you can write comments in Markdown in Xcode Playgrounds, this makes it very suitable to write documentation with compilable examples. Leveraging this, nef can create Markdown files that can be consumed from Jekyll to generate a microsite. The command to do this is:

➜ nef jekyll --project <nef playground> --output <path> --main-page <main-page>

Options:

<details> <summary>📣 How to setup a nef Playgroud for Jekyll?</summary>

nef finds all the Xcode Playgrounds in a nef Playground. Each playground is considered a section in the generated microsite structure. For each page in a playground, an entry in the corresponding section is created. The page is transformed from Swift to Markdown using the syntax described above. As a result, a directory structure matching the nef Playground structure is generated, together with a sidebar.yml that can be used as a menu in Jekyll.

nef adds some commands to modify the Markdown transformation process. All nef commands are included as Swift comments. They begin with // nef:begin: and end with // nef:end. The supported commands are:

// nef:begin:header
/*
  layout: docs
*/
// nef:end
// nef:begin:hidden
import Bow // This will be hidden in the Markdown file
// nef:end

struct Person {} // This will be present in the Markdown file
</details>

 

🌁 Exporting Carbon code snippets

Xcode Playgrounds are a great place for prototyping and trying new concepts. Oftentimes we want to share some Swift snippets. Carbon is a cool tool for this, and nef nicely integrates with it. You can take your nef Playground, write several pieces of code, and keep it verified. Later, you can export all your code snippets with the next command:

➜ nef carbon --project <nef playground> --output <path>

Options:

<details> <summary>📣 You can customize the output with the next commands</summary>

<table> <tr> <th width="20%">Command</th> <th width="20%">Description</th> <th width="18%">Format</th> <th>Options</th> <th width="5%">Default</th> </tr> <tr> <td align="center"><code>--background</code></td> <td>Background color applied to image</td> <td>hexadecimal <code>#AABBCC</code>, <code>#AABBCCDD</code> or predefined colors</td> <td><img src="https://placehold.it/15/8c44ff/000000?text=+"> <code>nef</code> <img src="https://placehold.it/15/d54048/000000?text=+"> <code>bow</code> <img src="https://placehold.it/15/ffffff/000000?text=+"> <code>white</code> <br \><img src="https://placehold.it/15/6ef0a7/000000?text=+"> <code>green</code> <img src="https://placehold.it/15/42c5ff/000000?text=+"><code>blue</code> <img src="https://placehold.it/15/ffed75/000000?text=+"><code>yellow</code> <br \><img src="https://placehold.it/15/ff9f46/000000?text=+"> <code>orange</code</td> <td align="center"><code>nef</code></td> </tr> <tr> <td align="center"><code>--theme</code></td> <td>Carbon's theme to be applied</td> <td align="center">String</td> <td><code>base16-dark</code> <code>blackboard</code> <code>cobalt</code> <code>duotone-dark</code> <code>dracula</code> <code>hopscotch</code> <code>lucario</code> <code>material</code> <code>monokai</code> <code>night-owl</code> <code>nord</code> <code>oceanic-next</code> <code>one-dark</code> <code>panda-syntax</code> <code>paraiso-dark</code> <code>seti</code> <code>shades-of-purple</code> <code>synthwave-84</code> <code>tomorrow-night-bright</code> <code>twilight</code> <code>verminal</code> <code>vscode</code> <code>zenburn</code></td> <td align="center"><code>dracula</code></td> </tr> <tr> <td align="center"><code>--size</code></td> <td>Export file dimensions</td> <td align="center">Number</td> <td align="center">[<code>1</code>, <code>5</code>]</td> <td align="center"><code>2</code></td> </tr> <tr> <td align="center"><code>--font</code></td> <td>Font type</td> <td align="center">String</td> <td><code>firaCode</code> <code>hack</code> <code>inconsolata</code> <code>iosevka</code> <code>monoid</code> <code>anonymousPro</code> <code>sourceCodePro</code> <code>darkMono</code> <code>droidMono</code> <code>fantasqueMono</code> <code>ibmPlexMono</code> <code>spaceMono</code> <code>ubuntuMono</code></td> <td align="center"><code>firaCode</code></td> </tr> <tr> <td align="center"><code>--show-lines</code></td> <td>shows/hides number of lines in code snippet</td> <td align="center">Bool</td> <td><code>true</code> <code>false</code></td> <td align="center"><code>true</code></td> </tr> <tr> <td align="center"><code>--show-watermark</code></td> <td>shows/hides watermark in code snippet</td> <td align="center">Bool</td> <td><code>true</code> <code>false</code></td> <td align="center"><code>true</code></td> </tr> </table>

Example of use

If we have a project created by nef, and an Xcode playground with the next content:

let example = "This is an example"
print("nef is super cool: \(example)")

// nef is super cool: This is an example

Running the following command, we will customize the background color to #d54048 bow, hide the number of lines, and set the export file to size 3:

➜ nef carbon --project . --output ~/Desktop/nef-carbon --background bow --size 3 --show-lines false
<p align="center"> <img src="assets/nef-carbon-example.png" width="600"/> </p> </details>

 

❤️ Contributing to the project

You can contribute in different ways to make nef better:

How to run the project

Open project/nef.xcodeproj in Xcode 11 (or newer) and you are ready to go. nef uses the [Swift Package Manager] to handle its dependencies - they will be resolving automatically from Xcode.

How to run the documentation project

For further information, refer to our Contribution guidelines.

 

⚖️ License

Copyright (C) 2019-2021 The nef Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.