diff options
Diffstat (limited to 'new/lib/crys/builder.rb')
-rw-r--r-- | new/lib/crys/builder.rb | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb index b8135c77..123935a6 100644 --- a/new/lib/crys/builder.rb +++ b/new/lib/crys/builder.rb @@ -1,39 +1,46 @@ +# frozen_string_literal: true + module Crys class Builder - def initialize(file_path:, output_dir:, image_dir:) + def initialize(file_path:, output_dir:, image_dir:, pages_db_manager:) @file_path = file_path @output_dir = output_dir - @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + @image_dir = image_dir + @pages_db_manager = pages_db_manager end - def build + def build + @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + process_content process_assets - - upsert_pages_db end private - attr_reader :file_path, :output_dir, :processor, :db + attr_reader :file_path, :output_dir, :processor, :db, :image_dir, :pages_db_manager + - def pages_db_manager - Crys::PagesDbManager.new - end - def process_assets processor.assets.each do |asset| - output_path = output_dir + "/" + asset.relative_path - File.open(output_path, 'w') { |file| file.write(asset.processed_asset) } + output_path = "#{output_dir}/#{asset.relative_path}" + File.write(output_path, asset.processed_asset) end end def process_content - content = processor.parsed_content - filename = processor.filename - output_path = output_dir + "/" + filename + processor.parsed_pages.each do |page| + path = output_dir + "/" + File.dirname(page.filename) + FileUtils.mkdir_p(path) + + content = page.content + filename = page.filename + output_path = "#{output_dir}/#{filename}" + pages_db_manager.add_page(page) + File.write(output_path, content) + end - File.open(output_path, 'w') { |file| file.write(content) } + pages_db_manager.save end def processor_class @@ -42,8 +49,10 @@ module Crys html_processor when /xml.rb$/ rss_processor + when /yaml$/ + yaml_batch_processor else - raise StandardError.new("No processor for #{file_path}") + raise StandardError, "No processor for #{file_path}" end end @@ -55,8 +64,8 @@ module Crys Crys::RssProcessor end - def upsert_pages_db - pages_db_manager.add_page(processor) + def yaml_batch_processor + Crys::YamlBatchProcessor end end end |