alexlawrence / declarative

Mapper for custom user interface markup.
Other
51 stars 4 forks source link

allow map concatenation #2

Closed tonydspaniard closed 11 years ago

tonydspaniard commented 11 years ago

Allows the addition of mappings, for example:

declarative.mappings.add({
    id: '2amigos.ui.js',
    prefix: 'data-transform-',
    types: ['currency'],
    callback: function(element, type, options) {
        var $el = $(element);
        var sign = options.sign || '$';
        var p = parseFloat(isNaN($el.text())?0:$el.text()).toFixed(2).split('.');
        $el.html(sign + p[0].split("").reverse().reduce(function(acc, num, i) {
            return  num + (i && !(i % 3) ? "," : "") + acc;
        }, "") + "." + p[1]);
    }
})
.add({
    id: 'widgets',
    prefix: 'data-ui-',
    types: ['counter'],
    callback: function(element, type, options) {
        $(options.target).keyup(function() {
            $(element).text($(this).val().length);
        });
    }
});
alexlawrence commented 11 years ago

Thanks for the pull request.

However it seems like you modified the "binary" file (therefore stored in /bin). The actual source code lies in /src and is built using cjs2web in combination with grunt.

The file in /bin is just included in the reqpository so people can use declarative directly without having to build it.