BH (mallimoottori)

BH
Tyyppi mallin moottori
Kehittäjä BEM-yhteisö
Sisään kirjoitettu JS , PHP (viralliset versiot)
Käyttöjärjestelmä Monialustainen ohjelmisto
Lisenssi MIT-lisenssi
Verkkosivusto bem.github.io/bh

BH ( B EM H TML ) on kääntäjän deklaratiivinen mallimoottori JS :lle .

BH:n avulla voit muokata DOM-puun solmuja samalla tavalla kuin CSS :ssä - deklaratiivisessa muodossa.

Esimerkki

JS- ilmoituksen saaminen :

bh . match ( 'painike' , function ( ctx ) { ctx . tag ( 'painike' ); }); bh . match ( 'button_legacy' , function ( ctx , json ) { ctx . tag ( 'input' ); ctx . attr ( 'type' , 'button' ); ctx . attr ( 'value' , json . content ); }) ; bh . match ( 'button_submit' , function ( ctx , json ) { ctx . tag ( 'input' ); ctx . attr ( 'type' , 'submit' ); ctx . attr ( 'arvo' , json . sisältö ); }) ;

Tai vastaava ilmoitus PHP -syntaksissa :

$bh -> match ( 'painike' , function ( $ctx ) { $ctx -> tag ( 'painike' ); }); $bh -> match ( 'button_legacy' , function ( $ctx , $json ) { $ctx -> tag ( 'input' ); $ctx -> attr ( 'type' , 'button' ); $ctx -> attr ( 'arvo' , $json -> sisältö ); }); $bh -> match ( 'button_submit' , function ( $ctx , $json ) { $ctx -> tag ( 'input' ); $ctx -> attr ( 'type' , 'submit' ); $ctx -> attr ( 'arvo' , $json -> sisältö ); });

Ja syötetiedot:

[ { "block" : "button" , "content" : "Vain painike" }, { "block" : "button" , "mods" : { "submit" : true }, "content" : "Lähetä-painike" } , { "block" : "button" , "mods" : { "legacy" : true }, "content" : "Legacy button" }, { "block" : "button" , "mods" : { "legacy" : true , "submit" : true }, "content" : "Vanhan tyylin lähetyspainike" } ]

Saamme tuloksen:

< button class = "painike" > Vain painike </ painike > < input class = "button button_submit" type = "submit" value = "Lähetä-painike" /> < input class = "button button_legacy" type = "button" value = "Vanha painike" /> < input class = "button button_legacy button_submit" type = "submit" value = "Vanhan tyylin lähetyspainike" />

Toteutukset

BH:n viralliset toteutukset on kirjoitettu JavaScriptillä ja PHP :llä .

Katso myös

Linkit

Muistiinpanot