Module: Jade::Formatter::StructDeclaration
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jade/formatter/declarations.rb', line 63
def format(node, indent:, source:)
node => AST::StructDeclaration(name:, type_params:, record_type:)
params_str = type_params.empty? ?
"" :
"(#{type_params.map(&:name).join(', ')})"
= "struct #{name}#{params_str} ="
record_type => AST::TypeRecord(fields:, row_var:)
if fields.size > 1
format_multiline(, fields, row_var, indent)
else
"#{} #{format_type(record_type)}".then(&and_indent(indent))
end
end
|
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/jade/formatter/declarations.rb', line 80
def format_multiline(, fields, row_var, indent)
open_brace = row_var ? "{ #{row_var.name} |" : "{"
fields_str = fields
.map { |k, v| "#{k}: #{format_type(v)}".then(&and_indent(indent + 1)) }
.join(",\n")
and_indent(indent)
.call("#{} #{open_brace}")
.then { "#{it}\n#{fields_str}\n#{INDENT * indent}}" }
end
|