//- bemto //- Copyright(c) 2012 Roman Komarov //- MIT Licensed include bemto_custom_tag.pug //- Tag mixin, used for tweaking what tag we are throwing and do we need to wrap anything here mixin bemto_tag(tag, tagMetadata) - var settings = get_bemto_settings() - tagMetadata = tagMetadata || {} //- rewriting tag name on different contexts - var newTag = tag || settings['default_tag'] - var contextIndex = bemto_chain_contexts.length //- Checks for contexts if no tag given if !tag if bemto_chain_contexts[contextIndex-1] === 'inline' - newTag = 'span' else if bemto_chain_contexts[contextIndex-1] === 'list' - newTag = 'li' else if bemto_chain_contexts[contextIndex-1] === 'optionlist' - newTag = 'option' //- Attributes context checks //- Only when no actual tag is given if !tag || tag == 'span' || tag == 'div' if attributes.href - newTag = 'a' if attributes.for - newTag = 'label' if attributes.type //- TODO: Add more checks for different type value patterns - newTag = block ? 'button' : 'input' else if attributes.src - newTag = 'img' //- Contextual wrappers if bemto_chain_contexts[contextIndex-1] === 'list' && newTag !== 'li' |
  • else if bemto_chain_contexts[contextIndex-1] !== 'list' && bemto_chain_contexts[contextIndex-1] !== 'pseudo-list' && newTag === 'li' | - bemto_chain_contexts = bemto_chain_contexts.splice(0,bemto_chain_contexts.length-1) //- Setting context - var content_type = tagMetadata.content_type || get_bemto_tag_content_type(newTag) - bemto_chain_contexts[bemto_chain_contexts.length] = content_type if newTag == 'img' //- If there is no title we don't need it to show even if there is some alt if attributes.alt && !attributes.title - attributes.title = '' //- If we have title, we must have it in alt if it's not set if attributes.title && !attributes.alt - attributes.alt = attributes.title if !attributes.alt - attributes.alt = '' if attributes.alt === '' - attributes.role = 'presentation' if !attributes.src if settings.nosrc_substitute === true - attributes.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' else if settings.nosrc_substitute - attributes.src = settings.nosrc_substitute if newTag == 'input' if !attributes.type - attributes.type = "text" if newTag == 'main' if !attributes.role - attributes.role = 'main' if newTag == 'html' +bemto_custom_tag(newTag, tagMetadata)&attributes(attributes) if block block //- Closing all the wrapper tails if bemto_chain_contexts[contextIndex-1] === 'list' && newTag != 'li' |