torture 0.0.2 → 0.0.3
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/CHANGES.md +6 -0
- data/lib/torture/snippet.rb +82 -26
- data/lib/torture/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aff3c08d8cd95104a55ad3dc537155ede021cdb199409b8c29a5559016cf0e2a
|
4
|
+
data.tar.gz: fb60c30209e3952b38c7913887050f9f4aaae1103483e03810cb1985b1d25733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00323374d686a6be90492708332cb232a605cab2a946b14cb67ce44f6e06afac5019c5dcf7901ad05019e0ed2e2fe2de670b4ada0edeaea8597df991998d77ce
|
7
|
+
data.tar.gz: 6af6813f27bb19e0e1edc442abb30cd4373a3ad2cc7f4726e5d46b9008ba377fce759a03ca1f566a4df6caa994395fde06d4af2972bc86b5067e7217f50d4469
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.0.3
|
2
|
+
|
3
|
+
* Introduce the `:zoom` option that can show a class header/end plus a "zoomed"
|
4
|
+
section.
|
5
|
+
* Fix a bug with `:collapse`, when the collapse marker had index `0`.
|
6
|
+
|
1
7
|
# 0.0.2
|
2
8
|
|
3
9
|
* Introduce the `:sub` option for `#snippet` to erase unwanted code parts.
|
data/lib/torture/snippet.rb
CHANGED
@@ -6,40 +6,31 @@ module Torture
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# @param :collapse name of the #~collapse marker that will be displayed as `# ...`.
|
9
|
-
def self.extract(input, marker:, collapse:nil, unindent:false, sub: nil)
|
10
|
-
|
11
|
-
ignore = false
|
12
|
-
indent = 0
|
9
|
+
def self.extract(input, marker:, collapse:nil, unindent:false, sub: nil, zoom: nil)
|
10
|
+
input_lines = input.each_line.to_a
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
break if ln =~ /\#:#{marker} end/
|
12
|
+
content_lines, first_line = extract_marker_section(input_lines, marker: marker)
|
13
|
+
raise "Couldn't find #{marker}" unless first_line
|
17
14
|
|
18
|
-
|
19
|
-
if ln =~ /\#:#{marker}$/
|
20
|
-
code = ""
|
21
|
-
indent = ln.match(/(^\s+)/) { |m| m[0].size } || 0
|
22
|
-
end
|
15
|
+
indent = first_line.match(/(^\s+)/) { |m| m[0].size } || 0 # FIXME: what if there's no first line?
|
23
16
|
|
24
|
-
|
17
|
+
if zoom
|
18
|
+
content_lines = zoom(content_lines, zoom: zoom)
|
19
|
+
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
code << ln.sub("#~#{collapse}", "# ...")
|
29
|
-
end
|
21
|
+
if collapse
|
22
|
+
count = content_lines.find_all { |ln| ln =~ /\#~#{collapse}$/ }.size # FIXME: hm, this is private.
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
next
|
24
|
+
count.times do
|
25
|
+
content_lines = collapse(content_lines, collapse: collapse)
|
34
26
|
end
|
35
|
-
|
36
|
-
next if ignore
|
37
|
-
next if ln =~ /#~/
|
38
|
-
next if ln =~ /#:/
|
39
|
-
code << ln and next
|
40
27
|
end
|
41
28
|
|
42
|
-
|
29
|
+
# remove foreign delimiters
|
30
|
+
content_lines = content_lines.reject { |ln| ln =~ /#~/ }
|
31
|
+
content_lines = content_lines.reject { |ln| ln =~ /#:/ }
|
32
|
+
|
33
|
+
code = content_lines.join("")
|
43
34
|
|
44
35
|
code = unindent(code, indent) if unindent == true
|
45
36
|
code = sub(code, sub) if sub
|
@@ -47,6 +38,71 @@ module Torture
|
|
47
38
|
code
|
48
39
|
end
|
49
40
|
|
41
|
+
def self.detect_marker_section(input, delimiter:)
|
42
|
+
start_i, stop_i = nil, nil
|
43
|
+
|
44
|
+
input.each.with_index do |ln, i|
|
45
|
+
# end of our section?
|
46
|
+
if ln =~ /\##{delimiter} end/
|
47
|
+
stop_i = i
|
48
|
+
break
|
49
|
+
end
|
50
|
+
|
51
|
+
# beginning of our section?
|
52
|
+
if ln =~ /\##{delimiter}$/
|
53
|
+
start_i = i
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
[start_i, stop_i]
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.extract_marker_section(input, marker:, delimiter: ":#{marker}")
|
61
|
+
start_i, stop_i = detect_marker_section(input, delimiter: delimiter)
|
62
|
+
return if start_i.nil?
|
63
|
+
|
64
|
+
marker_section = input[start_i + 1..stop_i - 1]
|
65
|
+
|
66
|
+
return marker_section, input[start_i]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.marker_to_dotdotdot(line, delimiter:)
|
70
|
+
line.sub("##{delimiter}", "# ...")
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.zoom(input, zoom:, zoom_frame: [0..0, -1..-1])
|
74
|
+
delimiter = "~#{zoom}"
|
75
|
+
zoomed_section, first_line = extract_marker_section(input, marker: nil, delimiter: delimiter)
|
76
|
+
|
77
|
+
before_range, after_range = zoom_frame # DISCUSS: do we need that?
|
78
|
+
|
79
|
+
content = []
|
80
|
+
content += input[before_range]
|
81
|
+
content << dotdotdot = marker_to_dotdotdot(first_line, delimiter: delimiter)
|
82
|
+
content += zoomed_section
|
83
|
+
content << dotdotdot
|
84
|
+
content += input[after_range]
|
85
|
+
|
86
|
+
content
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.collapse(input, collapse:)
|
90
|
+
delimiter = "~#{collapse}"
|
91
|
+
|
92
|
+
start_i, stop_i = detect_marker_section(input, delimiter: delimiter)
|
93
|
+
|
94
|
+
|
95
|
+
content = if start_i == 0
|
96
|
+
[] # if the #~skip start is index == 0, don't collect anything "before" (because there isn't anything).
|
97
|
+
# TODO: is there a Ruby idiom for this?
|
98
|
+
else
|
99
|
+
input[0..start_i - 1]
|
100
|
+
end
|
101
|
+
|
102
|
+
content << marker_to_dotdotdot(input[start_i], delimiter: delimiter)
|
103
|
+
content += input[stop_i + 1..-1]
|
104
|
+
end
|
105
|
+
|
50
106
|
# Strip {indent} characters of whitespace from each line beginning.
|
51
107
|
def self.unindent(code, indent)
|
52
108
|
code.gsub(/^ {#{indent}}/, "")
|
data/lib/torture/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|