erb-formatter 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/exe/erb-format +2 -66
- data/exe/erb-formatter +5 -0
- data/lib/erb/formatter/command_line.rb +81 -0
- data/lib/erb/formatter.rb +4 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ce05292fc99dcfeb80526b22aa762325c40589640086886190cf40d534facd
|
4
|
+
data.tar.gz: faecec389f0cd92c85e1300d9c32920ac76f508e0fc37b7c2e6a5449b5d7db35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13dfae2c05ecbb7f283ed1e76e1239dbad2923f1b0bc63b5d67e8de229ea3dfd97fe11d3d51734a2a33382a0d5a566dd16e8b2d8c73cc334eb8e424b685a7e3b
|
7
|
+
data.tar.gz: 64b9b47e1a6dd2c324c8167daf9dafcc0126950e0ae509088e19abc9ffb51b14bfd21cefb98aaf538e2c4a46bf5073fbab90c187e02e7831aa32024d55529ca1
|
data/exe/erb-format
CHANGED
@@ -1,69 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
write, filename, read_stdin, code = nil
|
6
|
-
|
7
|
-
OptionParser.new do |parser|
|
8
|
-
parser.banner = "Usage: #{$0} FILENAME... --write"
|
9
|
-
|
10
|
-
parser.on("-w", "--[no-]write", "Write file") do |value|
|
11
|
-
write = value
|
12
|
-
end
|
13
|
-
|
14
|
-
parser.on("--stdin-filename FILEPATH", "Set the stdin filename (implies --stdin)") do |value|
|
15
|
-
filename = value
|
16
|
-
read_stdin = true
|
17
|
-
end
|
18
|
-
|
19
|
-
parser.on("--[no-]stdin", "Read the file from stdin") do |value|
|
20
|
-
if read_stdin == true && value == false
|
21
|
-
abort "Can't set stdin filename and not use stdin at the same time"
|
22
|
-
end
|
23
|
-
|
24
|
-
read_stdin = value
|
25
|
-
filename ||= '-'
|
26
|
-
end
|
27
|
-
|
28
|
-
parser.on("--[no-]debug", "Enable debug mode") do |value|
|
29
|
-
$DEBUG = value
|
30
|
-
end
|
31
|
-
|
32
|
-
parser.on("-h", "--help", "Prints this help") do
|
33
|
-
puts parser
|
34
|
-
exit
|
35
|
-
end
|
36
|
-
end.parse!(ARGV)
|
37
|
-
|
38
|
-
abort "Can't read both stdin and a list of files" if read_stdin && !ARGV.empty?
|
39
|
-
|
40
|
-
# If multiple files are provided assume `--write` and
|
41
|
-
# execute on each of them.
|
42
|
-
if ARGV.size > 1
|
43
|
-
ARGV.each do |arg|
|
44
|
-
warn "==> Formatting #{arg}..."
|
45
|
-
system __FILE__, arg, *[
|
46
|
-
('--write' if write)
|
47
|
-
].compact or exit(1)
|
48
|
-
end
|
49
|
-
exit
|
50
|
-
end
|
51
|
-
|
52
|
-
require 'erb/formatter'
|
53
|
-
|
54
|
-
filename ||= ARGV.first
|
55
|
-
code = read_stdin ? $stdin.read : File.read(filename)
|
56
|
-
ignore = ERB::Formatter::IgnoreList.new
|
57
|
-
|
58
|
-
if ignore.should_ignore_file? filename
|
59
|
-
print code unless write
|
60
|
-
else
|
61
|
-
html = ERB::Formatter.format(code, filename: filename)
|
62
|
-
|
63
|
-
if write
|
64
|
-
File.write(filename, html)
|
65
|
-
else
|
66
|
-
puts html
|
67
|
-
end
|
68
|
-
end
|
3
|
+
require 'erb/formatter/command_line'
|
69
4
|
|
5
|
+
ERB::Formatter::CommandLine.new(ARGV).run
|
data/exe/erb-formatter
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require 'erb/formatter'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
class ERB::Formatter::CommandLine
|
6
|
+
|
7
|
+
attr_reader :write, :filename, :read_stdin
|
8
|
+
|
9
|
+
def initialize(argv, stdin: $stdin)
|
10
|
+
@argv = argv.dup
|
11
|
+
@stdin = stdin
|
12
|
+
|
13
|
+
@write, @filename, @read_stdin, @code = nil
|
14
|
+
|
15
|
+
OptionParser.new do |parser|
|
16
|
+
parser.banner = "Usage: #{$0} FILENAME... --write"
|
17
|
+
|
18
|
+
parser.on("-w", "--[no-]write", "Write file") do |value|
|
19
|
+
@write = value
|
20
|
+
end
|
21
|
+
|
22
|
+
parser.on("--stdin-filename FILEPATH", "Set the stdin filename (implies --stdin)") do |value|
|
23
|
+
@filename = value
|
24
|
+
@read_stdin = true
|
25
|
+
end
|
26
|
+
|
27
|
+
parser.on("--[no-]stdin", "Read the file from stdin") do |value|
|
28
|
+
if read_stdin == true && value == false
|
29
|
+
abort "Can't set stdin filename and not use stdin at the same time"
|
30
|
+
end
|
31
|
+
|
32
|
+
@read_stdin = value
|
33
|
+
@filename ||= '-'
|
34
|
+
end
|
35
|
+
|
36
|
+
parser.on("--[no-]debug", "Enable debug mode") do |value|
|
37
|
+
$DEBUG = value
|
38
|
+
end
|
39
|
+
|
40
|
+
parser.on("-h", "--help", "Prints this help") do
|
41
|
+
puts parser
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
end.parse!(@argv)
|
45
|
+
end
|
46
|
+
|
47
|
+
def ignore_list
|
48
|
+
@ignore_list ||= ERB::Formatter::IgnoreList.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def ignore?(filename)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
if read_stdin
|
57
|
+
abort "Can't read both stdin and a list of files" unless @argv.empty?
|
58
|
+
files = [
|
59
|
+
[@filename, @stdin.read]
|
60
|
+
]
|
61
|
+
else
|
62
|
+
files = @argv.map do |filename|
|
63
|
+
[filename, File.read(filename)]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
files.each do |(filename, code)|
|
68
|
+
if ignore_list.should_ignore_file? filename
|
69
|
+
print code unless write
|
70
|
+
else
|
71
|
+
html = ERB::Formatter.format(code, filename: filename)
|
72
|
+
|
73
|
+
if write
|
74
|
+
File.write(filename, html)
|
75
|
+
else
|
76
|
+
puts html
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/erb/formatter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
+
require 'pp'
|
3
4
|
require "erb"
|
4
5
|
require "ripper"
|
5
6
|
require 'securerandom'
|
@@ -7,7 +8,8 @@ require 'strscan'
|
|
7
8
|
require 'stringio'
|
8
9
|
|
9
10
|
class ERB::Formatter
|
10
|
-
VERSION = "0.
|
11
|
+
VERSION = "0.3.0"
|
12
|
+
|
11
13
|
autoload :IgnoreList, 'erb/formatter/ignore_list'
|
12
14
|
|
13
15
|
class Error < StandardError; end
|
@@ -340,7 +342,7 @@ class ERB::Formatter
|
|
340
342
|
self.pre_pos = scanner.charpos
|
341
343
|
|
342
344
|
# Don't accept `name= "value"` attributes
|
343
|
-
raise "Bad attribute, please fix spaces after the equal sign
|
345
|
+
raise "Bad attribute, please fix spaces after the equal sign:\n#{pre_match}" if BAD_ATTR.match? pre_match
|
344
346
|
|
345
347
|
format_erb_tags(pre_match) if pre_match
|
346
348
|
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rufo
|
@@ -29,6 +29,7 @@ email:
|
|
29
29
|
- elia@schito.me
|
30
30
|
executables:
|
31
31
|
- erb-format
|
32
|
+
- erb-formatter
|
32
33
|
extensions: []
|
33
34
|
extra_rdoc_files: []
|
34
35
|
files:
|
@@ -39,7 +40,9 @@ files:
|
|
39
40
|
- Rakefile
|
40
41
|
- erb-formatter.gemspec
|
41
42
|
- exe/erb-format
|
43
|
+
- exe/erb-formatter
|
42
44
|
- lib/erb/formatter.rb
|
45
|
+
- lib/erb/formatter/command_line.rb
|
43
46
|
- lib/erb/formatter/ignore_list.rb
|
44
47
|
- lib/erb/formatter/version.rb
|
45
48
|
- sig/erb/formatter.rbs
|