From dfe3b1473dd7eadd7f0cae6c7c4ea0264884d223 Mon Sep 17 00:00:00 2001 From: edith <58082567+jellodiil@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:59:25 +0100 Subject: [PATCH 1/4] WEB-6548: Adds a width_required attribute to ImageProvider --- app/lib/image_provider/provider.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/lib/image_provider/provider.rb b/app/lib/image_provider/provider.rb index 7eefc88..0ca82bd 100644 --- a/app/lib/image_provider/provider.rb +++ b/app/lib/image_provider/provider.rb @@ -5,10 +5,11 @@ module ImageProvider class Provider include Util::Logging - attr_reader :extractor + attr_reader :extractor, :width_required - def initialize(extractor:) + def initialize(extractor:,width_required:) @extractor = extractor + @width_required = width_required end def process From 4a3efbdfa577389986d8740a4bc32988499d5433 Mon Sep 17 00:00:00 2001 From: edith <58082567+jellodiil@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:59:42 +0100 Subject: [PATCH 2/4] WEB-6548: We either require widths or don't --- app/lib/runner/base.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/lib/runner/base.rb b/app/lib/runner/base.rb index f6ccaed..819465b 100644 --- a/app/lib/runner/base.rb +++ b/app/lib/runner/base.rb @@ -19,7 +19,7 @@ def render_book(publish_file:, local: false) parser = Parser::Publish.new(file: publish_file) book = parser.parse image_extractor = ImageProvider::BookExtractor.new(book) - image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor) + image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor, width_required: true) image_provider&.process renderer = Renderer::Book.new(book, image_provider:) renderer.render @@ -31,7 +31,7 @@ def publish_book(publish_file:) parser = Parser::Publish.new(file: publish_file) book = parser.parse image_extractor = ImageProvider::BookExtractor.new(book) - image_provider = ImageProvider::Provider.new(extractor: image_extractor) + image_provider = ImageProvider::Provider.new(extractor: image_extractor, width_required: true) image_provider.process Renderer::Book.new(book, image_provider:).render Api::Alexandria::BookUploader.upload(book) @@ -60,7 +60,7 @@ def render_video_course(release_file:, local: false) parser = Parser::Release.new(file: release_file) video_course = parser.parse image_extractor = ImageProvider::VideoCourseExtractor.new(video_course) - image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor) + image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor, width_required: false) image_provider&.process renderer = Renderer::VideoCourse.new(video_course, image_provider:) renderer.render @@ -112,7 +112,7 @@ def publish_pablo(source:, output:) output ||= default_pablo_output image_extractor = ImageProvider::DirectoryExtractor.new(source) - image_provider = ImageProvider::Provider.new(extractor: image_extractor) + image_provider = ImageProvider::Provider.new(extractor: image_extractor, width_required: false) image_provider.process paths = image_extractor.categories.map { "/#{_1}" }.push('/', '/license', '/instructions', '/styles.css', '/javascript/search.js') @@ -130,7 +130,7 @@ def render_content_module(module_file:, local: false) parser = Parser::Circulate.new(file: module_file) content_module = parser.parse image_extractor = ImageProvider::ContentModuleExtractor.new(content_module) - image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor) + image_provider = local ? nil : ImageProvider::Provider.new(extractor: image_extractor, width_required: false) image_provider&.process renderer = Renderer::ContentModule.new(content_module, image_provider:) renderer.render @@ -156,7 +156,7 @@ def circulate_content_module(module_file:) content_module = parser.parse image_extractor = ImageProvider::ContentModuleExtractor.new(content_module) - image_provider = ImageProvider::Provider.new(extractor: image_extractor) + image_provider = ImageProvider::Provider.new(extractor: image_extractor, width_required: false) image_provider.process Renderer::ContentModule.new(content_module, image_provider:).render Api::Alexandria::ContentModuleUploader.upload(content_module) From eb6fb6eeca5ede7969401f580d995ca8f94b8ade Mon Sep 17 00:00:00 2001 From: edith <58082567+jellodiil@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:00:00 +0100 Subject: [PATCH 3/4] WEB-6548: Checks whether we care for widths before we show an ugly error --- app/lib/renderer/rw_markdown_renderer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/renderer/rw_markdown_renderer.rb b/app/lib/renderer/rw_markdown_renderer.rb index 426289f..9e147a0 100644 --- a/app/lib/renderer/rw_markdown_renderer.rb +++ b/app/lib/renderer/rw_markdown_renderer.rb @@ -22,7 +22,7 @@ def image(node) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics alt_text = node.each.select { |child| child.type == :text }.map { |child| escape_html(child.string_content) }.join(' ') classes = class_list(alt_text) - if width_class?(alt_text) + if width_class?(alt_text) || @image_provider.width_required == false out('
') out(' ') if svg?(alt_text, node.url) From 7827a97075f015dc127423648868f34dde5e2fe4 Mon Sep 17 00:00:00 2001 From: edith <58082567+jellodiil@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:05:41 +0100 Subject: [PATCH 4/4] Update app/lib/image_provider/provider.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sämmi --- app/lib/image_provider/provider.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/image_provider/provider.rb b/app/lib/image_provider/provider.rb index 0ca82bd..1a0b863 100644 --- a/app/lib/image_provider/provider.rb +++ b/app/lib/image_provider/provider.rb @@ -7,7 +7,7 @@ class Provider attr_reader :extractor, :width_required - def initialize(extractor:,width_required:) + def initialize(extractor:, width_required:) @extractor = extractor @width_required = width_required end