-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options clobber Data? ( should be separate ) #29
Comments
That is a good point. thanks for bringing this up. On May 7, 2012, at 3:18 PM, Nick Perkins wrote:
|
I would like to try to fix this. I am having trouble running the tests, though. Is there any documentation on exactly how to run the tests, and what modules are required? ( ie "mocha", "should",etc ? ) |
Ok, never mind...figured it out...."cake build", "cake test"...i get it... |
|
@nickperkinslondon it's always a good idea to look in the package.json |
FYI the test_optimized.coffee is irrelevant. |
I don't think this issue can be fixed in a completely backwards-compatible way. I have tried a fix ( keep options separate from data), but there is a problem... For example, in the existing tests...the Stylus test does this: Do you see?...options are being passed as the "data" parameter. I think we must either fix it once and for all ( breaking some existing code ), or don't fix it, in which case strange things will continue happen to anyone who has a data attribute name the same as an Option name, and adding new Options in the future will be, well, impossible without breaking somebody's code. If this is not fixed, then we are left with a certain set of "reserved" words that must not be used as data attributes. |
I have thought about these issues. that's why I wanted to see your ideas. On May 12, 2012, at 11:47 AM, Nick Perkins wrote:
|
I think I have the basis of a solution, which converts all options into hard-code during the compile phase. |
There is also a problem with "locals": On the whole, I have become quite concerned about the whole "baking process", where the function is serialized, munged, and re-compiled, all in the interest of magically injecting all the tag names as local variables. It is a huge hack that was done to make the template syntax absolutely minimal. The down-side, as you all know, is that you lose closures, etc, and it makes error reporting difficult. I decided to do some experimenting, and see how far I could go with creating a similar project that does not use the "magic" injection of html tags. Instead, what if the html tags were passed to the template function as the "this" parameter? ( instead of the "data" being "this" ) On the downside, you would have to write "@H1" instead of just "h1", but on the plus-side...there is no magic. Your template is just a function, and it does not have to be stringified and re-compiled. The data can now be the parameters to the template function, which means you can have as many "data objects" as you want, and you can give them descriptive names. If you want to pass-in special helper functions or whatever, you can simply pass them in the same way as the data. If you want to provide common helpers, you just put onto the "this" object, along with all of the html tag functions. I have up-loaded my code to a new project called "coffee-mug" So... |
@nickperkinslondon I must say I really like the approach CoffeeMugg has taken... It makes me less reticent about using it on the client side (speed). I don't mind the extra @, in fact I rather like that it marks the method as special. This approach also allows changing the |
coffeecup.render = (template, data = {}, options = {}) ->
data[k] = v for k, v of options
data.cache ?= off
data.stylus = require 'stylus'
These first 3 lines of "render" start brutally clobbering the "data" object by injecting the options right into the data!
This means you can never use data attributes named any of the following:
"hardcode"
"optimize"
"locals"
"cache"
"stylus"
Options should be kept separate from Data, so that there are no secret "forbidden" attribute names!
The text was updated successfully, but these errors were encountered: