compose 0.1.6 → 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: '0181e80bc473a0e67c074cc18b299be97ecad391875a7578780a3f8a93286cdc'
4
- data.tar.gz: a4d171f396fd690387c122958565eb047efd3b0ef11c99acd6fc6e557a78f1e4
3
+ metadata.gz: 3ac262b371cf1ff49a50e94ea83aaf75e7867564341c3bd3bff024c77831c2b4
4
+ data.tar.gz: 8577e99ba4dc26f7cd96a40589bb4c75cca3394e6e3302d8d43c9786df4633dd
5
5
  SHA512:
6
- metadata.gz: 172b6babed118da8b989bffb8dad311eef02a27c21200df782fccf29783d929559ca44e98023c4ac2e3607e1ece53a36e7490834c9fc09aaffe82aaf8dfc94ec
7
- data.tar.gz: 89b5cd472edfe13a5007e753d23bca1be694ae056314f71376f442af323de21e1bdcf395c0560445534172c22a7304185df21d0b1835c7e65f05c26c325bf050
6
+ metadata.gz: 5db9243359a8045ca48620bb0fb9f5dc0876fe763c01f0e3fba2cf46467b1feffc42d69afd35857aa1398b0977a8d0478fef6a338c847b0ef43651a934b386f3
7
+ data.tar.gz: 3e4de964ef36267bf768eba57c09d58e7037ae17e7313e61b068bb4611bb688ef914757b805a20d3ba7e4cc2a07f156d31bcb6270a0aebbca29a7708e2aa08a1
@@ -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.6'
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.6
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