Skip to content

Commit 29a4521

Browse files
committed
Support a list filter
1 parent 5b83f77 commit 29a4521

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

demo.html

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ <h3>length</h3>
8282
<h3>trim</h3>
8383
{{' I was a string with leading and trailing whitespace ' | trim}}
8484

85+
<h3>list</h3>
86+
{{colors | list}}
87+
88+
<h3>list(" ")</h3>
89+
{{colors | list(" ")}}
90+
8591
</template>
8692
<script>
8793
var template = document.getElementById('view');

filter-list.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Transform an array of strings into a readable list
3+
* @param {array} input
4+
* @return {string} array elements delimited by a comma
5+
*/
6+
PolymerExpressions.prototype.list = function(input, space){
7+
return input.join("," + (space || ""));
8+
};

polymer-filters.html

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<script src="filter-titlecase.js"></script>
1616
<script src="filter-trim.js"></script>
1717
<script src="filter-length.js"></script>
18+
<script src="filter-list.js"></script>
1819

1920
<!--
2021
A collection of filters for formatting values of [Polymer expressions](http://www.polymer-project.org/docs/polymer/expressions.html) for display to users.
@@ -141,6 +142,16 @@
141142
142143
> 45.3
143144
145+
####Converting arrays to a list
146+
147+
{{ arr | list }}
148+
149+
> something,somethingelse,etc
150+
151+
{{ arr | list(" ") }}
152+
153+
> something, somethingelse, etc
154+
144155
@element polymer-filters
145156
@blurb A collection of Polymer filters for formatting values of expressions for display to users
146157
@homepage http://addyosmani.github.io/polymer-filters

0 commit comments

Comments
 (0)