Skip to content

Commit

Permalink
WEB-6754: Fixing images in local preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyd committed Jan 8, 2024
1 parent 4bc5c12 commit 44eef29
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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

0 comments on commit 44eef29

Please sign in to comment.