erb-formatter 0.7.0 → 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: a91fb15a3934ccb7a9589ebfefd60bd2b95610acb90259358a26239a34d7a3cb
4
- data.tar.gz: 576ac293a9932d8c81d2ef9a62cd98fc3a39a01da9c3b8ac7919438768e18c28
3
+ metadata.gz: b4d4aa4df0dfb6331993b2586513da76d3c4bb9443f536e5738adf68ef1cbb37
4
+ data.tar.gz: 0d6a144fd792f2eb78fb6a7112f49e330aae42a6c4b5de0b3b2fe42f6fb513d6
5
5
  SHA512:
6
- metadata.gz: 460305512646f76855effa266fb439083e571f9d14538e2b6417e00fec52859c2311d7ab2e2e44d32164320cb868d8d94e7c3118b2a855fd8270dfbb66303d17
7
- data.tar.gz: 9de4c93e2cf39ab24cf0b882b7c23291f812d9685fb6618b8787f425433288c1c3b9d4f3208118abedf54a193d01715734b3edbd523a8e694840a4eecd1230ba
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.0"
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
@@ -142,7 +144,12 @@ class ERB::Formatter
142
144
  next
143
145
  end
144
146
 
145
- 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)
146
153
  value_parts.sort_by!(&@css_class_sorter) if name == 'class' && @css_class_sorter
147
154
 
148
155
  full_attr = "#{name}=#{value[0]}#{value_parts.join(" ")}#{value[-1]}"
@@ -227,7 +234,7 @@ class ERB::Formatter
227
234
 
228
235
  return if text.match?(/\A\s*\z/m) # empty
229
236
 
230
- text = text.gsub(/\s+/m, ' ').strip
237
+ text = text.gsub(SPACES, ' ').strip
231
238
 
232
239
  offset = indented("").size
233
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.0
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: 2023-12-29 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.