leonidas / transparency

Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
http://leonidas.github.com/transparency/
MIT License
969 stars 112 forks source link

Documentation: Better Examples of HTML usages via directives #88

Closed cybercussion closed 11 years ago

cybercussion commented 11 years ago

Hi, More feedback, but a request better documentation - I've been high and low trying to figure out how to use a directive to allow html text to render in to its location. I see coffeescript examples that don't fully explain whats happening (least to someone unfamiliar with the syntax), and even the one on the main page that is there just renders <p>text<p> which I wouldn't think would be desire-able as a output. The tickets on the issue list several examples and a ongoing conversation about it but I couldn't find anything in the Wiki about doing anything more advanced with the safeHTML functionality or if thats really even a method.

Gracias

cybercussion commented 11 years ago

Ok, think I figured it out after evaluating the code directly.

     directives: {
                title: {
                    html: function() {
                        return this.title;
                    }
                }
            }

If there is a more optimal way to do it let me know.

Thanks

pyykkis commented 11 years ago

Hi, that's the correct way. Here's a fiddle I just made, with a bit more elaborate example: http://jsfiddle.net/akwYH/

I'm also planning to implement a feature which would simplify directives a bit, e.g., the example you gave above could be written as

directives = {
  title: { html: '.title' }
}

Would that make directives easier to use from your point of view?

Please let me know, in case you have ideas how the documentation could be improved - or edit the wiki directly.

cybercussion commented 11 years ago

Hi, That would make it click better without the function return. Not a huge issue really, I just found my self going thru a few past issues and got myself confused at a certain point. The example on the page - http://leonidas.github.com/transparency/ would of had me down the road with the html directive added. But I do get you were showing off a plain text transaction.

hello =
  hello: "Hello!"
  hi:    "<i>Hi there!</i>"
  span:  "Goodbye!"

$('.container').render hello

Thanks for the prompt response. I think just spelling out this use case under the user manual portion of the wiki or tweaking another example on the web page for the project would of solved it for me.