diff options
Diffstat (limited to 'new/lib/crys/builder.rb')
-rw-r--r-- | new/lib/crys/builder.rb | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb index a3f55b15..b8135c77 100644 --- a/new/lib/crys/builder.rb +++ b/new/lib/crys/builder.rb @@ -1,24 +1,26 @@ - 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 @@ -26,19 +28,21 @@ module Crys end end - def process_html - html = processor.to_html + def process_content + content = processor.parsed_content filename = processor.filename output_path = output_dir + "/" + filename - File.open(output_path, 'w') { |file| file.write(html) } + File.open(output_path, 'w') { |file| file.write(content) } end - def processor_class - case file_path - when /html.erb$/ - html_processor - else + def processor_class + case file_path + when /html.erb$/ + html_processor + when /xml.rb$/ + rss_processor + else raise StandardError.new("No processor for #{file_path}") end end @@ -46,5 +50,13 @@ module Crys 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 |