/*
<div bind="header" class="header">
<h1>This is the content for the header</h1>
</div>
<div bind="body" class="body">
<p> This is some content for the body</p>
</div>
*/
var Block = require('blocks/block')
var someBlock = block('some', {
template: '\
<div bind="header" class="header">\
</div>\
<div bind="body" class="body">\
</div>\
'
,children: {
header: new Block('some.header', {
template: '<h1>This is the content for the header</h1>'
})
,content: new Block({
template: '<%=this.getStringFromMethod()%>'
}, {
getStringFromMethod: function () {
return "<p> This is some content for the body</p>"
}
})
}
})
document.body.appendChild(someBlock.toElement())
- AMD Loader
- Yaul
- Yeah mixin
- Yate mixin
npm install blocks
- #setChild
- #getChild
- #removeChild
- #setChildren
- #getChildren
- #removeChildren
- *#getChildHtml
- *#emptyChildNode
- #attachEvents
- #bindTemplate
- *#bindElements
- *#bindChildren
- *#clearBoundElements
- #setBoundElement
- #getBoundElement | #bound
- *#getBoundElements
- #setContainer
- #getContainer
- #getUniqueId
- *#toString
- *#fillContainer
- #toElement
- #inject
* indicates it may or maynot be removed.
Options:
- template {string|path}
- children {object}
- events {object}
- inject {string|element}
var instance = block(/* object */ {})
var block = require('blocks/block')
var blocks = require('blocks')
var instance = block ('some.identifier',{})
blocks.reference('some.identifier') == instance
Adds a child block.
- key {String} child container reference
- block {Block || Array of Blocks}
var instance = block({
template: '<div class="wrapper"><b name="drop"></b></div>'
})
instance.setChild('drop', block({
template: '<h1>Hello</h1>'
})
)
instance.setChild('drop', [
block({template: '<h1>Hello Again</h1>'})
,block({template: '<p>Do you like my hat?</p>'})
])
Returns the unique identifing string
for the block instance. This method is intended mostly for internal use.
instance.getUniqueId() // h9s5ep2c1
Sugar syntax for document.getElementById('some-id').appendChild(instance.toElement())
.
- where {Element || String} Either the node reference, or the id of a DOM node of the element of which to inject the block into
// with a node reference passed in
instance.inject(document.body)
// with a node ID string passed
instance.inject('some-id')