Skip to content

Commit 0d8b227

Browse files
author
Dan Lasky
committed
array munger
1 parent 0545f08 commit 0d8b227

4 files changed

Lines changed: 199 additions & 0 deletions

File tree

src/mm-array-munge/index.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script language="javascript" src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
5+
<link rel="import" href="mm-array-munge.html">
6+
<style type="text/css">
7+
body, html {
8+
height: 100%;
9+
min-height: 100%;
10+
}
11+
12+
body {
13+
margin:0;
14+
padding:0;
15+
background: #eee;
16+
}
17+
18+
19+
</style>
20+
</head>
21+
<body>
22+
<dom-module id="munge-test">
23+
<template>
24+
<mm-array-munge input="{{input}}" output="{{output}}" rules="a->name,a->value"></mm-array-munge>
25+
</template>
26+
</dom-module>
27+
<script>
28+
HTMLImports.whenReady(function() {
29+
Polymer({
30+
is:'munge-test',
31+
properties:{
32+
input:{
33+
type:Array,
34+
value: function() {
35+
return [
36+
{a:1},
37+
{a:2},
38+
{a:3}
39+
];
40+
}
41+
},
42+
output:{
43+
type:Array,
44+
}
45+
},
46+
_mash: function(o) {
47+
return o.map(JSON.stringify);
48+
}
49+
});
50+
});
51+
</script>
52+
<munge-test></munge-test>
53+
</body>
54+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
* @license
3+
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
4+
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
5+
6+
-->
7+
<link rel="import" href="../../bower_components/polymer/polymer.html"/>
8+
<link rel="import" href="../shared/fonts/fonts.html"/>
9+
<link rel="import" href="../shared/js/colors.html"/>
10+
<link rel="import" href="../shared/behaviors/resolvable.html"/>
11+
<link rel="import" href="../shared/behaviors/stylable.html"/>
12+
<link rel="import" href="../shared/behaviors/refable.html"/>
13+
14+
<dom-module id="mm-action">
15+
<link rel="import" type="css" href="mm-array-munge.css"/>
16+
<template>
17+
</template>
18+
</dom-module>
19+
<script src="mm-array-munge.js"></script>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
4+
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
5+
6+
*/
7+
(function (scope) {
8+
9+
scope.ArrayMunge = Polymer({
10+
is: "mm-array-munge",
11+
12+
behaviors: [
13+
StrandTraits.Resolvable,
14+
StrandTraits.Refable
15+
],
16+
17+
properties: {
18+
_parsedRules:{
19+
type:Array,
20+
value: function() { return []; }
21+
},
22+
input:{
23+
type:Array,
24+
notify:true
25+
},
26+
output:{
27+
type:Array,
28+
notify:true
29+
},
30+
rules:{
31+
type:String,
32+
value:"",
33+
observer:"_parseRules"
34+
}
35+
},
36+
37+
observers:['_handleInputUpdate(input.*, _parsedRules)'],
38+
39+
_handleInputUpdate() {
40+
var o = this.input.map(function(i) {
41+
var o = {};
42+
this._parsedRules.forEach(function(rule) {
43+
var val = rule.from === '.' ? i : i[rule.from];
44+
if (rule.to !== '.') {
45+
o[rule.to] = val;
46+
} else {
47+
o = val;
48+
}
49+
})
50+
return o;
51+
},this);
52+
this.set('output', o);
53+
},
54+
55+
_parseRules: function() {
56+
this._parsedRules = this.rules.split(",").map(function(rule) {
57+
var parsed = rule.split("->");
58+
if (parsed.length === 2) {
59+
return {
60+
from:parsed[0],
61+
to:parsed[1]
62+
}
63+
}
64+
}, this).filter(function(o) { return !!o });
65+
}
66+
67+
});
68+
69+
})(window.Strand = window.Strand || {});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2015 MediaMath Inc. All rights reserved.
4+
* This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
5+
6+
*/
7+
/* test.sass */
8+
@import "_bourbon";
9+
@import "_color";
10+
@import "_mixins";
11+
12+
:host {
13+
color: $color-D0;
14+
position: relative;
15+
display: inline-block;
16+
vertical-align: middle;
17+
font-size: 0em;
18+
line-height: 0em;
19+
}
20+
21+
:host([disabled]) {
22+
pointer-events:none;
23+
opacity: 0.5;
24+
}
25+
26+
.action {
27+
display: inline-flex;
28+
align-items: center;
29+
30+
color: inherit;
31+
cursor: pointer;
32+
text-decoration: none;
33+
34+
&.underline > ::content label {
35+
text-decoration: underline;
36+
}
37+
38+
&.underline:hover > ::content label {
39+
text-decoration: none;
40+
}
41+
42+
& > ::content label {
43+
@include fontSmoothing();
44+
font-size: 13px;
45+
line-height: 15px;
46+
font-family: "ArimoRegular", sans-serif;
47+
pointer-events: none;
48+
color: inherit;
49+
}
50+
51+
& > ::content mm-icon {
52+
pointer-events: none;
53+
padding-right: 5px;
54+
margin-top: -1px;
55+
color: inherit;
56+
}
57+
}

0 commit comments

Comments
 (0)