OLD | NEW |
(Empty) | |
| 1 /** |
| 2 * @license |
| 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
| 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
| 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
| 7 * Code distributed by Google as part of the polymer project is also |
| 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
| 9 */ |
| 10 var path = require('path'); |
| 11 |
| 12 function concatTemplates($, context, query, matches) { |
| 13 $('template, ' + query, context).each(function() { |
| 14 if (this.name === 'template') { |
| 15 concatTemplates($, this.children[0], query, matches); |
| 16 } else { |
| 17 matches.push(this); |
| 18 } |
| 19 }); |
| 20 } |
| 21 |
| 22 module.exports = { |
| 23 // directly update the textnode child of <style> |
| 24 // equivalent to <style>.textContent |
| 25 setTextContent: function(node, text) { |
| 26 var unwrapped = node.cheerio ? node.get(0) : node; |
| 27 var child = unwrapped.children[0]; |
| 28 if (child) { |
| 29 child.data = text; |
| 30 } else { |
| 31 unwrapped.children[0] = { |
| 32 data: text, |
| 33 type: 'text', |
| 34 next: null, |
| 35 prev: null, |
| 36 parent: unwrapped |
| 37 }; |
| 38 } |
| 39 }, |
| 40 getTextContent: function(node) { |
| 41 var unwrapped = node.cheerio ? node.get(0) : node; |
| 42 var child = unwrapped.children[0]; |
| 43 return child ? child.data : ''; |
| 44 }, |
| 45 // escape a string to be used in new RegExp |
| 46 escapeForRegExp: function(s) { |
| 47 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 48 }, |
| 49 unixPath: function(inpath, optSep) { |
| 50 var sep = optSep || path.sep; |
| 51 if (sep !== '/') { |
| 52 inpath = inpath.split(sep).join('/'); |
| 53 } |
| 54 return inpath; |
| 55 }, |
| 56 processPolymerInvocation: function(elementName, invocation) { |
| 57 var name = invocation[1] || ''; |
| 58 var split = invocation[2] || ''; |
| 59 var trailing = invocation[3]; |
| 60 var nameIsString = /^['"]/.test(name); |
| 61 if (!split) { |
| 62 // assume "name" is actually the prototype if it is not a string literal |
| 63 if (!name || (name && !nameIsString)) { |
| 64 trailing = name + trailing; |
| 65 name = '\'' + elementName + '\''; |
| 66 } |
| 67 if (trailing !== ')') { |
| 68 split = ','; |
| 69 } |
| 70 } |
| 71 return 'Polymer(' + name + split + trailing; |
| 72 }, |
| 73 searchAll: function($, query) { |
| 74 var matches = []; |
| 75 concatTemplates($, null, query, matches); |
| 76 return $(matches); |
| 77 } |
| 78 }; |
OLD | NEW |