Skip to content

Commit dc5e1a4

Browse files
committed
Added a capitalize filter
1 parent 4557f0f commit dc5e1a4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

demo.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ <h3>list</h3>
104104
<h3>list(" ")</h3>
105105
{{colors | list(" ")}}
106106

107+
<h3>capitalize</h3>
108+
{{greeting | capitalize}}
109+
107110
</template>
108111
<script>
109112
var template = document.getElementById('view');
110113
var phones = [{'name':'Nexus S','snippet':'Fast just got faster with Nexus S.','age':1},{'name':'Motorola XOOM with Wi-Fi','snippet':'The Next, Next Generation tablet.','age':2},{'name':'MOTOROLA XOOM','snippet':'The Next, Next Generation tablet.','age':3}];
111-
var template = document.getElementById('view');
112114
template.phones = phones;
113115
template.orderProp = 'age';
114116
template.colors = ['red','green','blue','yellow'];

filter-capitalize.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Capitalize a string (transform its first letter to uppercase and the rest to lowercase)
3+
* @param {string} string
4+
* @return {string} the capitalized string
5+
*/
6+
PolymerExpressions.prototype.capitalize = function (string) {
7+
string = string.toLowerCase();
8+
return string.charAt(0).toUpperCase() + string.slice(1);
9+
};

polymer-filters.html

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<script src="filter-length.js"></script>
2020
<script src="filter-list.js"></script>
2121
<script src="filter-limitTo.js"></script>
22+
<script src="filter-capitalize.js"></script>
2223

2324
<!--
2425
A collection of filters for formatting values of [Polymer expressions](http://www.polymer-project.org/docs/polymer/expressions.html) for display to users.
@@ -176,6 +177,12 @@
176177
177178
> something, somethingelse, etc
178179
180+
####Capitalize
181+
182+
{{ "Hello World!" | capitalize }}
183+
184+
> Hello world!
185+
179186
@element polymer-filters
180187
@blurb A collection of Polymer filters for formatting values of expressions for display to users
181188
@homepage http://github.com/addyosmani/polymer-filters

0 commit comments

Comments
 (0)