compose 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d36eebaf01309fb4c0762dcbc6665e48704c47efdcc53d705a959eca780cbc2f
4
- data.tar.gz: d109de09f9b08947aa5b17a3f67ce4e050854cc123a69d4ae95c791586e0e719
3
+ metadata.gz: 3ac262b371cf1ff49a50e94ea83aaf75e7867564341c3bd3bff024c77831c2b4
4
+ data.tar.gz: 8577e99ba4dc26f7cd96a40589bb4c75cca3394e6e3302d8d43c9786df4633dd
5
5
  SHA512:
6
- metadata.gz: 657a0b56b8e25976c901be35c47d531947f524eef84e2696d9ebd0cdea8468b19ec1517b3eca803d49d4dac88e4a37b819695d3a8226bb323171fdeff8d38dd8
7
- data.tar.gz: 72e63f67707c80f0287d5faab11e611e08f4910640e02be9c570738a11bfa939f4adba9c64a2ecd1cf9684c06fcdd5327f181fd1ebce40d2e1bde61ceee8c70e
6
+ metadata.gz: 5db9243359a8045ca48620bb0fb9f5dc0876fe763c01f0e3fba2cf46467b1feffc42d69afd35857aa1398b0977a8d0478fef6a338c847b0ef43651a934b386f3
7
+ data.tar.gz: 3e4de964ef36267bf768eba57c09d58e7037ae17e7313e61b068bb4611bb688ef914757b805a20d3ba7e4cc2a07f156d31bcb6270a0aebbca29a7708e2aa08a1
@@ -7,6 +7,8 @@ Facts:
7
7
  2. Leave toLine empty for additions.
8
8
  3. Make sure the code snippet in the edit is complete. Feel free to make multiple edits, avoid repeating existing code if you can.
9
9
  4. Ensure the line numbers are accurate. Feel free to repeat existing code from previous or after lines to be sure.
10
+ 5. When adding new code to the end of a file, make sure to repeat the last
11
+ line of the file in the edit before adding a new line.
10
12
 
11
13
  ```json
12
14
  {
@@ -10,7 +10,10 @@ Verify this change:
10
10
  {{CHANGE}}
11
11
  ```
12
12
 
13
- and make sure it's needed and it's only replacing the correct lines, or adding the code to the correct place. Feel free to change additions to replacements or vice versa, or skip edits if they're not needed.
13
+ and make sure it's needed and it's only replacing the correct lines, or adding
14
+ the code to the correct place. Feel free to change additions to replacements
15
+ or vice versa, fix atLine, fromLineNumber, toLineNumber if they would produce
16
+ duplicated code lines, `or skip edits if they're not needed.
14
17
  Return only the fixed change object following this JSON spec:
15
18
 
16
19
  ```json
@@ -86,7 +86,7 @@ module Compose
86
86
 
87
87
  case edit[:change][:type]
88
88
  when 'addition'
89
- new_content.insert(edit[:change][:atLine] - 1, edit[:code])
89
+ new_content.insert(edit[:change][:atLine] - 1, edit[:code].split("\n").map { |line| line + "\n" })
90
90
  when 'replacement'
91
91
  new_content[edit[:change][:fromLineNumber] - 1..edit[:change][:toLineNumber] - 1] = edit[:code].split("\n").map { |line| line + "\n" }
92
92
  end
@@ -109,7 +109,7 @@ module Compose
109
109
  case edit[:change][:type]
110
110
  when 'addition'
111
111
  adjusted_line = edit[:change][:atLine] + line_offset
112
- content.insert(adjusted_line - 1, edit[:code])
112
+ content.insert(adjusted_line - 1, edit[:code].split("\n").map { |line| line + "\n" })
113
113
  line_offset += edit[:code].count("\n") + 1
114
114
  when 'replacement'
115
115
  from_line = edit[:change][:fromLineNumber] + line_offset
@@ -121,6 +121,8 @@ module Compose
121
121
  end
122
122
  end
123
123
 
124
+ content = content.flatten
125
+
124
126
  FileUtils.mkdir_p(File.dirname(filename))
125
127
  File.write(filename, content.join)
126
128
  puts "Applied changes to #{filename}".green
@@ -2,6 +2,11 @@
2
2
 
3
3
  require 'find'
4
4
  require 'pathname'
5
+ require 'httparty'
6
+ require 'nokogiri'
7
+ require 'reverse_markdown'
8
+ require 'digest/md5'
9
+ require 'fileutils'
5
10
 
6
11
  module Compose
7
12
  class FileProcessor
@@ -25,21 +30,19 @@ module Compose
25
30
  @files = {}
26
31
 
27
32
  input_files.each do |input|
28
- if File.directory?(input)
33
+ if input.start_with?('http://', 'https://')
34
+ @files[input] = process_url(input)
35
+ elsif File.directory?(input)
29
36
  find_files_in_directory(input).each do |file|
30
- @files[File.expand_path(file)] = nil
37
+ @files[File.expand_path(file)] = FileProcessor.load_file(file, include_imports: include_imports)
31
38
  end
32
39
  elsif File.file?(input)
33
- @files[File.expand_path(input)] = nil
40
+ @files[File.expand_path(input)] = FileProcessor.load_file(file, include_imports: include_imports)
34
41
  else
35
42
  puts "Skipping invalid input: #{input}".yellow
36
43
  end
37
44
  end
38
45
 
39
- @files.each do |file, _|
40
- @files[file] = FileProcessor.load_file(file, include_imports: include_imports)
41
- end
42
-
43
46
  self
44
47
  end
45
48
 
@@ -97,5 +100,33 @@ module Compose
97
100
  rescue
98
101
  false
99
102
  end
103
+
104
+ def process_url(url)
105
+ cached_file = File.join(ENV['HOME'], '.compose', 'cache', Digest::MD5.hexdigest(url))
106
+ content = if File.exist?(cached_file)
107
+ File.read(cached_file)
108
+ else
109
+ content = fetch_and_convert_url(url)
110
+ return if content.nil?
111
+
112
+ FileUtils.mkdir_p(File.dirname(cached_file))
113
+ File.write(cached_file, content)
114
+ content
115
+ end
116
+ return if content.nil?
117
+
118
+ "<url src='#{url}'>\n#{content}\n</url>"
119
+ end
120
+
121
+ def fetch_and_convert_url(url)
122
+ response = HTTParty.get(url, follow_redirects: true)
123
+ return nil if response.code != 200
124
+
125
+ doc = Nokogiri::HTML(response.body)
126
+ doc.search('script, style').remove
127
+ parsed_markdown = ReverseMarkdown.convert(doc.to_html, unknown_tags: :bypass)
128
+ normalized_markdown = parsed_markdown.gsub(/\s+/, ' ').strip
129
+ normalized_markdown
130
+ end
100
131
  end
101
132
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Compose
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dreaming Tulpa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-11 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -164,6 +164,62 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: httparty
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: nokogiri
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: reverse_markdown
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: digest
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
167
223
  - !ruby/object:Gem::Dependency
168
224
  name: bundler
169
225
  requirement: !ruby/object:Gem::Requirement