erb-formatter 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a21bdecce12179abd027c94e06f28e708323ef5217e1a45c43302e72c9334d9c
4
- data.tar.gz: c4f1dc0e38523170c62a2e4c474140da3b988741a0fe8f983b766738730b63eb
3
+ metadata.gz: b4d4aa4df0dfb6331993b2586513da76d3c4bb9443f536e5738adf68ef1cbb37
4
+ data.tar.gz: 0d6a144fd792f2eb78fb6a7112f49e330aae42a6c4b5de0b3b2fe42f6fb513d6
5
5
  SHA512:
6
- metadata.gz: c1377c919438c3db88d2398d9eef2e259c4fd36e9ad0299e1d5e0892a387389468ea8a7ba083a9575ef5b3814330f08bb549f2fe2e36b61266a58a1b63524b1d
7
- data.tar.gz: 9976eaea39da84cfca194851430428224c393bc8cd1e39ebe2b8833b7c57832911b6057415201d00bd00bd5956a5be7d6c197464233b80bc83e92482e0d0db2a
6
+ metadata.gz: 5db13cddb929dec25486feafd48261068365d4f6847e514ec1c99df903d45bd036e4fa82b54c4de08534af079e8d1dd7c879c282595cb2f539b0e07a44fda135
7
+ data.tar.gz: 4bacbaecf5078bc4fc43c89cdc183a5883522a23e015a7642fc6b56384bfa34440585a1afb7964e8643db2492d325994eaf6f0d41d2f790a4ddfd81add43e774
data/README.md CHANGED
@@ -119,6 +119,23 @@ let g:ale_fixers = {
119
119
  \}
120
120
  ```
121
121
 
122
+ ### With [Zed](https://zed.dev/) editor
123
+
124
+ With the gem installed, configure `settings.json` to use the formatter as an external command
125
+
126
+ ```json
127
+ "language_overrides": {
128
+ "ERB": {
129
+ "formatter": {
130
+ "external": {
131
+ "command": "erb-format",
132
+ "arguments": ["--stdin", "--print-width", "80"]
133
+ }
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
122
139
  ## Development
123
140
 
124
141
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,5 +3,5 @@
3
3
  require 'erb'
4
4
 
5
5
  class ERB::Formatter
6
- VERSION = "0.7.1"
6
+ VERSION = "0.7.2"
7
7
  end
data/lib/erb/formatter.rb CHANGED
@@ -26,9 +26,11 @@ class ERB::Formatter
26
26
 
27
27
  class Error < StandardError; end
28
28
 
29
+ SPACES = /\s+/m
30
+
29
31
  # https://stackoverflow.com/a/317081
30
32
  ATTR_NAME = %r{[^\r\n\t\f\v= '"<>]*[^\r\n\t\f\v= '"<>/]} # not ending with a slash
31
- UNQUOTED_VALUE = ATTR_NAME
33
+ UNQUOTED_VALUE = %r{[^<>'"\s]+}
32
34
  UNQUOTED_ATTR = %r{#{ATTR_NAME}=#{UNQUOTED_VALUE}}
33
35
  SINGLE_QUOTE_ATTR = %r{(?:#{ATTR_NAME}='[^']*?')}m
34
36
  DOUBLE_QUOTE_ATTR = %r{(?:#{ATTR_NAME}="[^"]*?")}m
@@ -136,17 +138,18 @@ class ERB::Formatter
136
138
  attrs.scan(ATTR).flatten.each do |attr|
137
139
  attr.strip!
138
140
  name, value = attr.split('=', 2)
139
- if UNQUOTED_ATTR =~ attr
140
- attr_html << indented("#{name}=\"#{value}\"")
141
- next
142
- end
143
141
 
144
142
  if value.nil?
145
143
  attr_html << indented("#{name}")
146
144
  next
147
145
  end
148
146
 
149
- value_parts = value[1...-1].strip.split(/\s+/)
147
+ if /\A#{UNQUOTED_VALUE}\z/o.match?(value)
148
+ attr_html << indented("#{name}=\"#{value}\"")
149
+ next
150
+ end
151
+
152
+ value_parts = value[1...-1].strip.split(SPACES)
150
153
  value_parts.sort_by!(&@css_class_sorter) if name == 'class' && @css_class_sorter
151
154
 
152
155
  full_attr = "#{name}=#{value[0]}#{value_parts.join(" ")}#{value[-1]}"
@@ -231,7 +234,7 @@ class ERB::Formatter
231
234
 
232
235
  return if text.match?(/\A\s*\z/m) # empty
233
236
 
234
- text = text.gsub(/\s+/m, ' ').strip
237
+ text = text.gsub(SPACES, ' ').strip
235
238
 
236
239
  offset = indented("").size
237
240
  # Restore full line width if there are less than 40 columns available
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.5.3
99
+ rubygems_version: 3.5.4
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Format ERB files with speed and precision.