Module: Jade::Formatter::Implementation

Extended by:
Helper, Implementation
Included in:
Implementation
Defined in:
lib/jade/formatter/declarations.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



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/jade/formatter/declarations.rb', line 149

def format(node, indent:, source:)
  node => AST::Implementation(interface:, applied_type:, extends:, functions:)

  extends_str = extends.empty? ? "" : " extends #{extends.join(', ')}"
  header = "implements #{interface}(#{format_type(applied_type)})" \
    "#{extends_str} with"
  fns_str = functions
    .map { format_node(it, indent: indent + 1, source:) }
    .join(",\n")

  [
    header.then(&and_indent(indent)),
    fns_str,
    "end".then(&and_indent(indent)),
  ].join("\n")
end