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
Feature request: Specify transclusion position #300
Comments
It would be useful to me too. +1 |
I created a plunk to demonstrate the concept (It may require some refresh to work due to plunker): http://embed.plnkr.co/QtPQCMUCsVDwRz1zV2C3/preview |
Cool. What about using Another option, I don't know if you've thought about it, would be to use a function call, which could be overridden in some situations |
I'd like to have a sort of poll about the name. I know transclusion is the correct technical term: but at the end of the day to it sounds really angularish. I would prefer to keep things understandable by everyone than to be absolutely technically correct. It's only my opinion so I accept alternative proposal for the name (alternative to transclusion). For the "{ transclude() }" proposal: maybe it could be an alternative method? I like the tag because you are marking the insertion point inside an html template. But why not both. I'll take a look at that. |
Another poll I have inserted two "compiler directives" here. "replacetag" and "transclude" and I took the opportunity to place them inside the opts object as it's already vehicolating correctly through the objects chain. |
Sorry, I wasn't implying to change the name of the tag to "transclude" just because I thought it the correct term. I just noticed that you had implemented both an option called "transclude" and a tag called "include" to create the one feature. Keeping them both the same would cause less confusion. And again, once you've decided on what to call the tag, the compiler directive's name will become obvious. I know what you mean about "transclusion" sounding a bit "angular-esc", however, it is the perfect term as it describes exactly what's happening. "Include" sounds more like pulling an external source in to the document. So "transclude" would be my vote. As for the object serving this feature, if you're going to be using the behaviour pattern, then "behaviour" is perfect. Otherwise I wouldn't say it would suit. Will it be serving an other features, or just this one? |
This feature in "Ember.js", it provides the |
Actually, yeh. "Yield" also makes sense. |
To such an object should be the way to activate framework features from the tag implementation to the framework. It should be general and work for every tag implementation. |
So that for now we have:
|
I think tag could be the correct term: with transclude <alert>
<div class="alert alert-{category}" role="alert"> {msg} <transclude></div>
opts.tag.transclusion = true, // was transclude
opts.tag.renderRoot = false // was replacetag
this.category = opts.category
this.msg = opts.msg
</alert> with yeld <alert>
<div class="alert alert-{category}" role="alert"> {msg} <yeld></div>
opts.tag.yeld = true, // was transclude
opts.tag.renderRoot = false // was replacetag
this.category = opts.category
this.msg = opts.msg
</alert> |
Remind me what |
|
I was leaning towards "yield" until I saw it in practice. Now I'm back on liking transclude. |
Ok, for now let's stay stick with transclude. If someone will came up with a good name we will update it later.
|
Ah. Cool. |
Ok done with transclusion / transclude. <alert>
<div class="alert alert-{category}" role="alert"> {msg} <transclude></div>
opts.tag.transclusion = true, // was transclude
opts.tag.skipRootNode = true // was replacetag
this.category = opts.category
this.msg = opts.msg
</alert> |
I've had following tag on the repository since the beginning: https://github.com/muut/riotjs/blob/master/test/tag/inner-html.tag It takes the inner html and appends more stuff to it upon "mount". I think you can play more with |
I want to be able to define tags and use them like this: (from twitter bootstrap http://getbootstrap.com/components/#navbar): <navbar>
<left>
<brand src="logo.gif"></brand>
<link href="#" active>text 1</link>
<link href="#" active>text 2</link>
<dropdown>
<menuitem href="#">item 1</menuitem>
<menuitem href="#">item 2</menuitem>
...
</dropdown>
<search></search>
</left>
<right>
<dropdown>
<menuitem href="#">item 1</menuitem>
<menuitem href="#">item 2</menuitem>
...
</dropdown>
</right>
</navbar> I don't want to define a navbar tag that uses these other tags, I want a palette of these tags that I can nest as shown in my page. That is, I want to cobble together some number of navbars with many different options for brand, dropdown present or not, etc. Compare that elegant looking code to the raw HTML: The beauty of such a solution is I can think about the components of the navbar without giving much thought at all to the clumsy HTML elements and styles and ids and so on that need to be generated for the navbar to look as sweet as Bootstrap can make it. |
Totally Agree with that. A sort of Riot-Bootstrap done that way would be wonderful! |
I think this is best solved with a custom tag. Like this for example: <some-tag>
<h1>Hello!</h1>
<inner-html/>
</some-tag> Here's the implementation for <inner-html>
var p = this.parent.root
while (p.firstChild) this.root.appendChild(p.firstChild)
</inner-html> definitely a useful tag. Maybe we'll have a "core tags" library at some point where this would fit perfectly. Thoughts? |
Ah yes, that makes sense. Quite a simple approach. |
In the tag layout for navigation I presented, the inner-tags have On Sat, Feb 14, 2015 at 3:11 AM, Tero Piirainen notifications@github.com
|
I think the custom tag approach does a good job because It still leaves room for custom transclusion logic. But mschwartz does have a good point and I can see how this can get hairy using custom tag logic if there is not an easy way to get at the riot level data and set the parent manually. |
Actually from what I can tell with console logging when using the inner-html custom tag approach is that other nested custom tags look to know their parent before they are moved. |
@mschwartz can you make a minimalistic jsfiddle where I can see this issue? Thanks! |
This only works 1 level deep. Any thoughts on how we can nest this feature? |
With my patch you can use the <my-tag>
<p>Hello <yield/></p>
this.text = 'world'
</my-tag> Usage <my-tag>
<b>{ text }</b>
</my-tag> Result <my-tag>
<p>Hello <b>world</b><p>
</my-tag> |
@johngeorgewright here is one of your jsfiddle using the yield tag http://jsfiddle.net/gianlucaguarini/cf0nqL7m/1/ |
Nice! Been gagging for this feature. |
Great to see it working again. As I said above, I really think the tag content should be parsed in the parent context, as it is in React and others. |
@eyy actually with the |
@GianlucaGuarini but in your comment and fiddle above it is parsed in the child context: http://jsfiddle.net/cf0nqL7m/2/ |
@eyy Could you please provide an example in React or vue please? thanks |
@GianlucaGuarini Sure: Vue, React. |
@eyy awesome I will update the |
@eyy @johngeorgewright here there's the new jsfiddle with the brand new |
👍 |
1 similar comment
+1 |
I have a question. I believe something like the below would be possible if yield was evaluated in the child context, but I'm not sure how to go about it or if it would be possible if it's evaluated in the parent context. How would you guys approach it? <people>
<person data="{person}"></person>
</people> <person>
<div>{person.name} - <strong>{person.phone}</strong></div>
this.person = opts.data;
</person>
<people>
<div each="{person in people}">
<yield/>
</div>
this.people = [{name:"bob",phone:"555-1212"},{name:"john",phone:"555-1213"}];
</people> |
@valan You are right at moment it's not possible I just wrote the documentation https://github.com/muut/riotjs/blob/feature/yield/doc/api/tags.md#html-transclusion-using-the-yield-tag--yield Maybe in future we could think about it |
so I guess the workaround for that would be putting the template in the tag definition rather than in the page, then maybe make a conditional if a different layout is needed <people layout="one"></people> <person>
<div>{person.name} - <strong>{person.phone}</strong></div>
this.person = opts.data;
</person>
<people>
<div if="{layout=='one'}">
layout 1
<div each="{person in people}"><person data="{person}"></person></div>
</div>
<div if="{layout=='two'}">
layout 2
<div each="{person in people}"><person data="{person}"></person></div>
</div>
this.people = [{name:"bob",phone:"555-1212"},{name:"john",phone:"555-1213"}];
this.layout = opts.layout;
</people> |
Now that the
|
Yeah, child context makes way more sense intuitively, at least to me. And you can always access the parent if you need to anyway. |
Well, I'll give one last advocation for parent-context compiling:
I'll finish with my real-world example: I wanted a popup tag, to provide different components with a simple close-button, <pop>
<div class="black-screen hide"></div>
<div class="popup hide">
<a href="#" onclick={ close }>X</a>
<yield />
</div>
<script>
let tags = $('.black-screen, .popup', this.root)
this.close = () => tags.addClass('hide')
this.show = () => tags.removeClass('hide')
</script>
</pop>
<app>
<pop name="won"><h2>You Won! Congrats, { name }</h2></pop>
<button onclick={ tags.won.show }>Roll?</button>
<script>
this.name = 'John'
</script>
</app> If that hasn't convinced, well, it's ok. Maybe if i'll have time i'll mess with the code a bit. |
@eyy thanks for your complete answer. The thing is much more complicate than what you think. What happens to the content of the nested loops? .. And of the nested loops of other internal loops? If we start handling all this cases we will end up writing angularjs. We need to keep riot dry using the yield tag we can cover the most of transclusion cases in a clear and simple way, without expecting any surprise. I'am going to close this issue for now. And I would be really happy to dig it more this argument in another issue. Thanks to for all your useful examples you helped me a lot ✌️ |
✌️ |
It would be great to specify where to include the content of a parent tag. Ie:
.... producing ....
The text was updated successfully, but these errors were encountered: