summaryrefslogtreecommitdiff
path: root/new/lib/crys/builder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'new/lib/crys/builder.rb')
-rw-r--r--new/lib/crys/builder.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb
index ee4fb8ce..123935a6 100644
--- a/new/lib/crys/builder.rb
+++ b/new/lib/crys/builder.rb
@@ -2,10 +2,11 @@
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
@image_dir = image_dir
+ @pages_db_manager = pages_db_manager
end
def build
@@ -13,17 +14,12 @@ module Crys
process_content
process_assets
-
- upsert_pages_db
end
private
- attr_reader :file_path, :output_dir, :processor, :db, :image_dir
+ 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|
@@ -34,12 +30,17 @@ module Crys
def process_content
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
+
+ pages_db_manager.save
end
def processor_class
@@ -48,6 +49,8 @@ module Crys
html_processor
when /xml.rb$/
rss_processor
+ when /yaml$/
+ yaml_batch_processor
else
raise StandardError, "No processor for #{file_path}"
end
@@ -61,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