GithubHelp home page GithubHelp logo

bem / bem-templates-converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vkz/bemhtml-syntax

2.0 2.0 1.0 214 KB

BEM Templates Converter: BEMHTML to BEMHML.js, BEMHTML to BH

JavaScript 100.00%

bem-templates-converter's People

Contributors

collapsus avatar miripiruni avatar vkz avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

collapsus

bem-templates-converter's Issues

empty string to undefined

block('misspell').elem('link').def()(function() {
  return applyCtx(this.extend(this.ctx, {
    block: 'link',
    elem: ''
  }));
});

to

block('misspell').elem('link').def()(function() {
  return applyCtx(this.extend(this.ctx, {
    block: 'link',
    elem: undefined
  }));
});

Use block('*') if not entity match

Input file i-log with BEMHTML:

logNodeAttrValue: JSON.stringify(this.ctx.logNode)

default {
    this.ctx.logNode: { /* ... */ }
}

Run [email protected]:

$ bemhtml-syntax -i i-log.bemhtml

Actual:

mode('logNodeAttrValue')(function() {
    return JSON.stringify(this.ctx.logNode);
});

def()(
    match(function() {
        return this.ctx.logNode;
    })(function() { /* ... */ })
);

Expected:

block('*')(
    mode('logNodeAttrValue')(function() {
        return JSON.stringify(this.ctx.logNode);
    }),
    def()(
        match(function() {
            return this.ctx.logNode;
        })(function() { /* ... */ })
    )
);

Incorect parse rules in parentheses

IN: block event, (this.mods && this.mods.type == 'sport')
OUT: block('event').match((this.mods && this.mods.type == 'sport'))
MUST BE: block('event').match(function() { return this.mods && this.mods.type == 'sport'; })

Regexp is broken after convert

Input file suggest-item_type_nav with BEMHTML:

block suggest-item, mod type nav {
    default: {
        var url = this.ctx.data[4];
        applyNext({_url: (url.match(/^\w[\w-]*:\/\//g) ? '' : 'http://') + url});
    }
}

Run [email protected]:

$ bemhtml-syntax -i suggest-item_type_nav

Actual:

block('suggest-item').mod('type', 'nav')(
    def()(function() {
        var url = this.ctx.data[4];
        return applyNext({
            _url: (url.match('^\w[\w-]*:\/\/' // regexp turned to string
                g) ? '' : 'http://') + url 
        });
    }))

Expected:

block('suggest-item').mod('type', 'nav')(
    def()(function() {
        var url = this.ctx.data[4];
        return applyNext({
            _url: (url.match(/^\w[\w-]*:\/\//g) ? '' : 'http://') + url
        });
    }))

Will generate replace().once()

Autoconvert:

block('feedback').def()(function() {
    return applyCtx({ block: 'feedback', elem: 'wrapper' });
});

to

block('feedback').replace()(function() {
    return { block: 'feedback', elem: 'wrapper' };
});

Convert apply to applyNext if no mode argument

Input file block with BEMHTML:

block block, default {
    !this.ctx._guard: {
        apply(
            this.ctx._guard = true
        );
    }
}

Run [email protected]:

$ bemhtml-syntax -i block

Actual:

block('block').match(function () {
    return !this.ctx._guard;
}).def()(function () {
    return apply({
        'ctx._guard': true
    });
});

Expected:

block('block').match(function () {
    return !this.ctx._guard;
}).def()(function () {
    return applyNext({
        'ctx._guard': true
    });
});

def() must return something;

block('a')(
  elem('link').def()(function() {
      applyNext();
  })
);
block('a')(
  elem('link').def()(function() {
      return applyNext();
  })
);

Convert applyNext + this.ctx to applyCtx

Input file block with BEMHTML:

block block, default: {
    applyNext(
        this.ctx = {
            block: 'other-block'
        }
    );
}

Run [email protected]:

$ bemhtml-syntax -i block.bemhtml

Actual:

block('block').def()(function () {
    return applyNext({
        ctx: {
            block: 'other-block'
        }
    });
});

Expected:

block('block').def()(function () {
    return applyCtx({
        block: 'other-block'
    });
});

Add .once() if applyNext(_mode: '')

Input file block with BEMHTML:

block block, default: {
    applyNext(
        _mode: '',
        this.ctx = {
            block: 'other-block'
        }
    );
}

Run [email protected]:

$ bemhtml-syntax -i block.bemhtml

Actual:

block('block').def()(function () {
    return applyNext({
        _mode: '',
        ctx: {
            block: 'other-block'
        }
    });
});

Expected:

block('block').def().once()(function () {
    return applyNext({
        ctx: {
            block: 'other-block'
        }
    });
});

Use elem('*') if match contains this.elem

Input file header with BEMHTML:

block header {
    default, ~['logo', 'search', 'nav'].indexOf(this.elem): {
        /* ... */
    }
}

Run [email protected]:

$ bemhtml-syntax -i header.bemhtml

Actual:

block('header').def().match(function() {        
     return ~['logo', 'search', 'nav'].indexOf(this.elem);
})(function() {
    /* ... */
});

Expected:

block('header').elem('*').match(function() {
    return ~['logo', 'search', 'nav'].indexOf(this.elem);
}).def()(function() {
    /* ... */
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.