-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splitting of Filters+Strings #63
Conversation
/// | ||
/// - Parameter string: The string to titleCase | ||
/// - Returns: The string with its first character uppercased, and the rest of the string unchanged. | ||
private static func titlecase(_ string: String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to upperFirstLetter
, titlecase
is the old name for this filter/function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why that titlecase
name came back up here, did you copy/paste the code from before the last commits which changed that name when you started working on that split? Or did we miss something when doing our latest merges and let that slip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware when I cloned the repo today the initial state was 49af697
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware I think you messed up something as we're still using titlecase
😄
But we maybe can remove it and use only upperFirstLetter
as @djbe commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In c4686c3 it's removed, but I had to create a function upperFirstLetter
that doesn't throw and takes String
parameter to be able to use in:
let comps = string.components(separatedBy: "_")
unprefixed = comps.map { upperFirstLetter($0) }.joined(separator: "")
/// - string: the value to be processed | ||
/// - stripLeading: if false, will preserve leading underscores | ||
/// - Returns: the camel case string | ||
static func snakeToCamelCase(_ string: String, stripLeading: Bool) throws -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be moved to private, except that swiftIdentifier depends on it.
Should we have a clearer separation between the Stencil filter functions (that accept and return Any), and the actual filter methods (that accept and return String + typed arguments)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe internal real functions should be separate to functions having a Filter signature and being used in registerFilter
… but then where should we put that static func snakeToCamelCase
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the:
Should we have a clearer separation between the Stencil filter functions (that accept and return Any), and the actual filter methods (that accept and return String + typed arguments)?
I wanna ask if it makes sense for you to validate input
not for string, but for string convertable. That would actually be a benefit for Sourcery and simplify the template writing 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antondomashnev so this then?
guard let value = value as? CustomStringConvertible else {...}
let string = value.description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea to me, we don't care what the data is as long as we can safely convert it to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djbe exactly.
Cool, I guess it worth another PR, as to not mess up things 😄
While we're at it, maybe check on codebeat if there are other changes we might want to apply: |
Pods/Pods.xcodeproj/project.pbxproj
Outdated
@@ -385,7 +387,9 @@ | |||
2E92B989035E25169DF9300616F23AAB /* Environment.swift */, | |||
0C6D246B203676EC17FA9473D97CB418 /* Filters.swift */, | |||
02B0A9A1128124B1A17D5AB1E23A0A45 /* Filters+Numbers.swift */, | |||
47DB41142F62E8B5174F3DF281DCD5E3 /* Filters+Strings.swift */, | |||
6D1EF02F1F49EC7C00EA91EF /* Filters+Strings+Lettercase.swift */, | |||
6D1EF02B1F49E85D00EA91EF /* Filters+Strings+Mutations.swift */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those short UUIDs intrigue me… is this a new thing in Xcode 9, shorter UUIDs for file references in Xcodeprojs? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happens when you add the files manually to the pods project. When you run pod install
you get the longer UUIDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @djbe didn't know it. @AliSoftware I used Xcode 8.x but added the, manually.
import Stencil | ||
|
||
extension Filters { | ||
enum Strings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh. There's no particular reason why the enum
would be declared in +Boolean
and extension
be used in the other files… But is it worth having a Filters+Strings.swift
which would only declare an empty enum Strings{}
just so all Filters+Strings+Whatever.swift
subsequent file are consistent and all use extension Filters.Strings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, I think it may be clearer for developer, that there is a "base" file.
/// - string: the value to be processed | ||
/// - stripLeading: if false, will preserve leading underscores | ||
/// - Returns: the camel case string | ||
static func snakeToCamelCase(_ string: String, stripLeading: Bool) throws -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe internal real functions should be separate to functions having a Filter signature and being used in registerFilter
… but then where should we put that static func snakeToCamelCase
method?
/// | ||
/// - Parameter string: The string to titleCase | ||
/// - Returns: The string with its first character uppercased, and the rest of the string unchanged. | ||
private static func titlecase(_ string: String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why that titlecase
name came back up here, did you copy/paste the code from before the last commits which changed that name when you started working on that split? Or did we miss something when doing our latest merges and let that slip?
@Antondomashnev you might want to (1) rebase your branch on top of Otherwise I'm ok with the names (or rather I can't think of anything better at the moment :-p), thanks for the PR :) |
I think the code is based on almost the most recent code. |
15ebab8
to
c4686c3
Compare
@AliSoftware @djbe the build is failing because the file The simplest way to fix it would be to keep the decalaration of |
I'm not sure I understand how, in the case where the |
@Antondomashnev Is it because you added the files to the pods project manually? Order really shouldn't matter. Try running |
@AliSoftware I don't understand as well. But as I wrote in the comment above:
|
@djbe tried it, didn't help. Also tried to remove references for these files, add them again and
@djbe you can see that |
@djbe @AliSoftware order definitely doesn't matter, but SPM still fails 😄 |
Does SPM uses -WMO? Or if not any way to enable it? I wonder if that would make a difference, forcing to compile it as a whole… |
@AliSoftware do you mean whole module optimisation? |
Yup |
@AliSoftware seems it does use it in release build and
|
Yeah, I've made it working. So it seems for the SPM the file names are still matter and I think it's somehow sorted so the |
Ok, that's cool… but it's still worth a JIRA in bugs.swift.org to me though, as I think that shouldn't be the case 😉 |
@AliSoftware very valid point, create one. Btw I still can not merge the PRs, maybe |
Yup, only the CoreTeam have right to merge into master 😉 |
This resolves the #58, naming selection was pretty difficult, but so far it looks ok to me. @AliSoftware @djbe if you have better names - I'd be happy to change it 😄