Class: HamlLint::Tree::SilentScriptNode

Inherits:
Node
  • Object
show all
Defined in:
lib/haml_lint/tree/silent_script_node.rb

Overview

Represents a HAML silent script node (‘- some_expression`) which executes code without producing output.

Instance Attribute Summary

Attributes inherited from Node

#children, #line, #parent, #type

Instance Method Summary collapse

Methods inherited from Node

#comment_configuration, #directives, #disabled?, #each, #initialize, #inspect, #keyword, #line_numbers, #lines, #next_node, #predecessor, #source_code, #subsequents, #successor, #text

Constructor Details

This class inherits a constructor from HamlLint::Tree::Node

Instance Method Details

#parsed_scriptParsedRuby

The Ruby script contents parsed into a syntax tree.

Returns:

  • (ParsedRuby)

    syntax tree in the form returned by Parser gem



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/haml_lint/tree/silent_script_node.rb', line 10

def parsed_script
  statement =
    case keyword = @value[:keyword]
    when 'else', 'elsif'
      'if 0;' + script + ';end'
    when 'when'
      'case;' + script + ';end'
    when 'rescue', 'ensure'
      'begin;' + script + ';end'
    else
      if children.empty?
        script
      else
        "#{script}#{keyword == 'case' ? ';when 0;end' : ';end'}"
      end
    end
  HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(statement))
end

#scriptString

Returns the source for the script following the ‘-` marker.

Returns:

  • (String)


32
33
34
# File 'lib/haml_lint/tree/silent_script_node.rb', line 32

def script
  @value[:text]
end