TVMLKitchen icon indicating copy to clipboard operation
TVMLKitchen copied to clipboard

Missing Product Recipe

Open steve228uk opened this issue 8 years ago • 8 comments

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 avatar Mar 14 '16 01:03 steve228uk

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

steve228uk avatar Mar 14 '16 01:03 steve228uk

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 .

toshi0383 avatar Mar 14 '16 02:03 toshi0383

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

steve228uk avatar Mar 14 '16 02:03 steve228uk

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?

toshi0383 avatar Jan 10 '17 04:01 toshi0383

@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.

steve228uk avatar Jan 10 '17 10:01 steve228uk

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?

toshi0383 avatar Jan 10 '17 12:01 toshi0383

@toshi0383 I'd say that makes sense 👍

steve228uk avatar Jan 10 '17 14:01 steve228uk

@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. 👍

Wei-Xia avatar Jan 10 '17 18:01 Wei-Xia