intercellular / cell

A self-driving web app framework
https://www.celljs.org
MIT License
1.5k stars 94 forks source link

Empty tag generate option #32

Closed abeq closed 7 years ago

abeq commented 7 years ago

Current: $components: [{ $type: "img", src: "http://localhost/img.jpg" }, ->

I want to generate empty tag with xml style (add '/' before '>'). ->

Could you add option to select it?

codehz commented 7 years ago

I think it is impossible to control the style...because it use document.createElement to create element(It means that the style is depended on browser's implement)

gliechtenstein commented 7 years ago

Currently there is no way to do so because like @codehz said, these elements are created natively by document.createElement and that's what browsers prefer.

I'm curious though, could you share why you want that format?

abeq commented 7 years ago

Thank you for your reply.

I'm curious though, could you share why you want that format?

Because I want to use generated code with xml related processor such as xslt, etc. Probably <img src="foo/bar.png"> will not be passed validation of xml parser.

gliechtenstein commented 7 years ago

Cell doesn't create HTML strings but actually creates HTML nodes on the browser. Therefore this is 100% dependent on how browser implements it (The recommended way nowadays is to NOT use the closing slashes for those nodes)

I don't know why you would want to pass an HTML through an XSLT parser, but if what you're looking for is to transform or compose nodes, you can do this BEFORE the nodes are created by Cell.

In fact this is the main strength of cell because it's powered by JSON. You can map, filter, sort, or run all kinds of functions on the original object before creating an HTML element.

There's not really much to be done about this so going to close for now.

But feel free to ask further questions, If the solution I suggested above was not what you were looking for I can try to suggest a solution for your problem. Anyway hope this answers your question!