0.0.2 • Published 10 years ago

bemtmpl v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

JavaScript based, client-side, lightweight, simple templater for BEM

npm

Demo

Declaration

Use .decl(name, templater) method to declarate new template.

  • name – the name of template
  • templater(ctx) – function, which convert entry bemjson to html
    • ctx – entry bemjson tree
BEMTMPL.decl('my-block', function(ctx) {
    ctx.content(ctx.data, true);
});

Templating

BEMTMPL.apply({ block: 'my-block', data: 'azaza' });

Methods

ctx object, that available inside templater, have several methods for modification entry bemjson tree:

  • js
  • attr
  • mods
  • mix
  • content

All methods have same signature method([data][, force]):

  • data – data to modify self-named field of bemjson tree
  • force – by default, field data was extended with data. If force: true, field value was replaced with data.

NOTE: force doesn't work for mix for ideological reasons.

Getters

If you don't specify the data, all above methods return value of appropriate field.

ctx.mods(); // { theme: simple }

For attrs and mods you can specify the name of attribute or modifier that you want to get.

ctx.mods('theme'); // 'simple'

Dependencies

0.0.2

10 years ago

0.0.1

10 years ago