From 44eef2964ba34b07959a65e7845ea5ff7f9075a5 Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Mon, 8 Jan 2024 20:49:37 +0700 Subject: [PATCH] WEB-6754: Fixing images in local preview --- app/server/local_image_provider.rb | 12 ++++++++---- app/server/robles_book_server.rb | 2 +- app/server/robles_content_module_server.rb | 9 +++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/server/local_image_provider.rb b/app/server/local_image_provider.rb index 79e8e50..46f26b8 100644 --- a/app/server/local_image_provider.rb +++ b/app/server/local_image_provider.rb @@ -2,14 +2,14 @@ # An implementation of an image provider suitable for use in the server class LocalImageProvider - attr_reader :chapter + attr_reader :container - def initialize(chapter:) - @chapter = chapter + def initialize(container:) + @container = container end def process - image_paths = extract_images_from_markdown(chapter.markdown_file) + image_paths = extract_images_from_markdown(container.markdown_file) @images = extract(image_paths) end @@ -29,4 +29,8 @@ def extract(image_paths) def extract_images_from_markdown(file) ImageProvider::MarkdownImageExtractor.images_from(file) end + + def width_required + false + end end diff --git a/app/server/robles_book_server.rb b/app/server/robles_book_server.rb index 1a95c4b..f0758d0 100644 --- a/app/server/robles_book_server.rb +++ b/app/server/robles_book_server.rb @@ -89,7 +89,7 @@ def chapter_for_slug(slug) end def render_chapter(chapter) - image_provider = LocalImageProvider.new(chapter:) + image_provider = LocalImageProvider.new(container: chapter) image_provider.process renderer = Renderer::Chapter.new(chapter, image_provider:) renderer.render diff --git a/app/server/robles_content_module_server.rb b/app/server/robles_content_module_server.rb index df9c8e3..7183d2e 100644 --- a/app/server/robles_content_module_server.rb +++ b/app/server/robles_content_module_server.rb @@ -95,6 +95,8 @@ def scss(template, options = {}, locals = {}) segment = segment_for_slug(lesson, params[:slug]) raise Sinatra::NotFound unless segment.present? + render_text(segment) + erb :'content_modules/text.html', locals: { segment:, @@ -126,6 +128,13 @@ def content_module(with_transcript: true) content_module end + def render_text(text) + image_provider = LocalImageProvider.new(container: text) + image_provider.process + renderer = Renderer::Segment.create(text, image_provider:) + renderer.render + end + def render_string(content) Renderer::MarkdownStringRenderer.new(content:).render end