bfe5773b4aaad844dea720e266a8268a9059ce52.svn-base 865 B

123456789101112131415161718192021222324252627282930313233
  1. var NodeContainer = require('./nodecontainer');
  2. function TextContainer(node, parent) {
  3. NodeContainer.call(this, node, parent);
  4. }
  5. TextContainer.prototype = Object.create(NodeContainer.prototype);
  6. TextContainer.prototype.applyTextTransform = function() {
  7. this.node.data = this.transform(this.parent.css("textTransform"));
  8. };
  9. TextContainer.prototype.transform = function(transform) {
  10. var text = this.node.data;
  11. switch(transform){
  12. case "lowercase":
  13. return text.toLowerCase();
  14. case "capitalize":
  15. return text.replace(/(^|\s|:|-|\(|\))([a-z])/g, capitalize);
  16. case "uppercase":
  17. return text.toUpperCase();
  18. default:
  19. return text;
  20. }
  21. };
  22. function capitalize(m, p1, p2) {
  23. if (m.length > 0) {
  24. return p1 + p2.toUpperCase();
  25. }
  26. }
  27. module.exports = TextContainer;