Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: node_modules/vulcanize/lib/utils.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « node_modules/vulcanize/lib/pathresolver.js ('k') | node_modules/vulcanize/lib/vulcan.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: node_modules/vulcanize/lib/utils.js
diff --git a/node_modules/vulcanize/lib/utils.js b/node_modules/vulcanize/lib/utils.js
new file mode 100644
index 0000000000000000000000000000000000000000..e7d078c40fa28a3da7e38e1b2068e95ac7650f76
--- /dev/null
+++ b/node_modules/vulcanize/lib/utils.js
@@ -0,0 +1,78 @@
+/**
+ * @license
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
+ * Code distributed by Google as part of the polymer project is also
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
+ */
+var path = require('path');
+
+function concatTemplates($, context, query, matches) {
+ $('template, ' + query, context).each(function() {
+ if (this.name === 'template') {
+ concatTemplates($, this.children[0], query, matches);
+ } else {
+ matches.push(this);
+ }
+ });
+}
+
+module.exports = {
+ // directly update the textnode child of <style>
+ // equivalent to <style>.textContent
+ setTextContent: function(node, text) {
+ var unwrapped = node.cheerio ? node.get(0) : node;
+ var child = unwrapped.children[0];
+ if (child) {
+ child.data = text;
+ } else {
+ unwrapped.children[0] = {
+ data: text,
+ type: 'text',
+ next: null,
+ prev: null,
+ parent: unwrapped
+ };
+ }
+ },
+ getTextContent: function(node) {
+ var unwrapped = node.cheerio ? node.get(0) : node;
+ var child = unwrapped.children[0];
+ return child ? child.data : '';
+ },
+ // escape a string to be used in new RegExp
+ escapeForRegExp: function(s) {
+ return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+ },
+ unixPath: function(inpath, optSep) {
+ var sep = optSep || path.sep;
+ if (sep !== '/') {
+ inpath = inpath.split(sep).join('/');
+ }
+ return inpath;
+ },
+ processPolymerInvocation: function(elementName, invocation) {
+ var name = invocation[1] || '';
+ var split = invocation[2] || '';
+ var trailing = invocation[3];
+ var nameIsString = /^['"]/.test(name);
+ if (!split) {
+ // assume "name" is actually the prototype if it is not a string literal
+ if (!name || (name && !nameIsString)) {
+ trailing = name + trailing;
+ name = '\'' + elementName + '\'';
+ }
+ if (trailing !== ')') {
+ split = ',';
+ }
+ }
+ return 'Polymer(' + name + split + trailing;
+ },
+ searchAll: function($, query) {
+ var matches = [];
+ concatTemplates($, null, query, matches);
+ return $(matches);
+ }
+};
« no previous file with comments | « node_modules/vulcanize/lib/pathresolver.js ('k') | node_modules/vulcanize/lib/vulcan.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698