Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
refactor templates to use constants instead of enum cases
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed May 30, 2017
1 parent 199c9b3 commit 3e077fa
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 280 deletions.
39 changes: 5 additions & 34 deletions Tests/Expected/Colors/swift2-context-defaults-customname.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,19 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol XCTColorsType {
var rgbaValue: UInt32 { get }
}

extension XCTColorsType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum XCTColors: XCTColorsType {
enum XCTColors {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case ArticleBody
static let ArticleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case ArticleFootnote
static let ArticleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case ArticleTitle
static let ArticleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case Private

var rgbaValue: UInt32 {
switch self {
case .ArticleBody:
return 0x339666ff
case .ArticleFootnote:
return 0xff66ccff
case .ArticleTitle:
return 0x33fe66ff
case .Private:
return 0xffffffcc
}
}
static let Private = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: XCTColorsType) {
self.init(rgbaValue: name.rgbaValue)
}
}
39 changes: 5 additions & 34 deletions Tests/Expected/Colors/swift2-context-defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,19 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol ColorNameType {
var rgbaValue: UInt32 { get }
}

extension ColorNameType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum ColorName: ColorNameType {
enum ColorName {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case ArticleBody
static let ArticleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case ArticleFootnote
static let ArticleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case ArticleTitle
static let ArticleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case Private

var rgbaValue: UInt32 {
switch self {
case .ArticleBody:
return 0x339666ff
case .ArticleFootnote:
return 0xff66ccff
case .ArticleTitle:
return 0x33fe66ff
case .Private:
return 0xffffffcc
}
}
static let Private = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: ColorNameType) {
self.init(rgbaValue: name.rgbaValue)
}
}
51 changes: 8 additions & 43 deletions Tests/Expected/Colors/swift2-context-text-defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,28 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol ColorNameType {
var rgbaValue: UInt32 { get }
}

extension ColorNameType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum ColorName: ColorNameType {
enum ColorName {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case ArticleBody
static let ArticleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case ArticleFootnote
static let ArticleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case ArticleTitle
static let ArticleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case Cyan_Color
static let Cyan_Color = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case NamedValue
static let NamedValue = Color(rgbaValue: 0xffffffcc)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case NestedNamedValue
static let NestedNamedValue = Color(rgbaValue: 0xffffffcc)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case Private

var rgbaValue: UInt32 {
switch self {
case .ArticleBody:
return 0x339666ff
case .ArticleFootnote:
return 0xff66ccff
case .ArticleTitle:
return 0x33fe66ff
case .Cyan_Color:
return 0xff66ccff
case .NamedValue:
return 0xffffffcc
case .NestedNamedValue:
return 0xffffffcc
case .Private:
return 0xffffffcc
}
}
static let Private = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: ColorNameType) {
self.init(rgbaValue: name.rgbaValue)
}
}
39 changes: 5 additions & 34 deletions Tests/Expected/Colors/swift3-context-defaults-customname.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,19 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol XCTColorsType {
var rgbaValue: UInt32 { get }
}

extension XCTColorsType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum XCTColors: XCTColorsType {
enum XCTColors {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case articleBody
static let articleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case articleFootnote
static let articleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case articleTitle
static let articleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case `private`

var rgbaValue: UInt32 {
switch self {
case .articleBody:
return 0x339666ff
case .articleFootnote:
return 0xff66ccff
case .articleTitle:
return 0x33fe66ff
case .`private`:
return 0xffffffcc
}
}
static let `private` = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: XCTColorsType) {
self.init(rgbaValue: name.rgbaValue)
}
}
39 changes: 5 additions & 34 deletions Tests/Expected/Colors/swift3-context-defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,19 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol ColorNameType {
var rgbaValue: UInt32 { get }
}

extension ColorNameType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum ColorName: ColorNameType {
enum ColorName {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case articleBody
static let articleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case articleFootnote
static let articleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case articleTitle
static let articleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case `private`

var rgbaValue: UInt32 {
switch self {
case .articleBody:
return 0x339666ff
case .articleFootnote:
return 0xff66ccff
case .articleTitle:
return 0x33fe66ff
case .`private`:
return 0xffffffcc
}
}
static let `private` = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: ColorNameType) {
self.init(rgbaValue: name.rgbaValue)
}
}
51 changes: 8 additions & 43 deletions Tests/Expected/Colors/swift3-context-text-defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,28 @@ extension Color {
}
// swiftlint:enable operator_usage_whitespace

protocol ColorNameType {
var rgbaValue: UInt32 { get }
}

extension ColorNameType {
var color: Color {
return Color(named: self)
}
}

// swiftlint:disable identifier_name line_length type_body_length
enum ColorName: ColorNameType {
enum ColorName {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
case articleBody
static let articleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case articleFootnote
static let articleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
case articleTitle
static let articleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
case cyanColor
static let cyanColor = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case namedValue
static let namedValue = Color(rgbaValue: 0xffffffcc)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case nestedNamedValue
static let nestedNamedValue = Color(rgbaValue: 0xffffffcc)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
case `private`

var rgbaValue: UInt32 {
switch self {
case .articleBody:
return 0x339666ff
case .articleFootnote:
return 0xff66ccff
case .articleTitle:
return 0x33fe66ff
case .cyanColor:
return 0xff66ccff
case .namedValue:
return 0xffffffcc
case .nestedNamedValue:
return 0xffffffcc
case .`private`:
return 0xffffffcc
}
}
static let `private` = Color(rgbaValue: 0xffffffcc)
}
// swiftlint:enable identifier_name line_length type_body_length

extension Color {
convenience init(named name: ColorNameType) {
self.init(rgbaValue: name.rgbaValue)
}
}
Loading

0 comments on commit 3e077fa

Please sign in to comment.