BEMHTML source code converter:
Given the impedence mismatch between Bemhtml and Bh it does not seem possible to convert every template or guarantee that the applicative semantics of the source is preserved in the result. Bemhtml is much too expressive and lenient to deliver on such promise. The ability to apply templates in a modified context powered by xjst methods apply, applyNext, applyCtx employing the result is one feature prominantly missing in Bh. Its applyBase method carries a very particular meaning that doesn't map clearly on Bemhtml machinery and as of this writing appears to be broken anyway.
npm -g install bemhtml-syntax
bemhtml-syntax [OPTIONS] [ARGS]# convert to new JS-syntax (bemxjst4 is the default and -f can be dropped).# -f bemxjst4 will also do its best to preserve comments.bemhtml-syntax -f bemxjst4 [OPTIONS] [ARGS]# convert to BHbemhtml-syntax -f bh [OPTIONS] [ARGS]
-S flag aka
--strictOff is specific to BH converter and as
the name suggests turns the default strict compiler mode off. Generally we don't
recommend it, but this may help you convert many more templates to BH without
warnings so it's there for when you have a fairly big BEMHTML template you want
to convert to BH and you'd rather have some skeleton you can flesh out rather
than starting completely from scratch. The result is not guaranteed to carry
proper BEMHTML semantics over to BH and assumes that you'll fix it by hand.
Other options mostly control the code-style of generated code. E.g. you may
-q double quotes for strings and enforcing
-Q quotes around object
keys, etc. Converter also accepts most options offered by js-beautify.
For example, convert
block b-wrappertag: 'wrap'content: thisctxcontentblock b-inner default:
bemhtml-syntax -f bemxjst1 -q "double" -Q -i test/basic/info6.bemhtml
Added in the latest version are some
bem-xjst4 specific features, these will work only with
-eM, --elem-match : Wrap predicates with "this.elem" in "elemMatch"-wP, --wrap-pattern : Use "wrap()" instead of "def()+applyCtx()+this.ctx()" pattern-aB, --assert-has-block : Assert that every template has sub-predicate matching "block"-aE, --assert-no-this-elem : Assert "this.elem" is not used in predicates-aF, --assert-no-buf : Assert "this._buf" is not used in templates-rD, --return-from-def : Always return in "default" mode, insert "return ''" when missing.-aM, --apply-sets-mode : Assert that every call to-aC, --apply-check-fields : Warn