summaryrefslogtreecommitdiff
path: root/new/lib
diff options
context:
space:
mode:
authormms <git@sapka.me>2025-01-08 22:20:17 +0100
committermms <git@sapka.me>2025-01-08 22:20:17 +0100
commit3d13bedaaffdae466621788d808a6b71b9ed9f59 (patch)
tree5e941bb44ad7cd37252459bfe48d57778b76342a /new/lib
parent4004a55b0e324c35cbc7d58b831e49efd484ab93 (diff)
feat: batch-first
Diffstat (limited to 'new/lib')
-rw-r--r--new/lib/crys.rb1
-rw-r--r--new/lib/crys/builder.rb18
-rw-r--r--new/lib/crys/processors/html_processor.rb20
-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.rb6
-rw-r--r--new/lib/crys/processors/rss_processor.rb13
7 files changed, 43 insertions, 19 deletions
diff --git a/new/lib/crys.rb b/new/lib/crys.rb
index eea74fa7..f1aac2d8 100644
--- a/new/lib/crys.rb
+++ b/new/lib/crys.rb
@@ -4,6 +4,7 @@ require 'bundler/setup'
require_relative 'crys/processors/html_processor'
require_relative 'crys/processors/rss_processor'
+require_relative 'crys/processors/processed_page'
require_relative 'crys/server'
require_relative 'crys/builder'
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