@herb-tools/formatter 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,11 +13,52 @@ export declare class Printer extends Visitor {
13
13
  private indentLevel;
14
14
  private inlineMode;
15
15
  private isInComplexNesting;
16
+ private currentTagName;
17
+ private static readonly INLINE_ELEMENTS;
16
18
  constructor(source: string, options: Required<FormatOptions>);
17
19
  print(object: Node | Token, indentLevel?: number): string;
18
20
  private push;
19
21
  private withIndent;
20
22
  private indent;
23
+ /**
24
+ * Format ERB content with proper spacing around the inner content.
25
+ * Returns empty string if content is empty, otherwise wraps content with single spaces.
26
+ */
27
+ private formatERBContent;
28
+ /**
29
+ * Check if a node is an ERB control flow node (if, unless, block, case, while, for)
30
+ */
31
+ private isERBControlFlow;
32
+ /**
33
+ * Count total attributes including those inside ERB conditionals
34
+ */
35
+ private getTotalAttributeCount;
36
+ /**
37
+ * Extract HTML attributes from a list of nodes
38
+ */
39
+ private extractAttributes;
40
+ /**
41
+ * Extract inline nodes (non-attribute, non-whitespace) from a list of nodes
42
+ */
43
+ private extractInlineNodes;
44
+ /**
45
+ * Render attributes as a space-separated string
46
+ */
47
+ private renderAttributesString;
48
+ /**
49
+ * Determine if a tag should be rendered inline based on attribute count and other factors
50
+ */
51
+ private shouldRenderInline;
52
+ private hasMultilineAttributes;
53
+ private formatClassAttribute;
54
+ private isFormattableAttribute;
55
+ private formatMultilineAttribute;
56
+ private formatMultilineAttributeValue;
57
+ private breakTokensIntoLines;
58
+ /**
59
+ * Render multiline attributes for a tag
60
+ */
61
+ private renderMultilineAttributes;
21
62
  /**
22
63
  * Print an ERB tag (<% %> or <%= %>) with single spaces around inner content.
23
64
  */
@@ -52,13 +93,36 @@ export declare class Printer extends Visitor {
52
93
  visitERBEnsureNode(node: ERBEnsureNode): void;
53
94
  visitERBUnlessNode(node: ERBUnlessNode): void;
54
95
  private visitERBGeneric;
96
+ private isNonWhitespaceNode;
97
+ /**
98
+ * Check if an element should be treated as inline based on its tag name
99
+ */
100
+ private isInlineElement;
101
+ /**
102
+ * Check if we're in a text flow context (parent contains mixed text and inline elements)
103
+ */
104
+ private visitTextFlowChildren;
105
+ private visitTextFlowChildrenMultiline;
106
+ private isInTextFlowContext;
55
107
  private renderInlineOpen;
56
108
  renderAttribute(attribute: HTMLAttributeNode): string;
109
+ /**
110
+ * Try to render a complete element inline including opening tag, children, and closing tag
111
+ */
112
+ private tryRenderInlineFull;
113
+ /**
114
+ * Try to render just the children inline (without tags)
115
+ */
116
+ private tryRenderChildrenInline;
57
117
  /**
58
118
  * Try to render children inline if they are simple enough.
59
119
  * Returns the inline string if possible, null otherwise.
60
120
  */
61
121
  private tryRenderInline;
122
+ /**
123
+ * Estimate the total content length of children nodes for decision making.
124
+ */
125
+ private estimateContentLength;
62
126
  /**
63
127
  * Calculate the maximum nesting depth in a subtree of nodes.
64
128
  */
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@herb-tools/formatter",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
+ "description": "Auto-formatter for HTML+ERB templates with intelligent indentation, line wrapping, and ERB-aware pretty-printing.",
4
5
  "license": "MIT",
5
6
  "homepage": "https://herb-tools.dev",
6
7
  "bugs": "https://github.com/marcoroth/herb/issues/new?title=Package%20%60@herb-tools/formatter%60:%20",
@@ -34,7 +35,7 @@
34
35
  }
35
36
  },
36
37
  "dependencies": {
37
- "@herb-tools/core": "0.4.2",
38
+ "@herb-tools/core": "0.5.0",
38
39
  "glob": "^11.0.3"
39
40
  },
40
41
  "files": [
package/src/cli.ts CHANGED
@@ -27,11 +27,11 @@ export class CLI {
27
27
 
28
28
  Examples:
29
29
  herb-format # Format all **/*.html.erb files in current directory
30
- herb-format --check # Check if all **/*.html.erb files are formatted
30
+ herb-format templates/ # Format and **/*.html.erb within the given directory
31
31
  herb-format templates/index.html.erb # Format and write single file
32
+ herb-format --check # Check if all **/*.html.erb files are formatted
32
33
  herb-format --check templates/ # Check if all **/*.html.erb files in templates/ are formatted
33
34
  cat template.html.erb | herb-format # Format from stdin to stdout
34
- herb-format - < template.html.erb # Format from stdin to stdout
35
35
  `
36
36
 
37
37
  async run() {