diff options
author | mms <git@sapka.me> | 2025-01-08 22:20:17 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2025-01-08 22:20:17 +0100 |
commit | 3d13bedaaffdae466621788d808a6b71b9ed9f59 (patch) | |
tree | 5e941bb44ad7cd37252459bfe48d57778b76342a /new/lib/crys | |
parent | 4004a55b0e324c35cbc7d58b831e49efd484ab93 (diff) |
feat: batch-first
Diffstat (limited to 'new/lib/crys')
-rw-r--r-- | new/lib/crys/builder.rb | 18 | ||||
-rw-r--r-- | new/lib/crys/processors/html_processor.rb | 20 | ||||
-rw-r--r-- | new/lib/crys/processors/mixins/common_functions.rb (renamed from new/lib/crys/processors/common_functions.rb) | 4 | ||||
-rw-r--r-- | new/lib/crys/processors/mixins/common_parts.rb (renamed from new/lib/crys/processors/common_parts.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/processors/processed_page.rb | 6 | ||||
-rw-r--r-- | new/lib/crys/processors/rss_processor.rb | 13 |
6 files changed, 42 insertions, 19 deletions
diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb index 3b1ed388..ee4fb8ce 100644 --- a/new/lib/crys/builder.rb +++ b/new/lib/crys/builder.rb @@ -5,10 +5,12 @@ module Crys def initialize(file_path:, output_dir:, image_dir:) @file_path = file_path @output_dir = output_dir - @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + @image_dir = image_dir end - def build + def build + @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + process_content process_assets @@ -17,7 +19,7 @@ module Crys private - attr_reader :file_path, :output_dir, :processor, :db + attr_reader :file_path, :output_dir, :processor, :db, :image_dir def pages_db_manager Crys::PagesDbManager.new @@ -31,11 +33,13 @@ module Crys end def process_content - content = processor.parsed_content - filename = processor.filename - output_path = "#{output_dir}/#{filename}" + processor.parsed_pages.each do |page| + content = page.content + filename = page.filename + output_path = "#{output_dir}/#{filename}" - File.write(output_path, content) + File.write(output_path, content) + end end def processor_class diff --git a/new/lib/crys/processors/html_processor.rb b/new/lib/crys/processors/html_processor.rb index 33116cef..5dd1387f 100644 --- a/new/lib/crys/processors/html_processor.rb +++ b/new/lib/crys/processors/html_processor.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -require 'erb' -require_relative 'common_functions' -require_relative 'common_parts' +require_relative 'mixins/common_functions' +require_relative 'mixins/common_parts' module Crys class HtmlProcessor @@ -15,15 +14,24 @@ module Crys @assets = [] end - def parsed_content - html_file = ERB.new(File.read(file_path)) - html_file.result(local_binding) + def parsed_pages + [ + ProcessedPage.new( + filename: filename, + content: html_content + ) + ] end def filename file_path.scan(%r{.*/(.*)\.erb}).flatten.first end + def html_content + html_file = ERB.new(File.read(file_path)) + html_file.result(local_binding) + end + attr_reader :assets, :file_path private diff --git a/new/lib/crys/processors/common_functions.rb b/new/lib/crys/processors/mixins/common_functions.rb index 9cf56692..52ce65ac 100644 --- a/new/lib/crys/processors/common_functions.rb +++ b/new/lib/crys/processors/mixins/common_functions.rb @@ -5,10 +5,10 @@ require 'rss' module Crys module CommonFunctions def project_root - File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))).to_s + File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))).to_s end - def process_image(file:, width: :auto) + def process_image(file:, width: :auto) full_path = "#{image_dir}/#{file}" image = ::Crys::ImageProcessor.new(path: full_path, filename: file, width: width) diff --git a/new/lib/crys/processors/common_parts.rb b/new/lib/crys/processors/mixins/common_parts.rb index a6c2dc16..a6c2dc16 100644 --- a/new/lib/crys/processors/common_parts.rb +++ b/new/lib/crys/processors/mixins/common_parts.rb diff --git a/new/lib/crys/processors/processed_page.rb b/new/lib/crys/processors/processed_page.rb new file mode 100644 index 00000000..5bab3566 --- /dev/null +++ b/new/lib/crys/processors/processed_page.rb @@ -0,0 +1,6 @@ +module Crys + ProcessedPage = Struct.new( + :filename, + :content + ) +end diff --git a/new/lib/crys/processors/rss_processor.rb b/new/lib/crys/processors/rss_processor.rb index de79f11b..4806c594 100644 --- a/new/lib/crys/processors/rss_processor.rb +++ b/new/lib/crys/processors/rss_processor.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'common_functions' -require_relative 'common_parts' +require_relative 'mixins/common_functions' +require_relative 'mixins/common_parts' module Crys class RssProcessor @@ -13,8 +13,13 @@ module Crys @image_dir = image_dir # just for api consistency end - def parsed_content - rss.content + def parsed_pages + [ + ProcessedPage.new( + filename: rss.filename, + content: rss.content + ) + ] end def filename |