Skip to content

Commit

Permalink
array munger
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lasky committed Mar 3, 2016
1 parent 0545f08 commit 0d8b227
Show file tree
Hide file tree
Showing 4 changed files with 199 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-action">
<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 || {});
57 changes: 57 additions & 0 deletions src/mm-array-munge/mm-array-munge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @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
*/
/* test.sass */
@import "_bourbon";
@import "_color";
@import "_mixins";

:host {
color: $color-D0;
position: relative;
display: inline-block;
vertical-align: middle;
font-size: 0em;
line-height: 0em;
}

:host([disabled]) {
pointer-events:none;
opacity: 0.5;
}

.action {
display: inline-flex;
align-items: center;

color: inherit;
cursor: pointer;
text-decoration: none;

&.underline > ::content label {
text-decoration: underline;
}

&.underline:hover > ::content label {
text-decoration: none;
}

& > ::content label {
@include fontSmoothing();
font-size: 13px;
line-height: 15px;
font-family: "ArimoRegular", sans-serif;
pointer-events: none;
color: inherit;
}

& > ::content mm-icon {
pointer-events: none;
padding-right: 5px;
margin-top: -1px;
color: inherit;
}
}

0 comments on commit 0d8b227

Please sign in to comment.