Class: PrettierPrint::LineSuffix

Inherits:
Object
  • Object
show all
Defined in:
lib/prettier_print.rb

Overview

A node in the print tree that has its own special buffer for implementing content that should flush before any newline.

Useful for implementating trailing content, as it’s not always practical to constantly check where the line ends to avoid accidentally printing some content after a line suffix node.

Constant Summary collapse

DEFAULT_PRIORITY =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(priority: DEFAULT_PRIORITY, contents: []) ⇒ LineSuffix

Returns a new instance of LineSuffix.



225
226
227
228
# File 'lib/prettier_print.rb', line 225

def initialize(priority: DEFAULT_PRIORITY, contents: [])
  @priority = priority
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



223
224
225
# File 'lib/prettier_print.rb', line 223

def contents
  @contents
end

#priorityObject (readonly)

Returns the value of attribute priority.



223
224
225
# File 'lib/prettier_print.rb', line 223

def priority
  @priority
end

Instance Method Details

#pretty_print(q) ⇒ Object



230
231
232
233
234
# File 'lib/prettier_print.rb', line 230

def pretty_print(q)
  q.group(2, "line-suffix([", "])") do
    q.seplist(contents) { |content| q.pp(content) }
  end
end