Skip to content
This repository has been archived by the owner on Oct 13, 2018. It is now read-only.

Missing Product Recipe #27

Open
steve228uk opened this issue Mar 14, 2016 · 8 comments
Open

Missing Product Recipe #27

steve228uk opened this issue Mar 14, 2016 · 8 comments

Comments

@steve228uk
Copy link
Collaborator

Howdy!

I've been working on some recipes for the Product and Descriptive Alert templates. Once completed, did you want me to submit a PR?

I'm also not sure of the best approach in handling actions. Is there a way for a recipe to intercept these or is it one global handler for the application? Currently I'm using the following:

func actionIDHandler(id: String) {
   switch id {
   case "showDescription":
       DescriptionRecipe.show(selectedMovie)
       break
   default:
       break
   }
}

My approach in generating the XML is slightly different to yours too and I'd appreciate your opinion on whether this is a good idea or not. I have an XML file called product.xml that has placeholders such as {{TITLE}} and {{DESCRIPTION}}. These are then replaced to generate the final template with the following:

public var template: String {
    var xml = ""
    if let url = NSBundle.mainBundle().URLForResource("product", withExtension: "xml") {
        xml = try! String(contentsOfURL: url)
        xml = xml.stringByReplacingOccurrencesOfString("{{DIRECTOR}}", withString: director)
        xml = xml.stringByReplacingOccurrencesOfString("{{TITLE}}", withString: title)
        xml = xml.stringByReplacingOccurrencesOfString("{{ACTORS}}", withString: actorString)
        xml = xml.stringByReplacingOccurrencesOfString("{{DESCRIPTION}}", withString: description)
        xml = xml.stringByReplacingOccurrencesOfString("{{IMAGE}}", withString: image)
        xml = xml.stringByReplacingOccurrencesOfString("{{YEAR}}", withString: year)
    }
    return xml
}

simulator screen shot 14 mar 2016 00 51 09
simulator screen shot 14 mar 2016 00 51 03

@steve228uk
Copy link
Collaborator Author

I just read through your slide deck and noticed you mentioned Stencil so perhaps the {{NAME}} method wouldn't be your ideal solution.

@toshi0383
Copy link
Owner

Hi, thanks! PR is totally welcomed. I will take a look and merge it ! 👍
Your xml replacing approach just look great. It would be fine as long as it works.

actionIDHandler is currently globally shared. I added description about actionIDHandler in #28 .

@steve228uk
Copy link
Collaborator Author

@toshi0383 Awesome 😊 Yeah it looked like the handlers were global when I was digging through the JS and Bridge.

@toshi0383
Copy link
Owner

For the Product template, I think we should leave the UI customization to the user, rather than embedding it as Recipe.

@steve228uk How do you think?

@steve228uk
Copy link
Collaborator Author

@toshi0383 I think I agree with you but providing an official approach for placeholders might be a good idea. Whether that's using stencil or something similar.

@toshi0383
Copy link
Owner

I think I need to describe more.

Lately I tend to think that Recipe feature should be separated into a different module since users can pass arbitrary xml to Kitchen.serve(xmlString:...) anyways.
Users can then use Stencil or whatever tool they prefer, to generate xml, and pass it to TVMLKitchen.

So IMO, we should not embed the Recipe in TVMLKitchen unless

  • It's so simple that users would reuse that template just as is. (e.g. Alert or Loading, but not Catalog)
  • We have to provide it to handle text input. (e.g. Search or TextField(which we don't support yet.))

So I think I'm going to remove the CatalogRecipe from built-in Recipes and move it to demo app.
I'm thinking about removing RecipeTheme feature, too.

@steve228uk @Wei-Xia
Any thoughts on this?

By the way, about the "official" template formatting, currently by conforming to the TemplateRecipeType, we can define a Recipe like this.
I actually haven't tried Stencil yet, so I don't know how much better API we can provide for Recipe implementation. I don't think there is much big difference, is there?

@steve228uk
Copy link
Collaborator Author

@toshi0383 I'd say that makes sense 👍

@Wei-Xia
Copy link

Wei-Xia commented Jan 10, 2017

@toshi0383 I'm thinking we could provide more templates like Apple has in their website if we have more time to work on this.

I agree with steve to provide an official approach with placeholders for users. They can simply fill with more content to use this library. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants