Repository navigation
Indent ERB views with htmlbeautifier when saving - #5
Merged
Merged
Conversation
Format ERB on Save indents HTML views (.html.erb) with htmlbeautifier, with the document's tab settings, keeping one blank line between blocks, unless TM_ERB_FORMAT_ON_SAVE is false. htmlbeautifier runs with Bundler when the bundle has it, or as installed for the project's Ruby; without it, views are saved as they are. Views with invalid nesting are left, with a tool tip. Formatted text is applied through TextMate (mate --lsp workspace/applyEdit), which replaces only the lines that change, so the caret and bookmarks stay; Format Document's RuboCop fallback does the same now, rather than replacing the document. Support/lib/rubocop.sh is now format.sh, and runs gems with ruby_gem_executable, which tells when one is not installed for the Ruby of the project. The tests run the commands as script files, as TextMate does, on macOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
callback.document.will-save, scopetext.html.erb) indents HTML views with htmlbeautifier..html.erbfiles, including variants such as.html+phone.erb. Mailer text views and other ERB files are left alone.--tab-stops Nor--tab) and passes--keep-blank-lines 1, because htmlbeautifier removes every blank line by default. It also passes--stop-on-errors: a view with a closing tag that has no opening tag is saved unchanged, with a tool tip saying where.TM_ERB_FORMAT_ON_SAVE = falseturns it off.TM_HTMLBEAUTIFIERandTM_HTMLBEAUTIFIER_OPTIONSset the command and add options.mate --lsp workspace/applyEdit(built withosascript), so TextMate replaces only the lines that change. With Pair lines that differ only in white space when applying edits textmate#13, the caret and bookmarks also stay on re-indented lines. Untitled documents, or a TextMate that can't apply the edit, get the whole document replaced as before (exit 202). Format Document's RuboCop CLI fallback now works the same way.Support/lib/rubocop.shbecomesformat.sh.ruby_gem_executable GEM …runs RuboCop and htmlbeautifier the same way (TM_«GEM», Bundler, mise) and returns 127 when the tool isn't installed. The temporary folder is shared.osascript.Test plan
ruby Support/test/test_format.rb: 18 runs, 0 failures, 0 skips. New tests cover:🤖 Generated with Claude Code