Skip to content
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

Does TyphoonConfig work with plist/json? #241

Closed
ghost opened this issue Aug 14, 2014 · 14 comments
Closed

Does TyphoonConfig work with plist/json? #241

ghost opened this issue Aug 14, 2014 · 14 comments

Comments

@ghost
Copy link

ghost commented Aug 14, 2014

Hi,

I'm using v2.1 and I've only ever been able to get TyphoonConfig to work using .properties files. I got curious after trying to get .plist to work again and started walking through the [TyphoonDefinition configDefinitionWithResources] method. From what I could tell, the method flow ends up in [TyphoonConfigPostProcessor configurerWithResourceList] which seems to specify to always use the "properties" style configuration. It seems like I must be getting this wrong, because the docs specifically mention json/plist. Any help would be appreciated. Thanks.

@jasperblues
Copy link
Member

@alexgarbarev Can you please take care of this one.

Let's make plist the default in the docs.

@alexgarbarev
Copy link
Contributor

Hi @johntvolk-novu, thank you for feedback.
The problem happens because you using old and deprecated method which supports only .properties config file.

To use json/plist config files use one of these methods:

/** Append resource found in main bundle by name */
- (void)useResourceWithName:(NSString *)name;

/** Append resource loaded from file at path */
- (void)useResourceAtPath:(NSString *)path;

/** Append TyphoonResource with specified extension (@see availableExtensions method) */
- (void)useResource:(id<TyphoonResource>)resource withExtension:(NSString *)typeExtension;

@jasperblues
Copy link
Member

Sounds like it is time to delete the old method.

@ghost
Copy link
Author

ghost commented Aug 15, 2014

Thanks, Alex/Jasper!

@ghost
Copy link
Author

ghost commented Aug 15, 2014

Is there a way to do this at build-time using TyphoonDefinition (rather than runtime using TyphoonConfigPostProcessor)?

edit:

I was able to get this working by "manually" building a TyphoonDefinition with TyphoonConfigPostProcessor as the defined class:

[TyphoonDefinition withClass:[TyphoonConfigPostProcessor class] ...

I guess I should be asking if there's a simpler way to do this at build-time.

Thanks.

@alexgarbarev
Copy link
Contributor

@johntvolk-novu No, currently we have not shorthands for that. Only way is creation definition manually.
But I think TyphoonConfigPostProcessor creation is not often, so better to have more compact API. Anyone can create category for that if he doing something often.

@jasperblues
Copy link
Member

I believe @johntvolk-novu was referring to _'to attach a properties file at build-time'_ from here:

https://github.com/typhoon-framework/Typhoon/wiki/What%20can%20be%20Injected#create-a-properties-file-with-the-values-as-follows

. . . which for example if you're using plist bootstrapping, allows you to set up all of Typhoon, including your normal runtime config in the assembly.

@dereekb
Copy link

dereekb commented Aug 31, 2014

I ran into this issue tonight too after putting together a plist containing some dictionaries.

So you're recommending just defining those dictionaries as definitions in the assemblies, or is there a way to declare the TyphoonConfigPostProcessor and pass the resource to it using TyphoonDefinition? @johntvolk-novu mentions manually building it, but I'm unsure of how he did that.

@alexgarbarev
Copy link
Contributor

Hi @dereekb
Just add definition into your assembly like this:

// This definition will be automatically catched by Typhoon
- (TyphoonConfigPostProcessor *)configPostProcessor
{
    return [TyphoonDefinition withClass:[TyphoonConfigPostProcessor class] configuration:^(TyphoonDefinition *definition) {
        [definition injectMethod:@selector(useResourceWithName:) parameters:^(TyphoonMethod *initializer) {
            [initializer injectParameterWith:@"you_config_file.plist"];
        }];
    }];
}

@dereekb
Copy link

dereekb commented Aug 31, 2014

Thanks! I'm still working through learning Typhoon and misunderstood what the injectMethod: method actually did.

@jasperblues
Copy link
Member

The documentation still refers to a short-hand approach that only works with .properties style:

- (id)config
{
    return [TyphoonDefinition configDefinitionWithResource:
        [TyphoonBundleResource withName:@"Configuration.properties"]];
}

Today I'll delete these deprecated methods, and add back a shorthand that:

  • Works with all styles {plist, json, properties}
  • Allows specifying a list of config files.

@alexgarbarev
Copy link
Contributor

I removed old methods and replace with new which doesn't use deprecated methods. TODO: update docs and close this ticket

@jasperblues
Copy link
Member

I will update docs + sample application over the weekend.

@jasperblues
Copy link
Member

Docs updated.

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

No branches or pull requests

3 participants