source: trip-planner-front/node_modules/stylus/lib/nodes/group.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1
2/*!
3 * Stylus - Group
4 * Copyright (c) Automattic <developer.wordpress.com>
5 * MIT Licensed
6 */
7
8/**
9 * Module dependencies.
10 */
11
12var Node = require('./node');
13
14/**
15 * Initialize a new `Group`.
16 *
17 * @api public
18 */
19
20var Group = module.exports = function Group(){
21 Node.call(this);
22 this.nodes = [];
23 this.extends = [];
24};
25
26/**
27 * Inherit from `Node.prototype`.
28 */
29
30Group.prototype.__proto__ = Node.prototype;
31
32/**
33 * Push the given `selector` node.
34 *
35 * @param {Selector} selector
36 * @api public
37 */
38
39Group.prototype.push = function(selector){
40 this.nodes.push(selector);
41};
42
43/**
44 * Return this set's `Block`.
45 */
46
47Group.prototype.__defineGetter__('block', function(){
48 return this.nodes[0].block;
49});
50
51/**
52 * Assign `block` to each selector in this set.
53 *
54 * @param {Block} block
55 * @api public
56 */
57
58Group.prototype.__defineSetter__('block', function(block){
59 for (var i = 0, len = this.nodes.length; i < len; ++i) {
60 this.nodes[i].block = block;
61 }
62});
63
64/**
65 * Check if this set has only placeholders.
66 *
67 * @return {Boolean}
68 * @api public
69 */
70
71Group.prototype.__defineGetter__('hasOnlyPlaceholders', function(){
72 return this.nodes.every(function(selector) { return selector.isPlaceholder; });
73});
74
75/**
76 * Return a clone of this node.
77 *
78 * @return {Node}
79 * @api public
80 */
81
82Group.prototype.clone = function(parent){
83 var clone = new Group;
84 clone.lineno = this.lineno;
85 clone.column = this.column;
86 this.nodes.forEach(function(node){
87 clone.push(node.clone(parent, clone));
88 });
89 clone.filename = this.filename;
90 clone.block = this.block.clone(parent, clone);
91 return clone;
92};
93
94/**
95 * Return a JSON representation of this node.
96 *
97 * @return {Object}
98 * @api public
99 */
100
101Group.prototype.toJSON = function(){
102 return {
103 __type: 'Group',
104 nodes: this.nodes,
105 block: this.block,
106 lineno: this.lineno,
107 column: this.column,
108 filename: this.filename
109 };
110};
Note: See TracBrowser for help on using the repository browser.