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

Commit

Permalink
Merge branch 'master' into swiftlint-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe authored May 8, 2017
2 parents 00c9c9c + d8421d3 commit f98995b
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 39 deletions.
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@

### Bug Fixes

* Don't convert colors to the calibrated RGB color space if it isn't needed.
[David Jennes](https://github.com/djbe)
[#23](https://github.com/SwiftGen/SwiftGenKit/issues/23)
_None_

### Breaking Changes

_None_

### New Features

_None_

### Internal Changes

_None_

## 1.1.0

### Bug Fixes

* Don't convert colors to the calibrated RGB color space if it isn't needed.
[David Jennes](https://github.com/djbe)
[#23](https://github.com/SwiftGen/SwiftGenKit/issues/23)

### New Features

* More variables have been deprecated, while new variables have been added.
[David Jennes](https://github.com/djbe)
[#5](https://github.com/SwiftGen/SwiftGenKit/issues/5)
[#13](https://github.com/SwiftGen/SwiftGenKit/issues/13)
[#27](https://github.com/SwiftGen/SwiftGenKit/issues/27)
[#33](https://github.com/SwiftGen/SwiftGenKit/issues/33)
* The `strings`, `structuredStrings` and `tableName` have been replaced by `tables`, which is an array of string tables, each with a `name` and a `strings` property.
* For each string, the `params` variable and it's subvariables (such as `names`, `count`, ...) have been replaced by `types`, which is an array of types.
* `enumName`, `sceneEnumName` and `segueEnumName` have been replaced by `param.enumName`, `param.sceneEnumName` and `param.segueEnumName` respectively. Templates should provide a default value for these in case the variables are empty.
Expand Down
16 changes: 8 additions & 8 deletions Documentation/Strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ will be parsed into the following structure (not showing the rest of the structu
The output context has the following structure:

- `tables`: `Array` — List of string tables
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `strings`: `Array` — list of strings at this level:
- `key`: `String` — the full translation key, as it appears in the strings file
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `children`: `Array` — list of sub-levels, repeating the same structure as a level
- `strings` : `Array` — list of strings at this level:
- `name` : `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `key` : `String` — the full translation key, as it appears in the strings file
- `translation`: `String` — the translation for that key in the strings file
- `types`: `Array<String>` — defined only if localized string has parameter placeholders like `%d` and `%@` etc.
Contains a list of types like `"String"`, `"Int"`, etc
- `keytail`: `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PODS:
- PathKit (0.8.0)
- SwiftGenKit (1.0.1):
- SwiftGenKit (1.1.0):
- PathKit (~> 0.8.0)

DEPENDENCIES:
- SwiftGenKit (from `.`)

EXTERNAL SOURCES:
SwiftGenKit:
:path: "."
:path: .

SPEC CHECKSUMS:
PathKit: dcab05d701474011aae0e40cf892298a831f63d6
SwiftGenKit: 9b6f20360c33216663514b720016fa2d57cea478
SwiftGenKit: 6bffbbb5e592d537e48930b28d01cf0bec9d771b

PODFILE CHECKSUM: c30ec8de82eda04587ffe005a6ce7372509b1340

Expand Down
4 changes: 2 additions & 2 deletions Pods/Local Podspecs/SwiftGenKit.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Target Support Files/SwiftGenKit/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,54 @@ task :generate_contexts => "xcode:build" do |task|
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "Generate Contexts" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty)
end

## [ Release a new version ] ##################################################

namespace :release do
desc 'Create a new release on CocoaPods'
task :new => [:check_versions, 'xcode:test', :cocoapods]

desc 'Check if all versions from the podspecs and CHANGELOG match'
task :check_versions do
results = []

# Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early)
`which bundler`
results << Utils.table_result( $?.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.')

# Extract version from SwiftGen.podspec
podspec_version = Utils.podspec_version('SwiftGenKit')
Utils.table_info('SwiftGenKit.podspec', podspec_version)

# Check if version in Podfile.lock matches
podfile_lock_version = Utils.podfile_lock_version('SwiftGenKit')
results << Utils.table_result(podfile_lock_version == podspec_version, "Podfile.lock", "Please run pod install")

# Check if submodule is aligned
submodule_aligned = Dir.chdir('Tests/Resources') do
`git fetch origin`
`git rev-parse origin/master`.chomp == `git rev-parse HEAD`.chomp
end
results << Utils.table_result(submodule_aligned, "Submodule on origin/master", "Please align the submodule to master")

# Check if entry present in CHANGELOG
changelog_entry = system(%Q{grep -q '^## #{Regexp.quote(podspec_version)}$' CHANGELOG.md})
results << Utils.table_result(changelog_entry, "CHANGELOG, Entry added", "Please add an entry for #{podspec_version} in CHANGELOG.md")

changelog_master = system(%q{grep -qi '^## Master' CHANGELOG.md})
results << Utils.table_result(!changelog_master, "CHANGELOG, No master", 'Please remove entry for master in CHANGELOG')

exit 1 unless results.all?

print "Release version #{podspec_version} [Y/n]? "
exit 2 unless (STDIN.gets.chomp == 'Y')
end

desc 'pod trunk push SwiftGenKit to CocoaPods'
task :cocoapods do
Utils.print_header "Pushing pod to CocoaPods Trunk"
sh 'bundle exec pod trunk push SwiftGenKit.podspec'
end
end


task :default => 'xcode:test'
36 changes: 21 additions & 15 deletions Sources/Stencil/StringsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@ private extension String {

/*
- `tables`: `Array` — List of string tables
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `strings`: `Array` — list of strings at this level:
- `key`: `String` — the full translation key, as it appears in the strings file
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `children`: `Array` — list of sub-levels, repeating the same structure as a level
- `strings` : `Array` — list of strings at this level:
- `name` : `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `key` : `String` — the full translation key, as it appears in the strings file
- `translation`: `String` — the translation for that key in the strings file
- `types`: `Array<String>` — defined only if localized string has parameter placeholders like `%d` and `%@` etc.
Contains a list of types like `"String"`, `"Int"`, etc
- `keytail`: `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above
*/
extension StringsFileParser {
public func stencilContext(enumName: String = "L10n", tableName: String = "Localizable") -> [String: Any] {

let entryToStringMapper = { (entry: Entry, keyPath: [String]) -> [String: Any] in
var keyStructure = entry.keyStructure
Array(0..<keyPath.count).forEach { _ in keyStructure.removeFirst() }
let keytail = keyStructure.joined(separator: ".")
let levelName = keyStructure.joined(separator: ".")

var result: [String: Any] = [
"name": levelName,
"key": entry.key.newlineEscaped,
"translation": entry.translation.newlineEscaped,
"keytail": keytail

// NOTE: keytail is deprecated
"keytail": levelName
]

if entry.types.count > 0 {
Expand Down Expand Up @@ -67,7 +70,7 @@ extension StringsFileParser {
)
let tables: [[String: Any]] = [[
"name": tableName,
"strings": structuredStrings
"levels": structuredStrings
]]

return [
Expand Down Expand Up @@ -108,7 +111,7 @@ extension StringsFileParser {
structuredStrings["name"] = lastKeyPathComponent
}

var subenums: [[String: Any]] = []
var children: [[String: Any]] = []
let nextLevelKeyPaths: [[String]] = entries
.filter({ $0.keyStructure.count > keyPath.count+1 })
.map({ Array($0.keyStructure.prefix(keyPath.count+1)) })
Expand All @@ -127,15 +130,18 @@ extension StringsFileParser {
let entriesInKeyPath = entries.filter {
Array($0.keyStructure.map(normalize).prefix(nextLevelKeyPath.count)) == nextLevelKeyPath.map(normalize)
}
subenums.append(
children.append(
structure(entries: entriesInKeyPath,
atKeyPath: nextLevelKeyPath,
usingMapper: mapper)
)
}

if !subenums.isEmpty {
structuredStrings["subenums"] = subenums
if !children.isEmpty {
structuredStrings["children"] = children

// NOTE: These are deprecated variables
structuredStrings["subenums"] = children
}

return structuredStrings
Expand Down
2 changes: 1 addition & 1 deletion SwiftGenKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftGenKit"
s.version = "1.0.1"
s.version = "1.1.0"
s.summary = "The SwiftGen framework responsible for parsing assets and turn them in a dictionary representation suitable for Stencil templates"

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources
Submodule Resources updated 60 files
+4 −0 CHANGELOG.md
+42 −42 Contexts/Fonts/customname.plist
+42 −42 Contexts/Fonts/defaults.plist
+222,328 −372 Contexts/Strings/customname.plist
+222,328 −372 Contexts/Strings/defaults.plist
+2 −2 Contexts/Strings/empty.plist
+30 −18 Contexts/Strings/entries.plist
+36 −3 Contexts/Strings/multiline.plist
+1,369 −105 Contexts/Strings/structuredonly.plist
+1,394 −162 Contexts/Strings/utf8.plist
+0 −0 Documentation/Creating-your-templates.md
+50 −0 Documentation/colors/default.md
+54 −0 Documentation/colors/rawvalue.md
+50 −0 Documentation/colors/swift3.md
+49 −0 Documentation/fonts/default.md
+49 −0 Documentation/fonts/swift3.md
+50 −0 Documentation/images/dot-syntax-swift3.md
+50 −0 Documentation/images/dot-syntax.md
+82 −0 Documentation/storyboards/default.md
+86 −0 Documentation/storyboards/osx-default.md
+86 −0 Documentation/storyboards/osx-swift3.md
+82 −0 Documentation/storyboards/swift3.md
+52 −0 Documentation/strings/default.md
+68 −0 Documentation/strings/dot-syntax-swift3.md
+68 −0 Documentation/strings/dot-syntax.md
+52 −0 Documentation/strings/swift3.md
+6 −6 Podfile.lock
+3 −3 Pods/Local Podspecs/StencilSwiftKit.podspec.json
+6 −6 Pods/Manifest.lock
+195 −187 Pods/Pods.xcodeproj/project.pbxproj
+1 −1 Pods/Stencil/README.md
+1 −1 Pods/Stencil/Sources/Context.swift
+75 −11 Pods/Stencil/Sources/ForTag.swift
+57 −23 Pods/Stencil/Sources/IfTag.swift
+2 −2 Pods/Stencil/Sources/Loader.swift
+7 −3 Pods/Stencil/Sources/Tokenizer.swift
+19 −20 Pods/StencilSwiftKit/README.md
+0 −0 Pods/StencilSwiftKit/Sources/CallMacroNodes.swift
+8 −7 Pods/StencilSwiftKit/Sources/Context.swift
+10 −9 Pods/StencilSwiftKit/Sources/Environment.swift
+33 −0 Pods/StencilSwiftKit/Sources/Filters+Numbers.swift
+169 −0 Pods/StencilSwiftKit/Sources/Filters+Strings.swift
+35 −157 Pods/StencilSwiftKit/Sources/Filters.swift
+37 −9 Pods/StencilSwiftKit/Sources/Parameters.swift
+1 −1 Pods/Target Support Files/Stencil/Info.plist
+1 −1 Pods/Target Support Files/StencilSwiftKit/Info.plist
+7 −9 templates/storyboards-default.stencil
+7 −9 templates/storyboards-lowercase.stencil
+3 −5 templates/storyboards-osx-default.stencil
+3 −5 templates/storyboards-osx-lowercase.stencil
+3 −5 templates/storyboards-osx-swift3.stencil
+7 −9 templates/storyboards-swift3.stencil
+7 −9 templates/storyboards-uppercase.stencil
+7 −7 templates/strings-default.stencil
+7 −7 templates/strings-dot-syntax-swift3.stencil
+7 −7 templates/strings-dot-syntax.stencil
+6 −6 templates/strings-genstrings.stencil
+7 −7 templates/strings-no-comments-swift3.stencil
+14 −14 templates/strings-structured.stencil
+7 −7 templates/strings-swift3.stencil
35 changes: 33 additions & 2 deletions rakelib/utils.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Used constants:
# none

require 'json'

class Utils
COLUMN_WIDTH = 30

# formatter types
:xcpretty # pass through xcpretty and store in artifacts
:raw # store in artifacts
Expand All @@ -21,6 +25,17 @@ class Utils
end
end

def self.podspec_version(file = '*')
JSON.parse(`bundle exec pod ipc spec #{file}.podspec`)["version"]
end

def self.podfile_lock_version(pod)
require 'yaml'
root_pods = YAML.load_file('Podfile.lock')['PODS'].map { |n| n.is_a?(Hash) ? n.keys.first : n }
pod_vers = root_pods.select { |n| n.start_with?(pod) }.first # "SwiftGen (x.y.z)"
/\((.*)\)$/.match(pod_vers)[1] # Just the 'x.y.z' part
end

# print an info header
def self.print_header(str)
puts "== #{str.chomp} ==".format(:yellow, :bold)
Expand All @@ -36,6 +51,21 @@ class Utils
puts str.chomp.format(:red)
end

# format an info message in a 2 column table
def self.table_info(label, msg)
puts "#{label.ljust(COLUMN_WIDTH)} 👉 #{msg}"
end

# format a result message in a 2 column table
def self.table_result(result, label, error_msg)
if result
puts "#{label.ljust(COLUMN_WIDTH)} ✅"
else
puts "#{label.ljust(COLUMN_WIDTH)} ❌ - #{error_msg}"
end
result
end

## [ Private helper functions ] ##################################################

# run a command, pipe output through 'xcpretty' and store the output in CI artifacts
Expand Down Expand Up @@ -68,9 +98,10 @@ class Utils

# select the xcode version we want/support
def self.version_select
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n")
version = '8.*'
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '#{version}'"`.chomp.split("\n")
if xcodes.empty?
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n"
raise "\n[!!!] SwiftGen requires Xcode #{version}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n"
end

# Order by version and get the latest one
Expand Down

0 comments on commit f98995b

Please sign in to comment.