Skip to content

Commit 534e37c

Browse files
committed
refactor: remove facade
Refactored RSS feed handling in app.rb to eliminate the Html2rssFacade. Merged configuration directly into request handlers, simplifying the feed generation process. This change enhances performance by reducing method calls and improves readability by consolidating logic. Removed unused helper files related to the facade, cleaning up the codebase. Signed-off-by: Gil Desmarais <[email protected]>
1 parent 3cd3756 commit 534e37c

File tree

5 files changed

+29
-143
lines changed

5 files changed

+29
-143
lines changed

app.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,38 @@ def self.development? = ENV['RACK_ENV'] == 'development'
8484
end
8585

8686
r.on String, String do |folder_name, config_name_with_ext|
87-
handle_html2rss_configs(request, folder_name, config_name_with_ext)
87+
response['Content-Type'] = CONTENT_TYPE_RSS
88+
89+
name = "#{folder_name}/#{File.basename(config_name_with_ext, '.*')}"
90+
config = Html2rss::Configs.find_by_name(name).dup
91+
92+
if (params = request.params).any?
93+
config[:params] ||= {}
94+
config[:params].merge!(params)
95+
end
96+
97+
feed = Html2rss.feed(config)
98+
99+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
100+
101+
feed.to_s
88102
end
89103

90104
r.on String do |config_name_with_ext|
91-
handle_local_config_feeds(request, config_name_with_ext)
105+
response['Content-Type'] = CONTENT_TYPE_RSS
106+
107+
config = LocalConfig.find(File.basename(config_name_with_ext, '.*'))
108+
109+
if (params = request.params).any?
110+
config[:params] ||= {}
111+
config[:params].merge!(params)
112+
end
113+
114+
feed = Html2rss.feed(config)
115+
116+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
117+
118+
feed.to_s
92119
end
93120
end
94121

app/html2rss_facade.rb

Lines changed: 0 additions & 77 deletions
This file was deleted.

helpers/handle_html2rss_configs.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

helpers/handle_local_config_feeds.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

spec/html2rss/web/app/html2rss_facade_spec.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)