Skip to content

Commit

Permalink
More function/var combos in R struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-cain13 committed Jan 10, 2016
1 parent 0b041a0 commit 296509b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- R.swift.Library (1.0.0.beta.4)
- R.swift.Library (1.0.0.beta.6)

DEPENDENCIES:
- R.swift.Library (from `./R.swift.Library`)
Expand All @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ./R.swift.Library

SPEC CHECKSUMS:
R.swift.Library: 9c624cd98f564c7404de07f6316ff6477a7c9247
R.swift.Library: 3247d9ea0da3d583f3e42571adba4dbd76b58ef1

COCOAPODS: 0.39.0
18 changes: 17 additions & 1 deletion R.swift/Generators/NibGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,27 @@ struct NibGenerator: Generator {
properties: groupedNibs
.uniques
.map(NibGenerator.nibVarForNib),
functions: [],
functions: groupedNibs
.uniques
.map(NibGenerator.nibFuncForNib),
structs: []
)
}

private static func nibFuncForNib(nib: Nib) -> Function {
return Function(
isStatic: true,
name: nib.name,
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void)
],
doesThrow: false,
returnType: Type._UINib,
body: "return UINib(resource: R.nib.\(sanitizedSwiftName(nib.name)))"
)
}

private static func nibVarForNib(nib: Nib) -> Let {
let nibStructName = sanitizedSwiftName("_\(nib.name)")
let structType = Type(module: .Host, name: "_R.nib.\(nibStructName)")
Expand Down
29 changes: 28 additions & 1 deletion R.swift/Generators/ResourceFileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,34 @@ struct ResourceFileGenerator: Generator {
let pathExtensionOrNilString = $0.pathExtension.map { "\"\($0)\"" } ?? "nil"
return Let(isStatic: true, name: $0.fullname, type: nil, value: "FileResource(bundle: _R.hostingBundle, name: \"\($0.filename)\", pathExtension: \(pathExtensionOrNilString))")
},
functions: [],
functions: groupedResourceFiles
.uniques
.flatMap {
[
Function(
isStatic: true,
name: $0.fullname,
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void)
],
doesThrow: false,
returnType: Type._NSURL.asOptional(),
body: "return R.file.\(sanitizedSwiftName($0.fullname)).bundle?.URLForResource(R.file.\(sanitizedSwiftName($0.fullname)))"
),
Function(
isStatic: true,
name: $0.fullname,
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void)
],
doesThrow: false,
returnType: Type._String.asOptional(),
body: "return R.file.\(sanitizedSwiftName($0.fullname)).bundle?.pathForResource(R.file.\(sanitizedSwiftName($0.fullname)))"
)
]
},
structs: []
)
}
Expand Down
14 changes: 13 additions & 1 deletion R.swift/Generators/StoryboardGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ struct StoryboardGenerator: Generator {
properties: storyboardStructs.map {
Let(isStatic: true, name: $0.type.name, type: nil, value: "_R.storyboard.\($0.type.name)()")
},
functions: [],
functions: storyboardStructs.map {
Function(
isStatic: true,
name: $0.type.name,
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void)
],
doesThrow: false,
returnType: Type._UIStoryboard,
body: "return UIStoryboard(resource: R.storyboard.\($0.type.name))"
)
},
structs: []
)

Expand Down

0 comments on commit 296509b

Please sign in to comment.