123456789101112131415161718192021222324252627282930313233 |
- var NodeContainer = require('./nodecontainer');
- function TextContainer(node, parent) {
- NodeContainer.call(this, node, parent);
- }
- TextContainer.prototype = Object.create(NodeContainer.prototype);
- TextContainer.prototype.applyTextTransform = function() {
- this.node.data = this.transform(this.parent.css("textTransform"));
- };
- TextContainer.prototype.transform = function(transform) {
- var text = this.node.data;
- switch(transform){
- case "lowercase":
- return text.toLowerCase();
- case "capitalize":
- return text.replace(/(^|\s|:|-|\(|\))([a-z])/g, capitalize);
- case "uppercase":
- return text.toUpperCase();
- default:
- return text;
- }
- };
- function capitalize(m, p1, p2) {
- if (m.length > 0) {
- return p1 + p2.toUpperCase();
- }
- }
- module.exports = TextContainer;
|