rubyn 0.1.3 → 0.1.5
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/lib/rubyn/context/file_applier.rb +3 -11
- data/lib/rubyn/context/response_parser.rb +17 -7
- data/lib/rubyn/engine/app/assets/javascripts/rubyn/application.js +10 -7
- data/lib/rubyn/engine/app/assets/stylesheets/rubyn/application.css +5 -0
- data/lib/rubyn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 36a16de7cb6802b6a29f1a5ac6f4b6688cd5761c5ac9d3cf90986842885f3e26
|
|
4
|
+
data.tar.gz: de2d885c2cd2ba5828817b4242de06b5c05296aa264546e017d3fdf06c9e9bac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cdc367ce9ff58c530f3c6fcb5ddacddcc0e7af44763258e62c4226f5531fe5b8d5b8608fa305800be01a2397241c9191e83c31f75114589a3d814da68337c3d
|
|
7
|
+
data.tar.gz: 504ae8345f735d6476576f40b16d84cb5959e3732f29c7a145a06f0c5ae7b665abd3a25bd6d13c3513c8eec31d9caad3272510b155b7508ca23be6b530b02019
|
|
@@ -18,14 +18,6 @@ module Rubyn
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def new_file?(path)
|
|
22
|
-
return false unless path
|
|
23
|
-
|
|
24
|
-
path != @original_file &&
|
|
25
|
-
!path.end_with?("/#{@original_file}") &&
|
|
26
|
-
!@original_file.end_with?("/#{path}")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
21
|
private
|
|
30
22
|
|
|
31
23
|
def apply_single(code)
|
|
@@ -50,7 +42,7 @@ module Rubyn
|
|
|
50
42
|
@formatter.info("This refactor produces #{file_blocks.length} file(s):")
|
|
51
43
|
file_blocks.each do |block|
|
|
52
44
|
path = block[:path] || @original_file
|
|
53
|
-
label =
|
|
45
|
+
label = block[:tag] == "new" ? "NEW" : "MODIFIED"
|
|
54
46
|
@formatter.info(" [#{label}] #{path}")
|
|
55
47
|
end
|
|
56
48
|
|
|
@@ -69,7 +61,7 @@ module Rubyn
|
|
|
69
61
|
|
|
70
62
|
def apply_selected(block)
|
|
71
63
|
path = block[:path] || @original_file
|
|
72
|
-
label =
|
|
64
|
+
label = block[:tag] == "new" ? "NEW" : "MODIFIED"
|
|
73
65
|
print " Apply [#{label}] #{path}? (y/n/diff) "
|
|
74
66
|
choice = $stdin.gets&.strip&.downcase
|
|
75
67
|
|
|
@@ -77,7 +69,7 @@ module Rubyn
|
|
|
77
69
|
when "y"
|
|
78
70
|
write_block(block)
|
|
79
71
|
when "diff"
|
|
80
|
-
existing =
|
|
72
|
+
existing = block[:tag] == "new" ? "" : File.read(resolve_path(block))
|
|
81
73
|
Rubyn::Output::DiffRenderer.render(original: existing, modified: block[:code])
|
|
82
74
|
print " Apply? (y/n) "
|
|
83
75
|
write_block(block) if $stdin.gets&.strip&.downcase == "y"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Rubyn
|
|
4
4
|
module Context
|
|
5
5
|
class ResponseParser
|
|
6
|
-
BOLD_HEADER = /\*\*(
|
|
6
|
+
BOLD_HEADER = /\*\*(New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i
|
|
7
7
|
BACKTICK_PATH = /`([a-zA-Z0-9_\/\.\-]+\.rb)`\s*\z/
|
|
8
8
|
INLINE_COMMENT = /^#\s*([a-zA-Z0-9_\/\.\-]+\.rb)/
|
|
9
9
|
|
|
@@ -24,9 +24,9 @@ module Rubyn
|
|
|
24
24
|
|
|
25
25
|
code = part.sub(/\A```ruby\n/, "").sub(/```\z/, "")
|
|
26
26
|
preceding = i > 0 ? parts[i - 1] : ""
|
|
27
|
-
|
|
27
|
+
result = detect_path(preceding, code)
|
|
28
28
|
|
|
29
|
-
blocks << { path: path, code: code }
|
|
29
|
+
blocks << { path: result[:path], tag: result[:tag], code: code }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
blocks
|
|
@@ -37,19 +37,29 @@ module Rubyn
|
|
|
37
37
|
def detect_path(preceding_text, code)
|
|
38
38
|
match_bold_header(preceding_text) ||
|
|
39
39
|
match_backtick_path(preceding_text) ||
|
|
40
|
-
match_inline_comment(code)
|
|
40
|
+
match_inline_comment(code) ||
|
|
41
|
+
{ path: nil, tag: nil }
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def match_bold_header(text)
|
|
44
|
-
text.match(BOLD_HEADER)
|
|
45
|
+
m = text.match(BOLD_HEADER)
|
|
46
|
+
return nil unless m
|
|
47
|
+
|
|
48
|
+
{ path: m[2], tag: m[1].downcase }
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
def match_backtick_path(text)
|
|
48
|
-
text.match(BACKTICK_PATH)
|
|
52
|
+
m = text.match(BACKTICK_PATH)
|
|
53
|
+
return nil unless m
|
|
54
|
+
|
|
55
|
+
{ path: m[1], tag: nil }
|
|
49
56
|
end
|
|
50
57
|
|
|
51
58
|
def match_inline_comment(code)
|
|
52
|
-
code.lines.first&.strip&.match(INLINE_COMMENT)
|
|
59
|
+
m = code.lines.first&.strip&.match(INLINE_COMMENT)
|
|
60
|
+
return nil unless m
|
|
61
|
+
|
|
62
|
+
{ path: m[1], tag: nil }
|
|
53
63
|
end
|
|
54
64
|
end
|
|
55
65
|
end
|
|
@@ -297,20 +297,22 @@
|
|
|
297
297
|
var fileChanges = codeBlocks.map(function(code, i) {
|
|
298
298
|
var header = fileHeaders[i];
|
|
299
299
|
var path = (header && header.path) ? header.path : file;
|
|
300
|
-
var
|
|
300
|
+
var tag = header ? header.tag : null;
|
|
301
301
|
return {
|
|
302
302
|
path: path,
|
|
303
|
-
|
|
303
|
+
tag: tag,
|
|
304
304
|
code: code
|
|
305
305
|
};
|
|
306
306
|
});
|
|
307
307
|
|
|
308
|
-
// Show each code block with its file path and
|
|
308
|
+
// Show each code block with its file path and tag badge
|
|
309
309
|
fileChanges.forEach(function(change, i) {
|
|
310
310
|
html += '<div class="rubyn-code-block">';
|
|
311
311
|
html += '<div class="rubyn-code-block-header">';
|
|
312
|
-
if (change.
|
|
312
|
+
if (change.tag === "new") {
|
|
313
313
|
html += '<span class="rubyn-file-tag rubyn-tag-new">NEW</span>';
|
|
314
|
+
} else if (change.tag === "updated" || change.tag === "modified") {
|
|
315
|
+
html += '<span class="rubyn-file-tag rubyn-tag-updated">UPDATED</span>';
|
|
314
316
|
}
|
|
315
317
|
html += '<span class="rubyn-tool-filepath">' + escapeHtml(change.path) + '</span>';
|
|
316
318
|
html += '<div class="rubyn-code-block-actions">';
|
|
@@ -488,11 +490,12 @@
|
|
|
488
490
|
var code = parts[i].replace(/^```ruby\n/, "").replace(/```$/, "");
|
|
489
491
|
var preceding = i > 0 ? parts[i - 1] : "";
|
|
490
492
|
var path = null;
|
|
493
|
+
var tag = null;
|
|
491
494
|
|
|
492
495
|
// Strategy 1: Bold header (**New file: path.rb**, **Updated file: path.rb**)
|
|
493
496
|
// Only match when preceded by New/Updated/Modified to avoid matching bold .rb references in prose
|
|
494
|
-
var boldMatch = preceding.match(/\*\*(
|
|
495
|
-
if (boldMatch)
|
|
497
|
+
var boldMatch = preceding.match(/\*\*(New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i);
|
|
498
|
+
if (boldMatch) { tag = boldMatch[1].toLowerCase(); path = boldMatch[2]; }
|
|
496
499
|
|
|
497
500
|
// Strategy 3: Backtick-wrapped path above code block
|
|
498
501
|
if (!path) {
|
|
@@ -507,7 +510,7 @@
|
|
|
507
510
|
if (commentMatch) path = commentMatch[1];
|
|
508
511
|
}
|
|
509
512
|
|
|
510
|
-
headers.push({ path: path });
|
|
513
|
+
headers.push({ path: path, tag: tag });
|
|
511
514
|
}
|
|
512
515
|
|
|
513
516
|
return headers;
|
data/lib/rubyn/version.rb
CHANGED