This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from SwiftGen/feature/color-literals
Color template with literals
- Loading branch information
Showing
14 changed files
with
400 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## Template Information | ||
|
||
| Name | Description | | ||
| --------- | ----------------- | | ||
| File name | colors/literals-swift3.stencil | | ||
| Invocation example | `swiftgen colors -t literals-swift3 …` | | ||
| Language | Swift 3 | | ||
| Author | Olivier Halligon | | ||
|
||
## When to use it | ||
|
||
- When you need to generate *Swift 3* code | ||
- Supports _multiple_ color names with the _same_ value | ||
- Uses `#colorLiteral`s for easy preview of the actual color | ||
|
||
## Customization | ||
|
||
You can customize some elements of this template by overriding the following parameters when invoking `swiftgen` in the command line, using `--param <paramName>=<newValue>` | ||
|
||
| Parameter Name | Default Value | Description | | ||
| -------------- | ------------- | ----------- | | ||
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. | | ||
|
||
Note: if you use `--param enumName=UIColor` (or `NSColor` on macOS) then the color constants will be generated as an extension of the `UIColor` (iOS) / `NSColor` (macOS) type directly without creating a separate `enum` type for namespacing those color constants. | ||
|
||
## Generated Code | ||
|
||
**Extract:** | ||
|
||
```swift | ||
extension ColorName { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
} | ||
``` | ||
|
||
[Full generated code](https://github.com/SwiftGen/templates/blob/master/Tests/Expected/Colors/literals-swift3-context-defaults.swift) | ||
|
||
## Usage example | ||
|
||
```swift | ||
// To reference a color, simpy reference its static instance by name: | ||
let title = ColorName.articleBody | ||
let footnote = ColorName.articleFootnote | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## Template Information | ||
|
||
| Name | Description | | ||
| --------- | ----------------- | | ||
| File name | colors/literals-swift4.stencil | | ||
| Invocation example | `swiftgen colors -t literals-swift4 …` | | ||
| Language | Swift 4 | | ||
| Author | Olivier Halligon | | ||
|
||
## When to use it | ||
|
||
- When you need to generate *Swift 4* code | ||
- Supports _multiple_ color names with the _same_ value | ||
- Uses `#colorLiteral`s for easy preview of the actual color | ||
|
||
## Customization | ||
|
||
You can customize some elements of this template by overriding the following parameters when invoking `swiftgen` in the command line, using `--param <paramName>=<newValue>` | ||
|
||
| Parameter Name | Default Value | Description | | ||
| -------------- | ------------- | ----------- | | ||
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. | | ||
|
||
Note: if you use `--param enumName=UIColor` (or `NSColor` on macOS) then the color constants will be generated as an extension of the `UIColor` (iOS) / `NSColor` (macOS) type directly without creating a separate `enum` type for namespacing those color constants. | ||
|
||
## Generated Code | ||
|
||
**Extract:** | ||
|
||
```swift | ||
extension ColorName { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
} | ||
``` | ||
|
||
[Full generated code](https://github.com/SwiftGen/templates/blob/master/Tests/Expected/Colors/literals-swift4-context-defaults.swift) | ||
|
||
## Usage example | ||
|
||
```swift | ||
// To reference a color, simpy reference its static instance by name: | ||
let title = ColorName.articleBody | ||
let footnote = ColorName.articleFootnote | ||
``` |
25 changes: 25 additions & 0 deletions
25
Tests/Expected/Colors/literals-swift3-context-defaults-customname.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum UIColor { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension UIColor { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
26 changes: 26 additions & 0 deletions
26
Tests/Expected/Colors/literals-swift3-context-defaults.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum ColorName { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
enum ColorName { } | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension ColorName { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
// No color found |
44 changes: 44 additions & 0 deletions
44
Tests/Expected/Colors/literals-swift3-context-multiple.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum ColorName { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
enum ColorName { } | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension ColorName { | ||
enum Colors { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
enum Extra { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let cyanColor = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let namedValue = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let nestedNamedValue = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
25 changes: 25 additions & 0 deletions
25
Tests/Expected/Colors/literals-swift4-context-defaults-customname.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum UIColor { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension UIColor { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
26 changes: 26 additions & 0 deletions
26
Tests/Expected/Colors/literals-swift4-context-defaults.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum ColorName { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
enum ColorName { } | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension ColorName { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
// No color found |
44 changes: 44 additions & 0 deletions
44
Tests/Expected/Colors/literals-swift4-context-multiple.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen | ||
|
||
#if os(OSX) | ||
import AppKit.NSColor | ||
typealias Color = NSColor | ||
enum ColorName { } | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
typealias Color = UIColor | ||
enum ColorName { } | ||
#endif | ||
|
||
// swiftlint:disable file_length | ||
|
||
// swiftlint:disable identifier_name line_length type_body_length | ||
extension ColorName { | ||
enum Colors { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
enum Extra { | ||
/// 0x339666ff (r: 51, g: 150, b: 102, a: 255) | ||
static let articleBody = #colorLiteral(red: 0.2, green: 0.588235, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let articleFootnote = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0x33fe66ff (r: 51, g: 254, b: 102, a: 255) | ||
static let articleTitle = #colorLiteral(red: 0.2, green: 0.996078, blue: 0.4, alpha: 1.0) | ||
/// 0xff66ccff (r: 255, g: 102, b: 204, a: 255) | ||
static let cyanColor = #colorLiteral(red: 1.0, green: 0.4, blue: 0.8, alpha: 1.0) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let namedValue = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let nestedNamedValue = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
/// 0xffffffcc (r: 255, g: 255, b: 255, a: 204) | ||
static let `private` = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.8) | ||
} | ||
} | ||
// swiftlint:enable identifier_name line_length type_body_length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.