Skip to content

Commit

Permalink
Merge pull request #62 from dlasky/dev/array-munge
Browse files Browse the repository at this point in the history
array munger
  • Loading branch information
dlasky committed Mar 3, 2016
2 parents a39a87f + 017e019 commit 0e8a4c8
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/mm-array-munge/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<script language="javascript" src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="mm-array-munge.html">
<style type="text/css">
body, html {
height: 100%;
min-height: 100%;
}

body {
margin:0;
padding:0;
background: #eee;
}


</style>
</head>
<body>
<dom-module id="munge-test">
<template>
<mm-array-munge input="{{input}}" output="{{output}}" rules="a->name,a->value"></mm-array-munge>
</template>
</dom-module>
<script>
HTMLImports.whenReady(function() {
Polymer({
is:'munge-test',
properties:{
input:{
type:Array,
value: function() {
return [
{a:1},
{a:2},
{a:3}
];
}
},
output:{
type:Array,
}
},
_mash: function(o) {
return o.map(JSON.stringify);
}
});
});
</script>
<munge-test></munge-test>
</body>
</html>
19 changes: 19 additions & 0 deletions src/mm-array-munge/mm-array-munge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
-->
<link rel="import" href="../../bower_components/polymer/polymer.html"/>
<link rel="import" href="../shared/fonts/fonts.html"/>
<link rel="import" href="../shared/js/colors.html"/>
<link rel="import" href="../shared/behaviors/resolvable.html"/>
<link rel="import" href="../shared/behaviors/stylable.html"/>
<link rel="import" href="../shared/behaviors/refable.html"/>

<dom-module id="mm-array-munge">
<link rel="import" type="css" href="mm-array-munge.css"/>
<template>
</template>
</dom-module>
<script src="mm-array-munge.js"></script>
69 changes: 69 additions & 0 deletions src/mm-array-munge/mm-array-munge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
*/
(function (scope) {

scope.ArrayMunge = Polymer({
is: "mm-array-munge",

behaviors: [
StrandTraits.Resolvable,
StrandTraits.Refable
],

properties: {
_parsedRules:{
type:Array,
value: function() { return []; }
},
input:{
type:Array,
notify:true
},
output:{
type:Array,
notify:true
},
rules:{
type:String,
value:"",
observer:"_parseRules"
}
},

observers:['_handleInputUpdate(input.*, _parsedRules)'],

_handleInputUpdate() {
var o = this.input.map(function(i) {
var o = {};
this._parsedRules.forEach(function(rule) {
var val = rule.from === '.' ? i : i[rule.from];
if (rule.to !== '.') {
o[rule.to] = val;
} else {
o = val;
}
})
return o;
},this);
this.set('output', o);
},

_parseRules: function() {
this._parsedRules = this.rules.split(",").map(function(rule) {
var parsed = rule.split("->");
if (parsed.length === 2) {
return {
from:parsed[0],
to:parsed[1]
}
}
}, this).filter(function(o) { return !!o });
}

});

})(window.Strand = window.Strand || {});
13 changes: 13 additions & 0 deletions src/mm-array-munge/mm-array-munge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
*/
// @import "_bourbon";
// @import "_color";
// @import "_mixins";

:host {
display:none;
}

0 comments on commit 0e8a4c8

Please sign in to comment.