Class: PrettierPrint::Breakable

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

Overview

A node in the print tree that represents a place in the buffer that the content can be broken onto multiple lines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(separator = " ", width = separator.length, force: false, indent: true) ⇒ Breakable

Returns a new instance of Breakable.



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/prettier_print.rb', line 85

def initialize(
  separator = " ",
  width = separator.length,
  force: false,
  indent: true
)
  @separator = separator
  @width = width
  @force = force
  @indent = indent
end

Instance Attribute Details

#separatorObject (readonly)

Returns the value of attribute separator.



83
84
85
# File 'lib/prettier_print.rb', line 83

def separator
  @separator
end

#widthObject (readonly)

Returns the value of attribute width.



83
84
85
# File 'lib/prettier_print.rb', line 83

def width
  @width
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/prettier_print.rb', line 97

def force?
  @force
end

#indent?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/prettier_print.rb', line 101

def indent?
  @indent
end

#pretty_print(q) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/prettier_print.rb', line 105

def pretty_print(q)
  q.text("breakable")

  attributes = [
    ("force=true" if force?),
    ("indent=false" unless indent?)
  ].compact

  if attributes.any?
    q.text("(")
    q.seplist(attributes, -> { q.text(", ") }) do |attribute|
      q.text(attribute)
    end
    q.text(")")
  end
end