Sha256: b1f2b1ec12bacf31fb07ed57a437ec35dbc42d57c13f46f2747250ff95ce387b
Contents?: true
Size: 1.54 KB
Versions: 5
Compression:
Stored size: 1.54 KB
Contents
/*! * Jade - nodes - Tag * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> * MIT Licensed */ /** * Module dependencies. */ var Node = require('./node'), Block = require('./block'); /** * Initialize a `Tag` node with the given tag `name` and optional `block`. * * @param {String} name * @param {Block} block * @api public */ var Tag = module.exports = function Tag(name, block) { this.name = name; this.attrs = []; this.block = block || new Block; }; /** * Inherit from `Node`. */ Tag.prototype.__proto__ = Node.prototype; /** * Set attribute `name` to `val`, keep in mind these become * part of a raw js object literal, so to quote a value you must * '"quote me"', otherwise or example 'user.name' is literal JavaScript. * * @param {String} name * @param {String} val * @return {Tag} for chaining * @api public */ Tag.prototype.setAttribute = function(name, val){ this.attrs.push({ name: name, val: val }); return this; }; /** * Remove attribute `name` when present. * * @param {String} name * @api public */ Tag.prototype.removeAttribute = function(name){ for (var i = 0, len = this.attrs.length; i < len; ++i) { if (this.attrs[i] && this.attrs[i].name == name) { delete this.attrs[i]; } } }; /** * Get attribute value by `name`. * * @param {String} name * @return {String} * @api public */ Tag.prototype.getAttribute = function(name){ for (var i = 0, len = this.attrs.length; i < len; ++i) { if (this.attrs[i] && this.attrs[i].name == name) { return this.attrs[i].val; } } };
Version data entries
5 entries across 5 versions & 1 rubygems