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.rb48
1 files changed, 31 insertions, 17 deletions
diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb
index a3f55b1..3b1ed38 100644
--- a/new/lib/crys/builder.rb
+++ b/new/lib/crys/builder.rb
@@ -1,50 +1,64 @@
+# frozen_string_literal: true
module Crys
class Builder
-
-
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)
-
end
def build
- process_html
+ process_content
process_assets
+
+ upsert_pages_db
end
private
- attr_reader :file_path, :output_dir, :processor
+ attr_reader :file_path, :output_dir, :processor, :db
+
+ 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_html
- html = processor.to_html
+ def process_content
+ content = processor.parsed_content
filename = processor.filename
- output_path = output_dir + "/" + filename
+ output_path = "#{output_dir}/#{filename}"
- File.open(output_path, 'w') { |file| file.write(html) }
+ File.write(output_path, content)
end
- def processor_class
- case file_path
- when /html.erb$/
- html_processor
- else
- raise StandardError.new("No processor for #{file_path}")
+ def processor_class
+ case file_path
+ when /html.erb$/
+ html_processor
+ when /xml.rb$/
+ rss_processor
+ else
+ raise StandardError, "No processor for #{file_path}"
end
end
def html_processor
Crys::HtmlProcessor
end
+
+ def rss_processor
+ Crys::RssProcessor
+ end
+
+ def upsert_pages_db
+ pages_db_manager.add_page(processor)
+ end
end
end