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

Unified Diff: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/lib/static.js

Issue 125733002: Add vulcanize to tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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
Index: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/lib/static.js
diff --git a/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/lib/static.js b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/lib/static.js
new file mode 100644
index 0000000000000000000000000000000000000000..10eabf5a2d067ab29aa4964a2ec34918de81f318
--- /dev/null
+++ b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/lib/static.js
@@ -0,0 +1,134 @@
+/**
+ * Module dependencies
+ */
+
+var select = require('cheerio-select'),
+ parse = require('./parse'),
+ render = require('./render'),
+ decode = require('./utils').decode;
+
+/**
+ * $.load(str)
+ */
+
+var load = exports.load = function(str, options) {
+ var Cheerio = require('./cheerio'),
+ root = parse(str, options);
+
+ var initialize = function(selector, context, r) {
+ return new Cheerio(selector, context, r || root);
+ };
+
+ // Add in the static methods
+ initialize.__proto__ = exports;
+
+ // Add in the root
+ initialize._root = root;
+
+ return initialize;
+};
+
+/**
+ * $.html([selector | dom])
+ */
+
+var html = exports.html = function(dom) {
+ if (dom) {
+ dom = (typeof dom === 'string') ? select(dom, this._root) : dom;
+ return render(dom);
+ } else if (this._root && this._root.children) {
+ return render(this._root.children);
+ } else {
+ return '';
+ }
+};
+
+/**
+ * $.xml([selector | dom])
+ */
+
+var xml = exports.xml = function(dom) {
+ if (dom) {
+ dom = (typeof dom === 'string') ? select(dom, this._root) : dom;
+ return render(dom, { xmlMode: true });
+ } else if (this._root && this._root.children) {
+ return render(this._root.children, { xmlMode: true });
+ } else {
+ return '';
+ }
+};
+
+/**
+ * $.text(dom)
+ */
+
+var text = exports.text = function(elems) {
+ if (!elems) return '';
+
+ var ret = '',
+ len = elems.length,
+ elem;
+
+ for (var i = 0; i < len; i ++) {
+ elem = elems[i];
+ if (elem.type === 'text') ret += decode(elem.data);
+ else if (elem.children && elem.type !== 'comment') {
+ ret += text(elem.children);
+ }
+ }
+
+ return ret;
+};
+
+/**
+ * $.parseHTML(data [, context ] [, keepScripts ])
+ * Parses a string into an array of DOM nodes. The `context` argument has no
+ * meaning for Cheerio, but it is maintained for API compatability with jQuery.
+ */
+var parseHTML = exports.parseHTML = function(data, context, keepScripts) {
+ var parsed;
+
+ if (!data || typeof data !== 'string') {
+ return null;
+ }
+
+ if (typeof context === 'boolean') {
+ keepScripts = context;
+ }
+
+ parsed = this.load(data);
+ if (!keepScripts) {
+ parsed('script').remove();
+ }
+
+ return parsed.root()[0].children;
+};
+
+/**
+ * $.root()
+ */
+var root = exports.root = function() {
+ return this(this._root);
+};
+
+/**
+ * $.contains()
+ */
+var contains = exports.contains = function(container, contained) {
+
+ // According to the jQuery API, an element does not "contain" itself
+ if (contained === container) {
+ return false;
+ }
+
+ // Step up the descendents, stopping when the root element is reached
+ // (signaled by `.parent` returning a reference to the same object)
+ while (contained && contained !== contained.parent) {
+ contained = contained.parent;
+ if (contained === container) {
+ return true;
+ }
+ }
+
+ return false;
+};

Powered by Google App Engine
This is Rietveld 408576698