Sha256: 3218d3fdbc188b1cfe2539af62e7bd82faea46be8465b4bacebe2b259400f6eb

Contents?: true

Size: 997 Bytes

Versions: 11

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeFreeResponse
  class V1
    renderable

    def bake(chapter:, metadata_source:, append_to:)
      @metadata_elements = metadata_source.children_to_keep.copy

      @free_response_clipboard = Kitchen::Clipboard.new
      chapter.pages.each do |page|
        free_response_questions = page.free_response
        next if free_response_questions.none?

        free_response_questions.search('h3')&.first&.trash
        title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
        free_response_questions.each do |free_response_question|
          free_response_question.prepend(child: title)
          free_response_question.cut(to: @free_response_clipboard)
        end
      end

      return if @free_response_clipboard.none?

      append_to_element = append_to || chapter
      @title_tag = append_to ? 'h3' : 'h2'

      append_to_element.append(child: render(file: 'free_response.xhtml.erb'))
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-18.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-17.1.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-12.2.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-12.1.0 lib/kitchen/directions/bake_free_response/v1.rb
openstax_kitchen-12.0.0 lib/kitchen/directions/bake_free_response/v1.rb