# Escapement Swift

## Installation

Install Escapement with [Carthage](https://github.com/Carthage/Carthage).

```
github "hodinkee/escapement-swift"
```

Or add the project and framework target directly to your project.

## Usage

# Escapement Swift

Render `NSAttributedString`s from the JSON structure generated by [escapement-rb](https://github.com/hodinkee/escapement-rb).

## Installation

Install Escapement with [Carthage](https://github.com/Carthage/Carthage).

```
github "hodinkee/escapement-swift"
```

## Usage

Escapement exposes two core types: `Document` and `Stylesheet`. `Document` conforms to `JSONDecodable` defined by [Alexander](https://github.com/hodinkee/alexander).

Given a `JSON` object, you can get a `Document?` by performing the following:

```swift
let document = JSON.flatMap(Document.decode)
```

(`Document`s are also `JSONEndocable` so you can serialize and save them.)

Now you can render an `NSAttributedString` with the following:

```swift
let stylesheet = Styleheet(rules: [
    Styleheet.Rule(selector: "*", attributes: [ NSFontAttributeName: UIFont(name: "TiemposText-Regular", size: 18)! ]),
    Styleheet.Rule(selector: "*", attributes: [ NSForegroundColorAttributeName: Theme.darkTextColor() ]),
    Styleheet.Rule(selectors: [ "s", "del" ], attributes: [ "TTTStrikeOutAttribute": NSUnderlineStyle.StyleSingle.rawValue ]),
    Styleheet.Rule(selector: "mark", attributes: [ NSBackgroundColorAttributeName: colorWithHex(0xEEEEEE) ])
])
let attributedString = document?.attributedStringWithStylesheet(stylesheet)
```

A `Stylesheet` allows you to decorate HTML markup with `NSAttributedString` attributes. Any attributes applied to the `*` selector are given to the attributed string upon initialization before other rules are applied. Rules are applied uniquely to each selector.

Add some usage to the readme.
Add some usage to the readme.