groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

Retrieving NSAttributedString objects instead of NSString objects. #60

Closed oleksii-demedetskyi closed 9 years ago

oleksii-demedetskyi commented 11 years ago

As soon as lib allow user apply uppercase() filter, why not allow bold() filter or something with string atttributes. Or there is some way to retrieve range of replaced values, and apply dictionary by hands, outside of the lib?

groue commented 11 years ago

Hi DAloG, that's quite a valid request, thanks.

I can't think of any way to achieve it, right now: there is no NSAttributedString support, and no way to extract ranges of rendered values, as you suggest.

Right now, you can look at https://github.com/johnezang/NSAttributedString-Additions-for-HTML and https://github.com/Cocoanetics/DTCoreText: you could render HTML with Mustache, and use those libraries to build attributed strings.

What do you think?

oleksii-demedetskyi commented 11 years ago

Hi @groue, i tried to look at custom render objects. I hope i can extract previous rendered string to catch start location of result string. Inside custom rendering objects i can edit an instance of NSMutableDictionary to store all ranges with appropriate attributes. What do you think about this approach?

groue commented 11 years ago

Custom rendering objects don't know when and where they are rendered, and there is no callback for the rendering of template filling text. For instance, when rendering prefix{{ tag }}, there is no API any object attached to tag could use to know the length of the prefix. I don't see how you could implement your ideas with the current API.

Hmmm...

groue commented 10 years ago

Do you know NSHTMLTextDocumentType? It may help: you first have GRMustache produce HTML, and another tool (here, a system one), turns this HTML into an attributed string.

groue commented 9 years ago

Let's close this issue. Mustache is a raw-text-processing tool, after all.