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

In-place directive manipulation support #46

Closed miohtama closed 12 years ago

miohtama commented 12 years ago

Add support for cases where directive handler uses jQuery to directly manipulate DOM in-place, instead of returning text or HTML snippet.

In complex manipulation cases this may be

The change itself is that if directive function returns null then don't try to run text or html replacement on this null value.

pyykkis commented 12 years ago

How about just

directives =
  person: (elem, i) ->
    elem = jQuery elem
    elem.attr "foobar", "foo"
    elem.text "daa"
    {}

I didn't test it, but as far as I see, it should work with current implementation?

Of course, the pull request would make things easier with javascript, as one could omit the last line.

miohtama commented 12 years ago

Thinking outside CoffeeScript box:

... so this is much more useful in JS side of the things and users do not return magical {}.

It is mostly what "users would think how API behaves" and thus will save lots of people from gotcha.

pyykkis commented 12 years ago

Fair enough, I'll merge to master :)

Before that, a bit of cleanup is needed. The pull request contains implementation also for the object-like directives, which is a separate topic.

miohtama commented 12 years ago

Looks like Github pull requests somehow picksk up the latest commits even if they are not on available on the moment I made the pull requests. Github > me :(

Probably the correct use is to make only one pull request per branch?

pyykkis commented 12 years ago

Yes, that's correct. Easiest way is to make a pull request is from a dedicated feature branch (which is kept up-to-date with upstream/master).

http://help.github.com/send-pull-requests/

miohtama commented 12 years ago

Used git create branch from commit and then re-created pull request to get correct commit range:

http://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git

Apparently Github pulls always the whole branch in the request and you cannot set commit range (even though it says commit range in the Github user interface). Please see the new pull request, closing this one.