erb-formatter 0.7.0 → 0.7.2
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.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/erb/formatter/version.rb +1 -1
- data/lib/erb/formatter.rb +10 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d4aa4df0dfb6331993b2586513da76d3c4bb9443f536e5738adf68ef1cbb37
|
4
|
+
data.tar.gz: 0d6a144fd792f2eb78fb6a7112f49e330aae42a6c4b5de0b3b2fe42f6fb513d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 =
|
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
|
-
|
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(
|
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.
|
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:
|
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.
|
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.
|