Module: Jade::Formatter::ModuleNode
- Extended by:
- Helper, ModuleNode
- Included in:
- ModuleNode
- Defined in:
- lib/jade/formatter/module_node.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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jade/formatter/module_node.rb', line 7 def format(node, indent:, source:) node => AST::Module(name:, exposing:, body:) chunks = body.expressions .chunk_while { |a, b| (a in AST::ImportDeclaration) && (b in AST::ImportDeclaration) } .map { |group| group.map { format_node(it, indent:, source:) }.join("\n") } header = "module #{name} #{format_exposing(exposing)}" # Two blank lines between top-level chunks so def-to-def boundaries # don't blur with blank lines inside a def body. Module header to # the first chunk stays one blank line. chunks.empty? ? header : "#{header}\n\n#{chunks.join("\n\n\n")}" end |