Skip to content

Commit

Permalink
Merge pull request #35 from groue/Swift3
Browse files Browse the repository at this point in the history
Swift 3
  • Loading branch information
groue authored Oct 23, 2016
2 parents 8f324a5 + 9f14141 commit 7befd1a
Show file tree
Hide file tree
Showing 87 changed files with 6,379 additions and 6,409 deletions.
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
Release Notes
=============

## v2.0.0

**New**

- **Swift 3**
- Templates learned to render Int64, UInt64, Float, and CGFloat.
- The Box() function is no longer necessary when feeding templates:

```swift
// Still supported
let rendering try template.render(Box(["name": "Arthur"]))

// New:
let rendering try template.render(["name": "Arthur"])
```

**Breaking Changes**

- The only collections that can feed Mustache templates are arrays, sets, dictionaries, and Foundation collections that adopt NSFastEnumeration such as NSArray, SSet, NSOrderedSet, NSDictionary, etc. Other Swift collections such as ranges can no longer feed templates.

- The following APIs were modified:

```diff
// Use nil instead
-func Box() -> MustacheBox

-typealias KeyedSubscriptFunction = (key: String) -> MustacheBox
+typealias KeyedSubscriptFunction = (_ key: String) -> Any?

-typealias FilterFunction = (box: MustacheBox, partialApplication: Bool) throws -> MustacheBox
+typealias FilterFunction = (_ box: MustacheBox, _ partialApplication: Bool) throws -> Any?

-typealias WillRenderFunction = (tag: Tag, box: MustacheBox) -> MustacheBox
+typealias WillRenderFunction = (_ tag: Tag, _ box: MustacheBox) -> Any?

struct Configuration {
- func registerInBaseContext(_ key: String, _ box: MustacheBox)
+ func register(_ value: Any?, forKey key: String)
}

class Template {
- func registerInBaseContext(_ key: String, _ box: MustacheBox)
+ func register(_ value: Any?, forKey key: String)
}

class Context {
- func contextWithRegisteredKey(_ key: String, box: MustacheBox) -> Context
- func mustacheBoxForKey(_ key: String) -> MustacheBox
- func mustacheBoxForExpression(_ string: String) throws -> MustacheBox
+ func extendedContext(withRegisteredValue value: Any?, forKey key: String) -> Context
+ func mustacheBox(forKey key: String) -> MustacheBox
+ func mustacheBox(forExpression string: String) throws -> MustacheBox
}

class MustacheBox {
- func mustacheBoxForKey(_ key: String) -> MustacheBox
+ func mustacheBox(forKey key: String) -> MustacheBox
}
```


## v1.1.0

Released on September 19, 2016
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand Down Expand Up @@ -433,7 +433,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
39 changes: 20 additions & 19 deletions Docs/DemoApps/MustacheDemoOSX/MustacheDemoOSX/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,41 @@ class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()

for textView in [templateTextView, JSONTextView] {
textView.automaticQuoteSubstitutionEnabled = false;
textView.textStorage?.font = font
}
templateTextView.isAutomaticQuoteSubstitutionEnabled = false
templateTextView.textStorage?.font = font

JSONTextView.isAutomaticQuoteSubstitutionEnabled = false
JSONTextView.textStorage?.font = font
}

@IBAction func render(sender: AnyObject) {
@IBAction func render(_ sender: Any?) {
do {
let template = try Template(string: model.templateString)

// Play with those goodies in your templates:
// They are documented at https://github.com/groue/GRMustache.swift/blob/master/Guides/goodies.md

let percentFormatter = NSNumberFormatter()
percentFormatter.numberStyle = .PercentStyle
template.registerInBaseContext("percent", Box(percentFormatter))
template.registerInBaseContext("each", Box(StandardLibrary.each))
template.registerInBaseContext("zip", Box(StandardLibrary.zip))
template.registerInBaseContext("localize", Box(StandardLibrary.Localizer(bundle: nil, table: nil)))
template.registerInBaseContext("HTMLEscape", Box(StandardLibrary.HTMLEscape))
template.registerInBaseContext("URLEscape", Box(StandardLibrary.URLEscape))
template.registerInBaseContext("javascriptEscape", Box(StandardLibrary.javascriptEscape))
let percentFormatter = NumberFormatter()
percentFormatter.numberStyle = .percent
template.register(percentFormatter, forKey: "percent")
template.register(StandardLibrary.each, forKey: "each")
template.register(StandardLibrary.zip, forKey: "zip")
template.register(StandardLibrary.Localizer(), forKey: "localize")
template.register(StandardLibrary.HTMLEscape, forKey: "HTMLEscape")
template.register(StandardLibrary.URLEscape, forKey: "URLEscape")
template.register(StandardLibrary.javascriptEscape, forKey: "javascriptEscape")

let data = model.JSONString.dataUsingEncoding(NSUTF8StringEncoding)!
let JSONObject: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
let data = model.JSONString.data(using: .utf8)!
let JSONObject = try JSONSerialization.jsonObject(with: data, options: [])
let string = try template.render(Box(JSONObject as? NSObject))
presentRenderingString(string)
present(renderingString: string)
}
catch let error as NSError {
presentRenderingString("\(error.domain): \(error.localizedDescription)")
present(renderingString: "\(error.domain): \(error.localizedDescription)")
}
}

func presentRenderingString(string: String) {
func present(renderingString string: String) {
self.renderingTextView.string = string
self.renderingTextView.textStorage?.font = font
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand Down Expand Up @@ -435,7 +435,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
149 changes: 0 additions & 149 deletions Docs/DesignNotes/Box.md

This file was deleted.

Loading

0 comments on commit 7befd1a

Please sign in to comment.