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
support for custom interpolation tags #115
Conversation
@anthonyshort @visionmedia could someone take a look at this? |
whats the use case for and then, i'm not a fan of unnecessary abbreviations, i'd probably prefer an api like: reactive.interpolate('{', '}'); |
Definitely feeling an api that accepts reactive.interpolate('{', '}');
reactive.interpolate(/\{{ ([^}]+)\ }}/g);
reactive.interpolate(function(str) {
// crazy custom interpolation function here
}) |
problem with the second two is that |
and by |
For regex it could use Really though just specifying a begin/end tag would cover most cases imho, I can't imagine needing anything more complex unless you needed some escape rules or something |
I would like to omit the support of an interpolation support if this is okay? |
This should do the trick function removeGlobal(regexp) {
var flags = regexp.ignoreCase ? "i" : ""
if (regexp.multiline) flags += "m"
return new RegExp(regexp.source, flags) I'm on my phone though so ymmv |
This actually should be handled by I tested the regex in the console and found out that it always changes from true to false (at least in the chrome console). Don’t know why. Am 11.12.2013 um 15:33 schrieb Chris Tarquini notifications@github.com:
|
Unfortunately |
I think keeping it simple to |
@visionmedia should I update the pull request to use something like |
I'd imagine you'd have to count the open/close braces and only create a substring when the count is equal |
@visionmedia Would something like this work? |
yeah you have to iterate and pair them up |
oh shit this looks a bit too mind fucking for me. Would it be an options to merge the current strategy and may be later update it to the proper way? Am 12.12.2013 um 18:48 schrieb TJ Holowaychuk notifications@github.com:
|
Don't be thrown off by that mess I posted, it's not so bad haha. The logic is basically increment on an open brace, decrement on a closed brace and save the stuff in between braces Result: {foo({bar: true})} other stuff
^ ^ ^ ^
1 2 1 0
^ ^ ^
A B C A. Since the count is 1 and this is an open brace - Save the index of the next character (f), anything before this character should be saved as non-interpolated text ( Once you're done with all the braces, save I can just try and integrate this with your pull request when I get home though unless you want to take a whack at it |
Okay makes sense :) I could give it another try tomorrow if you want. Today is already a bit late ... Am 14.12.2013 um 16:21 schrieb Chris Tarquini notifications@github.com:
|
@ilsken sry but I failed with implementing the new algorithm into reactive (sitting on this nearly 2h till now...) so except you want to take a look and fix it I would give up and close? |
I submitted a pull request on your fork. All the tests are passing so you can just look it over and merge it |
I hope it did not took to much time on your side! Thank you. |
@visionmedia ready for merge? |
Could we maybe get some cleanup in the commits so they can be reviewed better? There is a lot of commits which could really by squashed here. |
moved interpolation regex and char to lib/adapter.js added public methods to index.js which allow updating the interpolation adapter added test for custom interpolation tag adapter updated Readme.md with interpolation adapter updated custom interpolation api (hasInterpolation not safe!) applied not working workaround for hasInterpolation fixed hasInterpolation with one single regex added support for flags in interpolation regex
@defunctzombie I hope I have done this right. If you want I also can wipe out the first commit which includes the "old" custom interpolation way from me. |
@bodokaiser much much better :) I think that your two commits could be reverse tho. You could migrate to the updated interpolation algorithm, and then apply the feature/api to support custom tags. Will make your commits even cleaner since adding support for custom tags introduces code which you then delete in the algorithm commit. |
You mean this on
|
@bodokaiser was just an observation about the code changes between the two commits. To me it seems that your "updated algo" commit is logically the first one to make since it makes your custom tags commit simpler. Not sure what sequence of git magic needs to happen to reverse them (maybe some manual editing). In either case, I would wait to see what others say about these changes cause they may have different feedback. I am but just one voice :) |
I personally would leave the order as the "update algorithm" commit improves the first one. Though it still may be better for the master commit history. |
@ilsken could you review? |
@ilsken @defunctzombie @ianstormtaylor sorry for being so pushy but I would really like to use this feature :) |
Changed `interpolation.regex` to be compatiable with new interpolation algorithm Fixed custom interpolation methods and tests Added support for variable-length interpolation delimters removed parser.js escaping interpolation characters for regex
@bodokaiser Looks good to me but I'm just a user of reactive so getting it merged is up to everyone else haha. I agree though it's a pretty nice feature to have |
@anthonyshort @ianstormtaylor I am willing to step up maintain this more actively if there is interest. I currently maintain my own fork with things like iteration, separate adapters, and various other little fixes/tests. Would really like to contribute that back to the project :) |
always +1 for reviving a project :) Am 11.01.2014 um 15:47 schrieb Roman Shtylman notifications@github.com:
|
@defunctzombie I'd be very interested. I'm still itching to use reactive in production. Can you enable issues on it? I have some ideas I'd like to bounce off you |
@defunctzombie added to the org! |
You should give him npm rights to all the repos so he doesn't have to ping you anymore :) |
fuck npm |
we should just have a communal user haha, way easier |
But then you have to keep switching users :/ unless we all literally publish everything under one account. I'd be down for that. |
it's a shame you need that to not deal with crazy issues haha :s |
Closing since the codebase is changing a bit for reactive 1.0 ( |
Hello,
I wanted to use swig templates on for server side rendering and reactive on the client. A problem I had was that reactive does not allow setting own interpolation tags so I needed duplicates.
Example:
In this pull request I added support for setting a custom regex and character for interpolation (similar to the set, get, .. adapters). There is also a test which covers this specific use case. I guess you may want to change the public api (names).
Best,
Bo