Module: Jade::Formatter::RecordUpdate
- Extended by:
- Helper, RecordUpdate
- Included in:
- RecordUpdate
- Defined in:
- lib/jade/formatter/collections.rb
Instance Method Summary collapse
Methods included from Helper
and_indent, dispatch_for, format_delimited, format_exposing, format_leading_comments, format_node, format_pattern, format_trailing_comment, format_type, format_type_atom, too_long?
Instance Method Details
#format(node, indent:, source:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jade/formatter/collections.rb', line 60 def format(node, indent:, source:) node => AST::RecordUpdate(base:, fields:, trailing_comma:) base_str = format_node(base, source:) field_strs = fields.map { "#{it.key}: #{format_node(it.value, source:)}" } inline = "{ #{base_str} | #{field_strs.join(', ')} }" if trailing_comma || too_long?(inline, indent) inner = field_strs .map { "#{it.then(&and_indent(indent + 1))}," } .join("\n") "#{INDENT * indent}{ #{base_str} |\n#{inner}\n#{INDENT * indent}}" else inline.then(&and_indent(indent)) end end |