Skip to content

Multiple paths#213

Merged
djbe merged 4 commits intoSwiftGen:masterfrom
djbe:feature/multiple-paths
Dec 12, 2016
Merged

Multiple paths#213
djbe merged 4 commits intoSwiftGen:masterfrom
djbe:feature/multiple-paths

Conversation

@djbe
Copy link
Copy Markdown
Member

@djbe djbe commented Nov 26, 2016

Covers issues:

Aditionaly relates to:

I've now hit a wall in the easy implementation bit:

  • Fonts just adds entries to one big structure, no need to split up by path.
  • Same for storyboards, especially because value collisions of scene identifiers (and storyboard names) are not allowed (they generate errors/warnings).
  • Images (asset catalog) could be done easily. Image(named: "...") does not care in which catalog something is, and name collisions (I assume) generate warnings. But it might be interesting for the user to know which catalog he/she is accessing. We could just add another folder level, but this would depend on Images: dot syntax #206). We'd only add an extra level if there are multiple catalogs.
  • Colors could be namespaced or not, depends on what might be preferred. Same situation as with Images, because I could have 2 files with the color "orange" but they might actually have different values. Postponed to later PR
  • Strings need to be namespaced, namely we'd need to use the correct tableName (see Support other names than Localizable.strings as input (tableName parameter) #39 and Allow swiftgen strings to use a directory as input #32). Postponed to later PR

We could just leave some of these open for later, especially the strings one because it first needs more work to support tableNames.

@AliSoftware
Copy link
Copy Markdown
Collaborator

You're on fire! 👍
I'll take a look in the afternoon, thanks again!

Podfile Outdated

target 'swiftgen' do
pod 'Commander', '~> 0.5.0'
pod 'Commander', :git => 'https://github.com/kylef/Commander.git'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.6.0 is out 🎉

Option<String>("segueEnumName", "StoryboardSegue", flag: "g",
description: "The name of the enum to generate for Segues"),
Options<String>("import", [], count: 0,
VariadicOption<String>("import", [],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I guess that means that #175 wasn't actually working as described in the CHANGELOG entry until now… (« Multiple imports can be added by repeating this flag. ») and that actually fixes it then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can imagine how I felt when I tried the release 😱

I'd completely misinterpreted the purpose of Options<> which needs a count for the number of arguments it should expect. This fixes that issue 😅

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I know that @plivesey had the same misunderstanding of this Options<…>(count: ) stuff in Commander (and so did I when we talked about it)… not very intuitive ^^

@AliSoftware
Copy link
Copy Markdown
Collaborator

My thoughts on your questions in your original comment:

Images

We'd only add an extra level if there are multiple catalogs.

Seems good to me. But be sure to make it as a separate key in the StencilContext, so that people would have the chose to separate it or not in their own templates.

That logic of adding an extra level should be done at the template level imho, with the StencilContext probably having a root key assetCatalogs containing an array of Dictionaries ((name, assets) pairs), one for each Asset Catalog with their name and content. And then the template would iterate over them; using the assetCatalogs[i].name or not in the template being up to the template itself, and using it only if assetCatalogs.count > 1 seems a good idea for the bundled templates.
(You might need to add an extra hasMultipleCatalogs: Bool root key to the StencilContext as I think it's not possible in Stencil to compare values using > 1 just yet?)

Colors

Colors being generated by a file entirely written manually (as opposed to other commands relying on parsing directories and Xcode/IB files), I'm not sure a lot of people have multiple colours input files 🤔

But since we'd probably already have the logic for the Images, it's probably worth doing the same logic for Colors indeed.

Strings

As you said, name spacing Strings is probably worth being in its own separate PR to handle tableNames.

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 28, 2016

  • Images: agreed. I'd let it depend on Images: dot syntax #206 as it already has all the structure stuff, just add an extra enum case.
  • Colors: that's what I though, but it has a bit more implications as right now, a color parser is a specific subclass for a specific file type. I'd need to create a more general color parser type, that internally creates the correct parsers for each file type.
  • Strings: later.

@djbe djbe added this to the Next minor (4.1.0) milestone Nov 28, 2016
@AliSoftware
Copy link
Copy Markdown
Collaborator

Another thing that would be nice to add in this PR would be to generate an error in case the path(s) given to swiftgen images isn't an .xcassets directory. That way, people that used to do swiftgen images $(PROJECT_DIR) would now have an explicit error message rather than ending with #207

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 29, 2016

I'd actually put that in a separate PR, coming up!

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 29, 2016

Tried a rebase this time. Also tried it with #206 but that just gave me headaches 😐

@AliSoftware
Copy link
Copy Markdown
Collaborator

Is this really done and ready to merge now? (I mean, for what I've reviewed in GitHub it seems OK to me, but given that the original comment of this PR still has unchecked boxes I don't want to merge on your behalf if you planned to add more to this PR or will do them in separate PRs.

But if you're good, I'll let you the pleasure of hitting the Merge button 👍

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 29, 2016 via email

@AliSoftware
Copy link
Copy Markdown
Collaborator

AliSoftware commented Nov 29, 2016

Ok. I just added the WIP label to mark it as unfinished, feel free to remove once ready 👍

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Dec 7, 2016

Right, so images was a bit more annoying than expected.

Both images and strings dot-syntax should be rewritten with some sort of recursion using the set tag. I've noticed that the modified context is stack dependent, so if you set a variable inside an if block, it won't be visible outside of that block. Which is good news for recursion.

The current templates contains code that depends on unreleased Stencil code (stencilproject/Stencil#77), but compiles without issues for now. Multiple catalogs' entries will for now appear under one enum. Once we have the new Stencil, we can expect it to automatically work, and will just need an updated output file.

@AliSoftware
Copy link
Copy Markdown
Collaborator

Does that mean that we should wait for the new version of Stencil containing stencilproject/Stencil#77 to be out to release a version of SwiftGen with this #213 PR? As otherwise we would do breaking changes twice (one with the images template containing the extra level even if there's only one assets catalog, then later the one removing it)?

@kylef
Copy link
Copy Markdown
Collaborator

kylef commented Dec 7, 2016

I'm happy to make a Stencil 0.8 (or maybe 1.0-rc.1 🤔) release soon to support this if needed.

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Dec 7, 2016

Yeah, I suggest waiting until we can merge a PR supporting the latest Stencil.

@AliSoftware
Copy link
Copy Markdown
Collaborator

👍

@djbe djbe merged commit 2d6cb0e into SwiftGen:master Dec 12, 2016
@djbe djbe deleted the feature/multiple-paths branch December 12, 2016 15:33
This was referenced Dec 12, 2016
djbe added a commit that referenced this pull request Jan 3, 2017
Add missing entry for multiple paths PR #213
@djbe djbe mentioned this pull request Jan 3, 2017
AliSoftware pushed a commit that referenced this pull request Jan 3, 2017
Add missing entry for multiple paths PR #213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants