Code Monkey home page Code Monkey logo

playgroundbook's Introduction

CircleCI

playgroundbook

A series of tools for Swift Playground and Playground books based on Apple's documentation.

It's a work in progress (see issues) but you can use it now.

Installation

> [sudo] gem install playgroundbook

Usage

To lint an existing playground book:

> playgroundbook lint MyPlaygroundbook.playgroundbook

To generate a playground book:

> playgroundbook render book.yaml

The yml file should be in the following format:

name: Testing book
identifier: com.ashfurrow.example
resources: assets # Optional
cover: cover.jpeg # Optional
deployment_target: ios10.0 # Optional
imports: # Optional, defaults to UIKit
 - UIKit
 - CoreGraphics
chapters:
  - name: Chapter 1
    edge_to_edge_live_view: false # defaults to true
    live_view_mode: "VisibleByDefault" # defaults to "HiddenByDefault"
  - name: Chapter 2
  - etc...
glossary:
  term: definition

Note that you can't use tabs when indenting in the .yaml file. Everything needs to have spaces in order to work properly. Otherwise you will end up with parse errors.

Each chapter needs to have a corresponding playground; so Chapter 1 requires there be a Chapter 1.playground playground. Your directory should look like this:

Once you've created a playground for each chapter, it's time to add pages to your playgrounds. You can do this in Xcode.

Note that the order of the pages is determined by the ordering of the filesystem, which is lexicographical. You also can't have any periods in your pages.

Then run the render command in the directory containing the yaml file.

playgroundbook render book.yaml

The playgrounds can reference (not copy) resources from an optionally specified directory. import frameworks are specified in the yaml file and are added to every page of the book. You can specify a cover image file name that's stored in the resources directory (it should be 400x300 pixels). Finally, you can supply a glossary, a dictionary of term/definition pairs. This lets you link to terms in markdown. For example:

... [term](glossary://term) ...

Only the link to the term must be URL encoded. For example, the term "reuse identifier" would be defined in the yaml as reuse identifier but linked to as glossary://reuse%20identifier.

Each page in a chapter's .playground will be a separate page in the .playgroundbook and it's Source. The contents of the Source and Resource folders for each chapter and each page are copied.

Limitations of Book Rendering

Playground books support a rich set of awesome features to make learning how to code really easy, and this tool only scratches the surface. Read over the Playground Book reference to see all the available options. If you have suggestions, please open an issue ๐Ÿ‘

Creating a Playground from markdown

Maybe you want to do something for a website, or a git repo first, and then generate your Playground? Well in those cases your source of truth is the markdown document. For that case, we have playgroundbook wrapper.

For example, you might have a folder that looks like:

> tree Beginners/Lesson\ One

Beginners/Lesson\ One
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ README_ZH.md
โ””โ”€โ”€ img
    โ”œโ”€โ”€ emptyplayground.png
    โ”œโ”€โ”€ multipleresults.png
    โ”œโ”€โ”€ newplayground.png
    โ”œโ”€โ”€ results.png
    โ”œโ”€โ”€ tentimes.png
    โ””โ”€โ”€ welcome.png

You can run:

playgroundbook wrapper "Beginners/Lesson\ One/README.md" "Lesson One"

And it will switch out swift codeblocks into the playground. You have to use triple backticks with swift ```swift. No space between them. You should avoid using backtick blocks for anything other than Swift code, if you need to show examples, use Markdown's indentation rules with four spaces.

> tree Beginners/Lesson\ One

Beginners/Lesson\ One
โ”œโ”€โ”€ Lesson\ One.playground
โ”‚ย ย  โ”œโ”€โ”€ Contents.swift
โ”‚ย ย  โ”œโ”€โ”€ Resources
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ img
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ emptyplayground.png
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ newplayground.png
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ results.png
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ welcome.png
โ”‚ย ย  โ”œโ”€โ”€ contents.xcplayground
โ”‚ย ย  โ””โ”€โ”€ timeline.xctimeline
โ”œโ”€โ”€ README.md
...

You might notice that a subset of images, have moved well, they're the only one being used in the README.md. Slick huh?

Contributing

Hey! Like this tool? Awesome! We could actually really use your help!

Open source isn't just writing code. We could use your help with any of the following:

  • Finding (and reporting!) bugs.
  • New feature suggestions.
  • Answering questions on issues.
  • Reviewing pull requests.
  • Helping to manage issue priorities.
  • Fixing bugs/new features.

If any of that sounds cool to you, send a pull request! After a few contributions, we'll add you as an admin to the repo so you can merge pull requests and help steer the ship ๐Ÿšข You can read more details about that in our contributor guidelines.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by [its terms](Code of Conduct.md).

License

MIT, except for the starter.playgroundbook in the unit tests, which is licensed by Apple.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.