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

Commit

Permalink
Merge pull request #84 from SwiftGen/feature/access-modifier
Browse files Browse the repository at this point in the history
Adding a `param` to customize the access modifier (supersedes #81)
  • Loading branch information
AliSoftware authored Nov 1, 2017
2 parents 366a1d8 + f17dc0a commit 901f661
Show file tree
Hide file tree
Showing 156 changed files with 4,577 additions and 2,470 deletions.
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AllCops:
Exclude:
- SwiftGenKit/Tests/Resources/**/*
- SwiftGen/Resources/**/*

Style/HashSyntax:
Enabled: false

Lint/RescueWithoutErrorClass:
Enabled: false

Metrics/AbcSize:
Max: 24

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 140

Metrics/MethodLength:
Max: 30

Metrics/ClassLength:
Max: 120
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _None_
* XCAssets: exposed getter for color name string.
[Stephan Diederich](https://github.com/diederich)
[#87](https://github.com/SwiftGen/templates/pull/87)
* Allows to set all properties as `public` by using `--param publicAccess` on all templates.
[Olivier Halligon](https://github.com/AliSoftware)
[#84](https://github.com/SwiftGen/templates/pull/84)
[Txai Wieser](https://github.com/txaiwieser)
[#81](https://github.com/SwiftGen/templates/pull/81)

### Internal Changes

Expand Down
1 change: 1 addition & 0 deletions Documentation/colors/literals-swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

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.

Expand Down
1 change: 1 addition & 0 deletions Documentation/colors/literals-swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

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.

Expand Down
1 change: 1 addition & 0 deletions Documentation/colors/swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. |
| `colorAliasName` | `Color` | Allows you to change the name of the generated `typealias` for the platform specific color type. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/colors/swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. |
| `colorAliasName` | `Color` | Allows you to change the name of the generated `typealias` for the platform specific color type. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/colors/swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. |
| `colorAliasName` | `Color` | Allows you to change the name of the generated `typealias` for the platform specific color type. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/fonts/swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `FontFamily` | Allows you to change the name of the generated `enum` containing all font families. |
| `preservePath` | N/A | Setting this parameter will disable the basename filter applied to all font paths. Use this if you added your font folder as a "folder reference" in your Xcode project, making that folder hierarchy preserved once copied in the build app bundle. The path will be relative to the folder you provided to SwiftGen. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/fonts/swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `FontFamily` | Allows you to change the name of the generated `enum` containing all font families. |
| `preservePath` | N/A | Setting this parameter will disable the basename filter applied to all font paths. Use this if you added your font folder as a "folder reference" in your Xcode project, making that folder hierarchy preserved once copied in the build app bundle. The path will be relative to the folder you provided to SwiftGen. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/fonts/swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `FontFamily` | Allows you to change the name of the generated `enum` containing all font families. |
| `preservePath` | N/A | Setting this parameter will disable the basename filter applied to all font paths. Use this if you added your font folder as a "folder reference" in your Xcode project, making that folder hierarchy preserved once copied in the build app bundle. The path will be relative to the folder you provided to SwiftGen. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/storyboards/swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You can customize some elements of this template by overriding the following par
| `segueEnumName` | `StoryboardSegue` | Allows you to change the name of the generated `enum` containing all storyboard segues. |
| `module` | N/A | By default, the template will import the needed modules for custom classes, but won’t import the target’s module to avoid an import warning — using the `PRODUCT_MODULE_NAME` environment variable to detect it. Should you need to ignore an additional module, you can provide it here. |
| `ignoreTargetModule` | N/A | Setting this parameter will disable the behaviour of prefixing classes with their module name for (only) the target module. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/storyboards/swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You can customize some elements of this template by overriding the following par
| `segueEnumName` | `StoryboardSegue` | Allows you to change the name of the generated `enum` containing all storyboard segues. |
| `module` | N/A | By default, the template will import the needed modules for custom classes, but won’t import the target’s module to avoid an import warning — using the `PRODUCT_MODULE_NAME` environment variable to detect it. Should you need to ignore an additional module, you can provide it here. |
| `ignoreTargetModule` | N/A | Setting this parameter will disable the behaviour of prefixing classes with their module name for (only) the target module. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/storyboards/swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You can customize some elements of this template by overriding the following par
| `segueEnumName` | `StoryboardSegue` | Allows you to change the name of the generated `enum` containing all storyboard segues. |
| `module` | N/A | By default, the template will import the needed modules for custom classes, but won’t import the target’s module to avoid an import warning — using the `PRODUCT_MODULE_NAME` environment variable to detect it. Should you need to ignore an additional module, you can provide it here. |
| `ignoreTargetModule` | N/A | Setting this parameter will disable the behaviour of prefixing classes with their module name for (only) the target module. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/flat-swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/flat-swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/flat-swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/structured-swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/structured-swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/strings/structured-swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You can customize some elements of this template by overriding the following par
| -------------- | ------------- | ----------- |
| `enumName` | `L10n` | Allows you to change the name of the generated `enum` containing all string tables. |
| `noComments` | N/A | Setting this parameter will disable the comments describing the translation of a key. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/xcassets/swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can customize some elements of this template by overriding the following par
| `colorTypeName` | `ColorAsset` | Allows you to change the name of the struct type representing a color. |
| `imageTypeName` | `ImageAsset` | Allows you to change the name of the struct type representing an image. |
| `noAllValues` | N/A | Setting this parameter will disable generation of the `allColors` and `allImages` constants. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/xcassets/swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can customize some elements of this template by overriding the following par
| `colorTypeName` | `ColorAsset` | Allows you to change the name of the struct type representing a color. |
| `imageTypeName` | `ImageAsset` | Allows you to change the name of the struct type representing an image. |
| `noAllValues` | N/A | Setting this parameter will disable generation of the `allColors` and `allImages` constants. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
1 change: 1 addition & 0 deletions Documentation/xcassets/swift4.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can customize some elements of this template by overriding the following par
| `colorTypeName` | `ColorAsset` | Allows you to change the name of the struct type representing a color. |
| `imageTypeName` | `ImageAsset` | Allows you to change the name of the struct type representing an image. |
| `noAllValues` | N/A | Setting this parameter will disable generation of the `allColors` and `allImages` constants. |
| `publicAccess` | N/A | If set, the generated constants will be marked as `public`. Otherwise, they'll be declared `internal`. |

## Generated Code

Expand Down
15 changes: 15 additions & 0 deletions Fixtures/stub-env/PublicDefinitions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if os(iOS)
import UIKit

public class CreateAccViewController: UIViewController {
}
public class XXPickerViewController: UIViewController {
}
#elseif os(OSX)
import Cocoa

public class CustomTabViewController: NSWindowController {
}
public class NSControllerPlaceholder: NSWindowController {
}
#endif
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

source 'https://rubygems.org'

gem 'cocoapods', '1.3.1'
gem 'cocoapods', '~> 1.3'
gem 'octokit', '~> 4.7'
gem 'rake'
gem 'rake', '~> 10.4'
gem 'rubocop', '~> 0.51'
gem 'xcpretty'
25 changes: 21 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
ast (2.3.0)
claide (1.0.2)
cocoapods (1.3.1)
activesupport (>= 4.0.2, < 5)
Expand Down Expand Up @@ -59,16 +60,31 @@ GEM
netrc (0.7.8)
octokit (4.7.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
public_suffix (2.0.5)
rake (12.0.0)
rainbow (2.2.2)
rake
rake (10.5.0)
rouge (2.0.7)
rubocop (0.51.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-macho (1.1.0)
ruby-progressbar (1.9.0)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode-display_width (1.3.0)
xcodeproj (1.5.1)
CFPropertyList (~> 2.3.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -81,10 +97,11 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.3.1)
cocoapods (~> 1.3)
octokit (~> 4.7)
rake
rake (~> 10.4)
rubocop (~> 0.51)
xcpretty

BUNDLED WITH
1.15.3
1.16.0
15 changes: 8 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'English'
WORKSPACE = 'Templates'.freeze
SCHEME_NAME = 'Tests'.freeze
CONFIGURATION = 'Debug'.freeze
MIN_XCODE_VERSION = '~> 9.0'
MIN_XCODE_VERSION = '~> 9.0'.freeze

## [ Output compilation ] #####################################################

Expand Down Expand Up @@ -125,15 +125,16 @@ namespace :output do
end
sdks = sdks(f)

definitions = if f.include?('extra-definitions')
%("#{MODULE_OUTPUT_PATH}/Definitions.swift" "#{MODULE_OUTPUT_PATH}/ExtraDefinitions.swift")
else
definitions = %("#{MODULE_OUTPUT_PATH}/Definitions.swift")
end
defs = if f.include?('publicAccess')
["#{MODULE_OUTPUT_PATH}/PublicDefinitions.swift"]
else
defs = ["#{MODULE_OUTPUT_PATH}/Definitions.swift"]
end
defs << "#{MODULE_OUTPUT_PATH}/ExtraDefinitions.swift" if f.include?('extra-definitions')

commands = sdks.map do |sdk|
%(--toolchain #{toolchain[:toolchain]} -sdk #{sdk} swiftc -swift-version #{toolchain[:version]} ) +
%(-typecheck -target #{SDKS[sdk]} -I #{toolchain[:module_path]} #{definitions} #{f})
%(-typecheck -target #{SDKS[sdk]} -I #{toolchain[:module_path]} #{defs.join(' ')} #{f})
end
subtask = File.basename(f, '.*')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if os(OSX)
import AppKit
enum UIColor { }
internal enum UIColor { }
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit
#endif
Expand All @@ -11,7 +11,7 @@
// swiftlint:disable file_length

// swiftlint:disable identifier_name line_length type_body_length
extension UIColor {
internal 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)
Expand Down
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
public enum ColorName { }
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit
public enum ColorName { }
#endif

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length

// swiftlint:disable identifier_name line_length type_body_length
public 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
6 changes: 3 additions & 3 deletions Tests/Expected/Colors/literals-swift3-context-defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

#if os(OSX)
import AppKit
enum ColorName { }
internal enum ColorName { }
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit
enum ColorName { }
internal enum ColorName { }
#endif

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length

// swiftlint:disable identifier_name line_length type_body_length
extension ColorName {
internal 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)
Expand Down
6 changes: 3 additions & 3 deletions Tests/Expected/Colors/literals-swift3-context-multiple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

#if os(OSX)
import AppKit
enum ColorName { }
internal enum ColorName { }
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit
enum ColorName { }
internal enum ColorName { }
#endif

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length

// swiftlint:disable identifier_name line_length type_body_length
extension ColorName {
internal 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)
Expand Down
Loading

0 comments on commit 901f661

Please sign in to comment.