Class: Sass::Tree::Node
- Inherits:
-
Object
- Object
- Sass::Tree::Node
- Defined in:
- lib/scss_lint/sass/tree.rb
Overview
Define some common helper code for use in the various monkey patchings.
Instance Attribute Summary collapse
-
#node_parent ⇒ Object
Stores node for which this node is a direct child.
Instance Method Summary collapse
-
#add_line_number(node) ⇒ Object
The Sass parser sometimes doesn’t assign line numbers in cases where it should.
-
#add_line_numbers_to_args(arg_list) ⇒ Object
The ‘args` field of some Sass::Tree::Node classes returns Sass::Script::Variable nodes with no line numbers.
-
#concat_expr_lists(*expr_lists) ⇒ Object
Takes a list of arguments, be they arrays or individual objects, and returns a single flat list that can be passed to Sass::Tree::Visitors::Base#visit_children.
-
#create_variable(var_name) ⇒ Object
Sometimes the parse tree doesn’t return a Sass::Script::Variable, but just the name of the variable.
-
#extract_script_nodes(list) ⇒ Object
A number of tree nodes return lists that have strings and Sass::Script::Nodes interspersed within them.
Instance Attribute Details
#node_parent ⇒ Object
Stores node for which this node is a direct child
12 13 14 |
# File 'lib/scss_lint/sass/tree.rb', line 12 def node_parent @node_parent end |
Instance Method Details
#add_line_number(node) ⇒ Object
The Sass parser sometimes doesn’t assign line numbers in cases where it should. This is a helper to easily correct that.
25 26 27 28 |
# File 'lib/scss_lint/sass/tree.rb', line 25 def add_line_number(node) node.line ||= line if node.is_a?(::Sass::Script::Tree::Node) node end |
#add_line_numbers_to_args(arg_list) ⇒ Object
The ‘args` field of some Sass::Tree::Node classes returns Sass::Script::Variable nodes with no line numbers. This adds the line numbers back in so lint reporting works for those nodes.
17 18 19 20 21 |
# File 'lib/scss_lint/sass/tree.rb', line 17 def add_line_numbers_to_args(arg_list) arg_list.each do |variable, _default_expr| add_line_number(variable) end end |
#concat_expr_lists(*expr_lists) ⇒ Object
Takes a list of arguments, be they arrays or individual objects, and returns a single flat list that can be passed to Sass::Tree::Visitors::Base#visit_children.
49 50 51 |
# File 'lib/scss_lint/sass/tree.rb', line 49 def concat_expr_lists(*expr_lists) expr_lists.flatten.compact end |
#create_variable(var_name) ⇒ Object
Sometimes the parse tree doesn’t return a Sass::Script::Variable, but just the name of the variable. This helper takes that name and turns it back into a Sass::Script::Variable that supports lint reporting.
33 34 35 36 37 |
# File 'lib/scss_lint/sass/tree.rb', line 33 def create_variable(var_name) ::Sass::Script::Tree::Variable.new(var_name).tap do |v| v.line = line # Use line number of the containing parse tree node end end |
#extract_script_nodes(list) ⇒ Object
A number of tree nodes return lists that have strings and Sass::Script::Nodes interspersed within them. This returns a filtered list of just those nodes.
42 43 44 |
# File 'lib/scss_lint/sass/tree.rb', line 42 def extract_script_nodes(list) list.select { |item| item.is_a?(::Sass::Script::Tree::Node) } end |