Skip to content

Switch the asset catalog parser to using "actool" to parse its contents#199

Merged
djbe merged 15 commits intoSwiftGen:masterfrom
djbe:feature/images-actool
Nov 16, 2016
Merged

Switch the asset catalog parser to using "actool" to parse its contents#199
djbe merged 15 commits intoSwiftGen:masterfrom
djbe:feature/images-actool

Conversation

@djbe
Copy link
Copy Markdown
Member

@djbe djbe commented Nov 13, 2016

This is a first step to eventually implementing the dot-syntax for asset catalogs, mentioned in #52.

The good thing about this is that, without changing the template, it already fixes an issue with the generated code for catalogs with namespaces folders. Currently the generated enum cases only contain the last filename of imagesets (eg. case myImage = "myImage"), but if they are contained in namespaced folders, the case should actually be case namespace1_namespace2_myImage = "namespace1\namespace2\myImage".

This is a preliminary pull request, I still need to add a changelog entry and a bunch of unit tests. But I'd like a quick review of the changed code and your input before continuing.

Copy link
Copy Markdown
Collaborator

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

Looks like a good start, thanks for the PR 👍

let filename = item[AssetCatalog.filename.rawValue] as! NSString

// this is a simple imageset
if filename.pathExtension == AssetsCatalogParser.ImageSet {
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.

SwiftGen has a dependency to PathKit which is a pod providing Swiftier API for manipulating files, file extensions, basenames, etc.
You should switch your code so it uses it (instead of having to convert to NSString and use Foundation) 😉

return children
}

private func executeCommand(command: String, args: [String]) -> NSData {
Copy link
Copy Markdown
Collaborator

@AliSoftware AliSoftware Nov 13, 2016

Choose a reason for hiding this comment

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

Wondering if that couldn't be useful for other subcommands one day so maybe worth moving to some helper?

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.

Sure, where should I put it? A new subfolder in GenumKit called Utils next to Parsers and Stencil?

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.

Good question… yeah sounds about right!

@djbe djbe mentioned this pull request Nov 15, 2016
@djbe djbe added this to the 3.0.2 (or 3.1.0) milestone Nov 15, 2016
Copy link
Copy Markdown
Collaborator

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

We should add unit tests for the use case you claim that this PR solved as a side effect of using actool (I believe you were mentioning namespaces with spaces in their names or something?)

Otherwise seems good (even if I only reviewed from my phone on GitHub)

}

extension AssetsCatalogParser {
static let ImageSet = "imageset"
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'd rename that constant imageSetExtension (_lower_CsmelCase seems to be the rule even for constants in Swift I think)


extension AssetsCatalogParser {
private func loadAssetCatalogContents(path: String) -> [[String: AnyObject]]? {
let command = Command("xcrun", arguments: "actool", "--print-contents", path)
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.

Nitpicking: indentation

@AliSoftware
Copy link
Copy Markdown
Collaborator

Oh sorry I re-read your original comment you were just talking about namespaces in the asset catalog, which you already covered in your additional tests, right?

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 15, 2016

Jup, I've added folders in the current asset catalog, both namespaced and normal ones.

@AliSoftware
Copy link
Copy Markdown
Collaborator

Still missing a CHANGELOG entry though 😜

@djbe
Copy link
Copy Markdown
Member Author

djbe commented Nov 15, 2016

Gah, gimme a second

CHANGELOG.md Outdated
[David Jennes](https://github.com/djbe), [#175](https://github.com/AliSoftware/SwiftGen/pull/175)
* Remove the `key` param label from the `tr` function for Localized String in the swift3 template [AndrewSB](https://github.com/AndrewSB), [#190](https://github.com/AliSoftware/SwiftGen/pull/190)
* The `swiftgen images` command now uses the `actool` utility to parse asset catalogs,
ensuring that the parser correctly handles namespaced folders.
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.

You forgot to add two spaces after the full stop (which will allow the rendered markdown to insert a newline in the same paragraph here)

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 know, I'm pedantic ^^

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.

I thought I copied my previous changelog, seems I didn't, or Xcode is messing with me.

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.

Wait… in fact a lot of those CHANGELOG entry are not correctly formatted 😱

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.

I noticed 😄 I can fix that in one commit if you want?

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 that would be nice 😉👍

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.

There typical expected format is the one used in 3.0.1 section and before.

* Description of the change.••
  [Author Name](GH profile link)
  [#PRNum](link to PR)

With to be replaced by a space, otherwise going on a new, indented line for every link after the description because I have OCD 😂

Copy link
Copy Markdown
Member Author

@djbe djbe left a comment

Choose a reason for hiding this comment

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

herp derp, I'm going to sleep, I'm making a mess of the commit history 😐

Copy link
Copy Markdown
Collaborator

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

Ok, LGTM now 👍

I'll let you guys @djbe @dostrander decide when to the merge (probably after your good night sleep 😜), as you seem to already have started a list of PRs and milestones, but you have my go 👌

@djbe djbe merged commit c8bd21a into SwiftGen:master Nov 16, 2016
@djbe djbe deleted the feature/images-actool branch November 20, 2016 17:57
@djbe djbe mentioned this pull request Nov 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants