Module: SyntaxTree::RemoveBreaks
- Defined in:
- lib/syntax_tree/node.rb
Overview
This module will remove any breakables from the list of contents so that no newlines are present in the output.
Class Method Summary collapse
Class Method Details
.call(doc) ⇒ Object
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 |
# File 'lib/syntax_tree/node.rb', line 1948 def call(doc) marker = Object.new stack = [doc] while stack.any? doc = stack.pop if doc == marker stack.pop next end stack += [doc, marker] case doc when PrettyPrint::Align, PrettyPrint::Indent, PrettyPrint::Group doc.contents.map! { |child| remove_breaks(child) } stack += doc.contents.reverse when PrettyPrint::IfBreak doc.flat_contents.map! { |child| remove_breaks(child) } stack += doc.flat_contents.reverse end end end |