Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEB-6754: Fixing images in local preview #237

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/server/local_image_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion app/server/robles_book_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/server/robles_content_module_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:,
Expand Down Expand Up @@ -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
Expand Down