diff options
author | mms <git@sapka.me> | 2025-01-08 22:20:17 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2025-01-08 22:20:17 +0100 |
commit | 3d13bedaaffdae466621788d808a6b71b9ed9f59 (patch) | |
tree | 5e941bb44ad7cd37252459bfe48d57778b76342a | |
parent | 4004a55b0e324c35cbc7d58b831e49efd484ab93 (diff) |
feat: batch-first
l--------- | new/.#.rubocop | 1 | ||||
l--------- | new/.#.rubocop_todo.yml | 1 | ||||
-rw-r--r-- | new/bin/builder.rb | 22 | ||||
-rw-r--r-- | new/lib/crys.rb | 1 | ||||
-rw-r--r-- | new/lib/crys/builder.rb | 18 | ||||
-rw-r--r-- | new/lib/crys/processors/html_processor.rb | 20 | ||||
-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.rb | 6 | ||||
-rw-r--r-- | new/lib/crys/processors/rss_processor.rb | 13 | ||||
l--------- | new/splash/bin/.#build.rb | 1 | ||||
-rwxr-xr-x | new/splash/bin/build.rb | 18 | ||||
-rw-r--r-- | new/splash/db/pages.yaml | 4 | ||||
-rw-r--r-- | new/splash/lib/splash.rb | 1 | ||||
-rw-r--r-- | new/splash/lib/splash/batch_builder.rb | 8 | ||||
-rw-r--r-- | new/splash/pages/index.html.erb | 3 | ||||
-rw-r--r-- | new/splash/pages/index.xml.rb | 1 |
17 files changed, 64 insertions, 58 deletions
diff --git a/new/.#.rubocop b/new/.#.rubocop deleted file mode 120000 index 0f727030..00000000 --- a/new/.#.rubocop +++ /dev/null @@ -1 +0,0 @@ -mms@voyager.local.6355:1735980208
\ No newline at end of file diff --git a/new/.#.rubocop_todo.yml b/new/.#.rubocop_todo.yml deleted file mode 120000 index 0f727030..00000000 --- a/new/.#.rubocop_todo.yml +++ /dev/null @@ -1 +0,0 @@ -mms@voyager.local.6355:1735980208
\ No newline at end of file diff --git a/new/bin/builder.rb b/new/bin/builder.rb index 7172cf85..b5f5270b 100644 --- a/new/bin/builder.rb +++ b/new/bin/builder.rb @@ -22,27 +22,23 @@ end.parse! module Crys class BuilderRunner - def initialize(file_path:, image_dir:, output_dir:, builder_class:, batch_builder_class:, theme_dir:, pages_db:) - @file_path = file_path - @output_dir = output_dir - @builder_class = builder_class - @batch_builder_class = batch_builder_class - @image_dir = image_dir - @theme_dir = theme_dir - @pages_db = pages_db + def initialize(batch_builder:, builder:, batch:) + @builder = builder + @batch_builder = batch_builder + @batch = batch end def run - if file_path == :all - batch_builder_class.new(pages_db: pages_db, output_dir: output_dir, image_dir: image_dir, - builder_class: builder_class).build + p batch + if batch + batch_builder.build else - builder_class.new(file_path: file_path, output_dir: output_dir, image_dir: image_dir).build + builder.build end end private - attr_reader :builder_class, :file_path, :output_dir, :image_dir, :batch_builder_class, :theme_dir, :pages_db + attr_reader :builder, :batch_builder, :batch end end 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 diff --git a/new/splash/bin/.#build.rb b/new/splash/bin/.#build.rb deleted file mode 120000 index 0f727030..00000000 --- a/new/splash/bin/.#build.rb +++ /dev/null @@ -1 +0,0 @@ -mms@voyager.local.6355:1735980208
\ No newline at end of file diff --git a/new/splash/bin/build.rb b/new/splash/bin/build.rb index 7f5ac93f..38b87f55 100755 --- a/new/splash/bin/build.rb +++ b/new/splash/bin/build.rb @@ -4,21 +4,19 @@ require_relative '../lib/splash' require_relative '../../bin/builder' -builder_class = Crys::Splash::Builder -batch_builder_class = Crys::Splash::BatchBuilder output_dir = "#{File.dirname(File.dirname(__FILE__))}/output" image_dir = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/assets/images" -theme_dir = "#{File.dirname(File.dirname(__FILE__))}/theme" pages_db = Crys::Splash::PagesDbManager file_path = @options[:filepath] +batch = file_path == :all + +builder = Crys::Splash::Builder.new(file_path: file_path, output_dir: output_dir, image_dir: image_dir) +batch_builder = Crys::BatchBuilder.new(pages_db: pages_db, output_dir: output_dir, image_dir: image_dir, + builder_class: Crys::Splash::Builder) Crys::BuilderRunner.new( - file_path: file_path, - output_dir: output_dir, - builder_class: builder_class, - image_dir: image_dir, - batch_builder_class: batch_builder_class, - theme_dir: theme_dir, - pages_db: pages_db + builder: builder, + batch_builder: batch_builder, + batch: batch ).run diff --git a/new/splash/db/pages.yaml b/new/splash/db/pages.yaml index a0d51655..9d438881 100644 --- a/new/splash/db/pages.yaml +++ b/new/splash/db/pages.yaml @@ -3,10 +3,10 @@ d5d3594a0e43df11c58fad58073dc288: :filename: index.html :file_path: "/home/mms/ghq/michal.sapka.me/mms/site/new/splash/pages/index.html.erb" - :last_update: 2025-01-08 21:08:36.876579930 +01:00 + :last_update: 2025-01-08 22:18:17.593730099 +01:00 :in_rss: false b6bd1d5c7d2d3ea1d0db3032235af0bf: :filename: index.xml :file_path: "/home/mms/ghq/michal.sapka.me/mms/site/new/splash/pages/index.xml.rb" - :last_update: 2025-01-08 21:08:36.895155483 +01:00 + :last_update: 2025-01-08 22:19:55.857164931 +01:00 :in_rss: false diff --git a/new/splash/lib/splash.rb b/new/splash/lib/splash.rb index 5a299566..cf354740 100644 --- a/new/splash/lib/splash.rb +++ b/new/splash/lib/splash.rb @@ -4,7 +4,6 @@ require_relative '../../lib/crys' require_relative 'splash/server' require_relative 'splash/builder' -require_relative 'splash/batch_builder' require_relative 'splash/pages_db_manager' module Crys diff --git a/new/splash/lib/splash/batch_builder.rb b/new/splash/lib/splash/batch_builder.rb deleted file mode 100644 index 71f5594b..00000000 --- a/new/splash/lib/splash/batch_builder.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -module Crys - module Splash - class BatchBuilder < Crys::BatchBuilder - end - end -end diff --git a/new/splash/pages/index.html.erb b/new/splash/pages/index.html.erb index a23c8ff8..5614cb73 100644 --- a/new/splash/pages/index.html.erb +++ b/new/splash/pages/index.html.erb @@ -1,6 +1,6 @@ <!DOCTYPE html> - <html lang="en"> + TEST <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta charset="utf-8"> @@ -22,7 +22,6 @@ background-image: url("<%= process_image(file: "background.png").relative_path %>"); color: #000; } - a { color: #000; } diff --git a/new/splash/pages/index.xml.rb b/new/splash/pages/index.xml.rb index 01edf785..fe4f8b91 100644 --- a/new/splash/pages/index.xml.rb +++ b/new/splash/pages/index.xml.rb @@ -18,6 +18,7 @@ module Crys 'index.xml' end + private attr_reader :main_rss |