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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a406bccd1e8bba621fd7465b792b8630c2dd586118d9116e1ad178061fe39dd
4
- data.tar.gz: a49480476f8293d38a2998a0df0f6b1144ccc477dec6982ac853038a93866d0a
3
+ metadata.gz: 36a16de7cb6802b6a29f1a5ac6f4b6688cd5761c5ac9d3cf90986842885f3e26
4
+ data.tar.gz: de2d885c2cd2ba5828817b4242de06b5c05296aa264546e017d3fdf06c9e9bac
5
5
  SHA512:
6
- metadata.gz: a68aa5fac1c7c708e678976e89818bc0cc108ab1b4e902d6f32ec82d71872ddea82f060db656d9829fa095cba6655b9de3b24464ec8d151fcfbf4846fde8fe83
7
- data.tar.gz: edb357abf5f2e8e0c106fe35a22866db7c4a70dda97d5edc9b90ff8c93077d99d1e148f780346b5ba90b7b88cdb9ba900ef8e610e0b62186dbdb4703258af8d6
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 = new_file?(path) ? "NEW" : "MODIFIED"
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 = new_file?(path) ? "NEW" : "MODIFIED"
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 = new_file?(path) ? "" : File.read(resolve_path(block))
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 = /\*\*(?:New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i
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
- path = detect_path(preceding, code)
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)&.[](1)
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)&.[](1)
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)&.[](1)
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 isNew = !!(path && file && path !== file && path.indexOf(file) === -1 && file.indexOf(path) === -1);
300
+ var tag = header ? header.tag : null;
301
301
  return {
302
302
  path: path,
303
- isNew: isNew,
303
+ tag: tag,
304
304
  code: code
305
305
  };
306
306
  });
307
307
 
308
- // Show each code block with its file path and NEW badge if applicable
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.isNew) {
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(/\*\*(?:New|Updated|Modified)\s*(?:file)?:\s*([a-zA-Z0-9_\/\.\-]+\.rb)\*\*/i);
495
- if (boldMatch) path = boldMatch[1];
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;
@@ -735,6 +735,11 @@ body {
735
735
  color: var(--rubyn-success);
736
736
  }
737
737
 
738
+ .rubyn-tag-updated {
739
+ background: var(--rubyn-primary-soft);
740
+ color: var(--rubyn-primary);
741
+ }
742
+
738
743
 
739
744
  .rubyn-code-block .rubyn-tool-output {
740
745
  margin: 0;
data/lib/rubyn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubyn
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - matthewsuttles