Top Level Namespace

Defined Under Namespace

Modules: I18n, Kitchen, LocaleToEnMonkeypatch, Nokogiri Classes: Array, Integer, Object, String

Constant Summary collapse

VALIDATE_OUTPUT =

Offers some validation for baked output. Run after each recipe. Does NOT transform any of the content.

Kitchen::BookRecipe.new(book_short_name: :validate) do |doc|
  # Check for duplicate IDs
  def warn_if_already_seen(id)
    duplicate_ids_to_ignore = %w[author-1 author-2 publisher-1 publisher-2 publisher-3 publisher-4
                                 copyright-holder-1 copyright-holder-2 copyright-holder-3].freeze
    @already_seen_ids ||= Set.new
    if @already_seen_ids.include?(id) && !duplicate_ids_to_ignore.include?(id)
      puts "warning! duplicate id found for #{id}"
    end
    @already_seen_ids.add(id)
  end

  # ADD FURTHER VALIDATION STEPS HERE

  doc.traverse do |child|
    next if child.text? || child.document?

    warn_if_already_seen(child[:id]) if child[:id]
  end
end
BCA_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :bca) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true
    }
  )

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise,
      options: { alphabetical_multiparts: true, list_type: 'upper-alpha' }
    )
  end

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    # EOC sections
    eoc_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary',
      append_to: eoc_wrapper,
      wrap_section: true,
      wrap_content: true
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page), title_tag: 'h4')
      section.prepend(child: title)
    end

    eoc_sections = %w[review-questions conceptual-questions you-try practice-exercises
                      written-questions case-exercises extension-exercises]

    eoc_sections.each do |klass|
      Kitchen::Directions::MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: klass,
        uuid_key: ".#{klass}",
        section_selector: "section.#{klass}",
        append_to: eoc_wrapper
      ) do |exercise_section|
        Kitchen::Directions::RemoveSectionTitle.v1(section: exercise_section)
        exercise_section.search('section').each do |section|
          section.first('h4').name = 'h5'
        end
      end
    end

    selectors = 'section.review-questions, section.conceptual-questions,
                 section.you-try, section.practice-exercises,
                 section.written-questions, section.case-exercises,
                 section.extension-exercises'

    chapter.composite_pages.search(selectors).injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
    end
  end

  notes = %w[real-application spotlight-ethics link-to-learning]
  BakeAutotitledNotes.v1(book: book, classes: notes)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[mac-tip],
    options: { bake_exercises: true }
  )

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
  end

  BakeIframes.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
DUMMY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :dummy) do |doc, _resources|
  include Kitchen::Directions

  # Patch locale
  LocaleToEnMonkeypatch.apply_patch
  raise "Locale is #{doc.locale}; should be 'en'" if doc.locale != 'en'

  book = doc.book
  book.search('div.test123').each { |div| div.replace_children(with: 'Hello, world!') }
end
PYTHON_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :python) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  BakeIframes.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(exercise: exercise)
  end

  BakeHighlightedCode.v1(book: book, languages: ['python'])

  notes = %w[guided-slides learning-questions practice-program]
  BakeAutotitledNotes.v1(book: book, classes: notes, options: { bake_exercises: false })

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.pages('$.preface').each do |page|
    page.notes('$.learning-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:page),
        options: { only_number_solution: false }
      )
    end

    answer_key_preface_inner_container = AnswerKeyInnerContainer.v1(
      chapter: page, metadata_source: , append_to: answer_key,
      options: { solutions_plural: false, in_preface: true }
    )
    Kitchen::Directions::MoveSolutionsFromAutotitledNote.v1(
      page: page, append_to: answer_key_preface_inner_container,
      note_class: 'learning-questions', title: nil
    )
  end

  BakeChapterTitle.v1(book: book)

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true
    }
  )

  book.chapters.each do |chapter|

    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.pages.notes('$.learning-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:page),
        options: { only_number_solution: false, add_dot: true }
      )
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )
    chapter.non_introduction_pages.each do |page|
      title = page.title.children
      Kitchen::Directions::MoveSolutionsFromAutotitledNote.v1(
        page: page, append_to: answer_key_inner_container, note_class: 'learning-questions',
        title: title
      )
    end
  end

  BakeFootnotes.v1(book: book, number_format: :roman) # check if exists
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ANATOMY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :anatomy) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')
  BakeUnitTitle.v1(book: book)
  AddInjectedExerciseId.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book,
    options: {
      bake_chapter_outline: false,
      introduction_order: :v2
    }
  )
  BakeChapterTitle.v1(book: book)

  book.notes('$.homeostatic').each { |note| note['use-subtitle'] = true }

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[interactive everyday homeostatic disorders career aging diseases]
  )

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    exercise_section_classes = %w[interactive-exercise multiple-choice free-response]

    exercise_section_classes.each do |klass|
      MoveExercisesToEOC.v1(
        chapter: chapter,
        metadata_source: ,
        klass: klass
      )
    end

    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div.os-eoc'),
      exercise_options: { suppress_solution_if: true }
    )

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeReferences.v3(book: book, metadata_source: )
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
BIOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :biology) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeAutotitledNotes.v1(book: book, classes: %w[visual-connection interactive evolution career
                                                 scientific everyday])
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: , klass: 'summary')
    chapter.search('section.summary').each do |summary| # TODO: remove this
      summary.first('h3').remove_attribute('itemprop')
    end
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: 'visual-exercise')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: 'multiple-choice')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: 'critical-thinking')
    exercise_selectors = \
      'section.visual-exercise, section.multiple-choice, section.critical-thinking'
    chapter.search(exercise_selectors).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter),
                              options: { suppress_solution_if: true })
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
  end

  BakeUnnumberedTables.v1(book: book)
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeScreenreaderSpans.v1(book: book)
  BakeIframes.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
FINANCE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :finance) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    page_summary: 'section.section-summary'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')

  book.pages('$.preface').each do |page|
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: table.count_in(:page).to_s)
    end
  end

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[think-through link-to-learning concepts-practice]
  )

  BakeNumberedNotes.v1(
    book: book,
    classes: %w[cfa-institute]
  )

  BakeCustomTitledNotes.v1(book: book, classes: %w[excel-spreadsheet])

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeChapterSummary.v1(chapter: chapter, metadata_source: , klass: 'section-summary')
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    eoc_sections = %w[multiple-choice review-questions problem-set video-activity]

    eoc_sections.each do |klass|
      chapter.pages.search("section.#{klass}").injected_questions.each do |question|
        BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      end
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'cfa-institute',
      uuid_key: '.cfa-institute',
      section_selector: 'section.cfa-institute'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'sources-notes',
      uuid_key: '.sources-notes',
      section_selector: 'section.sources-notes'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeIframes.v1(book: book)
  BakeEquations.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
HISTORY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :history) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakePreface.v1(book: book, title_element: 'h1')
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[click-and-explore my-story americana defining-american]
  )

  answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    eoc_sections = %w[review-questions critical-thinking]

    chapter.search(eoc_sections.prefix('section.')).exercises.each do |exercise|
      if exercise.parent.has_class?('review-questions')
        BakeNumberedExercise.v1(
          exercise: exercise,
          number: exercise.count_in(:chapter),
          options: {
            suppress_solution_if: :even?,
            note_suppressed_solutions: true
          }
        )
      else
        BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
      end
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key,
      options: { solutions_plural: false }
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: {
        selectors: ['section.review-questions'],
        condition: :even?
      },
      chapter: chapter,
      append_to: answer_key_inner_container
    )

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
  end

  BakeUnnumberedFigure.v1(book: book)

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
CALCULUS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :calculus) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)

  book.notes('$.theorem').each { |theorem| theorem['use-subtitle'] = true }

  BakeAutotitledNotes.v1(book: book, classes: %w[media-2 problem-solving project])
  BakeNumberedNotes.v1(book: book, classes: %w[theorem checkpoint])

  book.chapters.each do |chapter|
    chapter_review = ChapterReviewContainer.v1(
      chapter: chapter,
      metadata_source: 
    )

    BakeChapterGlossary.v1(
      chapter: chapter, metadata_source: , append_to: chapter_review
    )
    BakeChapterKeyEquations.v1(
      chapter: chapter, metadata_source: , append_to: chapter_review
    )
    BakeChapterKeyConcepts.v1(
      chapter: chapter, metadata_source: , append_to: chapter_review
    )
    MoveExercisesToEOC.v1(
      chapter: chapter, metadata_source: ,
      append_to: chapter_review, klass: 'review-exercises'
    )
    BakeChapterSectionExercises.v1(chapter: chapter)

    # Just above we moved the review exercises to the end of the chapter. Now that all of the
    # non-checkpoint exercises are in the right order, we bake them (the "in place" modifications)
    # and number them.
    chapter.search('section.section-exercises, section.review-exercises').exercises.each \
    do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end
  end

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  book.chapters.each do |chapter|
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    page.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{appendix_letter}#{example.count_in(:page)}",
                     title_tag: 'div')
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  # Here we move the solutions to the end of the book. Calculus has an "Answer Key" composite
  # chapter after the appendices. So we make the answer key, then iterate over the chapters, making
  # an answer key composite page for each chapter that we append to the answer key composite chapter
  book_answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: book_answer_key
    )
    # Bake solutions
    MoveSolutionsFromAutotitledNote.v1(
      page: chapter, append_to: answer_key_inner_container, note_class: 'checkpoint',
      title: I18n.t(:'notes.checkpoint')
    )
    chapter.sections('$.section-exercises').each do |section|
      number = "#{chapter.count_in(:book)}.#{section.count_in(:chapter)}"
      MoveSolutionsFromExerciseSection.v1(
        within: section, append_to: answer_key_inner_container, section_class: 'section-exercises',
        title_number: number
      )
    end
    MoveSolutionsFromExerciseSection.v1(
      within: chapter, append_to: answer_key_inner_container, section_class: 'review-exercises'
    )
  end

  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  book.search('section.section-exercises', 'div.os-eob.os-solutions-container').each do |within|
    BakeFirstElements.v1(within: within)
  end

  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeEquations.v1(book: book, number_decorator: :parentheses)
  BakeFolio.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v2(chapter: chapter)
  end

  BakeRexWrappers.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeLinks.v1(book: book)

end
DEV_MATH_RECIPE =

used for prealgebra, intermediate-algebra, and elementary-algebra

Kitchen::BookRecipe.new(book_short_name: :dev_math) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeUnclassifiedNotes.v1(book: book)
  BakeNumberedNotes.v1(book: book, classes: %w[try be-prepared])
  book.notes('$.try, .be-prepared').exercises.each do |exercise|
    BakeFirstElements.v1(within: exercise, first_inline_list: true)
  end
  BakeAutotitledNotes.v1(book: book, classes: %w[manipulative-math howto media-2 links-to-literacy])

  answer_key = BookAnswerKeyContainer.v1(book: book)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter_review = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )
    exercises_composite_chapter = ChapterReviewContainer.v1(
      chapter: chapter, metadata_source: , klass: 'exercises'
    )
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: chapter_review)
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter, metadata_source: ,
      container_key: 'key-concepts', uuid_key: '.key-concepts',
      section_selector: 'section.key-concepts',
      append_to: chapter_review,
      wrap_section: true, wrap_content: true
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page), title_tag: 'h4')
      section.prepend(child: title)
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter, metadata_source: ,
      container_key: 'review-exercises', uuid_key: '.review-exercises',
      section_selector: 'section.review-exercises',
      append_to: exercises_composite_chapter
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      ChangeSubsectionTitleTag.v1(section: section)
    end
    MoveExercisesToEOC.v1(
      chapter: chapter, metadata_source: , klass: 'practice-test',
      append_to: exercises_composite_chapter
    )
    exercise_sections = 'section.section-exercises, section.review-exercises, section.practice-test'
    chapter.search(exercise_sections).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
      BakeFirstElements.v1(within: exercise, first_inline_list: true)
    end
    BakeChapterSectionExercises.v1(chapter: chapter)
    chapter.sections('$.section-exercises').each do |section|
      section.search(' > h3[data-type="title"]').first&.trash
    end

    # Make the answer key:
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )
    MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'be-prepared'
    )
    MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'try'
    )
    chapter.non_introduction_pages.each do |page|
      number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: page, append_to: answer_key_inner_container, section_class: 'section-exercises',
        title_number: number
      )
    end
    exercise_section_classes = %w[review-exercises practice-test]
    exercise_section_classes.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end

    # Bake features
    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end
    chapter.examples.each do |example|
      BakeExample.v1(
        example: example,
        number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
        title_tag: 'h3'
      )
      example.first('div.os-solution-container')&.first('h4[data-type="title"]')&.trash
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.examples.exercises.each do |exercise|
    BakeFirstElements.v1(within: exercise, first_inline_list: true)
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeUnnumberedTables.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ASTRONOMY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :astronomy) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[
      link-to-learning
      astronomy-basics
      making-connections
      seeing-for-yourself
      voyagers-in-astronomy
    ]
  )
  BakeUnclassifiedNotes.v1(book: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )
    section_keys = %w[further-exploration group-activities]
    section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
    exercises_composite_chapter = \
      ChapterReviewContainer.v1(chapter: chapter, metadata_source: , klass: 'exercises')
    exercise_section_keys = %w[review-questions thought-questions figuring-for-yourself]
    exercise_section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: exercises_composite_chapter
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
    exercises_composite_chapter.exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end
    exercises_composite_chapter.trash if exercises_composite_chapter.sections.none?

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end
    chapter.examples.each do |example|
      BakeExample.v1(
        example: example,
        number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
        title_tag: 'h3'
      )
    end
    chapter.tables.each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
  end

  BakeScreenreaderSpans.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
CHEMISTRY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :chemistry) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)
  book.chapters.each do |chapter|
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterKeyEquations.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )
    MoveExercisesToEOC.v3(chapter: chapter, metadata_source: , klass: 'exercises')
    chapter.search('section.exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key,
      options: { solutions_plural: false }
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: { selectors: ['section.exercises'] },
      chapter: chapter,
      append_to: answer_key_inner_container
    )
  end

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    page.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{appendix_letter}#{example.count_in(:page)}",
                     title_tag: 'div')
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeUnnumberedTables.v1(book: book)

  book.search('div[data-type="solution"]').each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  note_classes = %w[link-to-learning everyday-life chemist-portrait sciences-interconnect]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)
  BakeUnclassifiedNotes.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeEquations.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ECONOMICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :economics) do |doc, _resources|
  include Kitchen::Directions

  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')
  BakeChapterIntroductions.v2(book: book)
  BakeChapterTitle.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  BakeIframes.v1(book: book)
  BakeAutotitledNotes.v1(book: book, classes: %w[linkup bringhome clearup workout])
  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    exercise_section_classes = \
      %w[summary self-check-questions review-questions critical-thinking problems]

    chapter.search(exercise_section_classes.prefix('section.')).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    exercise_section_classes.each do |klass|
      MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: klass)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: {
        selectors: %w[self-check-questions problems ap-test-prep].prefix('section.')
      },
      chapter: chapter,
      append_to: answer_key_inner_container
    )

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.exercises.each do |exercise|
      BakeFirstElements.v1(within: exercise)
    end

    BakeNonIntroductionPages.v1(chapter: chapter)
  end
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    BakeAppendix.v1(page: page, number: appendix_letter)
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    page.search('section').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise,
                              number: "#{appendix_letter}#{exercise.count_in(:page)}")
      BakeFirstElements.v1(within: exercise)
    end
  end

  BakeUnnumberedTables.v1(book: book)

  book.search('div.os-solutions-container').solutions.each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  BakeReferences.v2(book: book, metadata_source: )
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
MARKETING_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :marketing) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)

  book.pages('$.preface').each do |page|
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: table.count_in(:page).to_s)
    end
  end

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true, introduction_order: :v3
    }
  )
  BakeChapterTitle.v1(book: book)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  AddInjectedExerciseId.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeLearningObjectives.v2(chapter: chapter, add_title: false, li_numbering: :count_only_li)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.pages.each do |page|
      BakeAllNumberedExerciseTypes.v1(
        within: page.search('section.knowledge-check'),
        question_options: { add_dot: true }
      )
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'chapter-summary',
      uuid_key: '.chapter-summary',
      section_selector: 'section.chapter-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    eoc_sections = %w[marketing-discussion critical-thinking building-brand
                      marketers-do marketing-plan company-case]

    eoc_sections.each do |section_key|
      BakeAllNumberedExerciseTypes.v1(
        within: chapter.pages.search("section.#{section_key}")
      )

      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section, selector: 'h3')
      end
    end

    BakeChapterReferences.v2(
      chapter: chapter,
      metadata_source: ,
      uuid_prefix: '.',
      klass: 'references'
    )

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key,
      options: { solutions_plural: false }
    )
    chapter.non_introduction_pages.each do |page|
      number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: page, append_to: answer_key_inner_container, section_class: 'knowledge-check',
        title_number: number
      )
    end
  end

  notes = %w[marketing-practice companies-conscience link-to-learning careers-marketing]
  BakeAutotitledNotes.v1(book: book, classes: notes)
  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[marketing-dashboard],
    options: { bake_exercises: true }
  )
  BakeCustomTitledNotes.v1(book: book, classes: %w[unit-opener word-document])

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    BakeLearningObjectives.v2(
      chapter: page, add_title: false, li_numbering: :count_only_li_in_appendix
    )

    feature_sections_selectors = %w[references chapter-summary knowledge-check]
    feature_sections_selectors.each do |selector|
      page.search("section.#{selector}").each do |section|
        BakeAppendixFeatureTitles.v1(section: section, selector: selector)
      end
    end

    page.search('section.knowledge-check').injected_exercises.each do |exercise|
      BakeInjectedExercise.v1(exercise: exercise)
    end

    page.search('section.knowledge-check').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: "#{appendix_letter}#{question.count_in(:page)}"
      )
    end

    answer_key_appendix_inner_container = AnswerKeyInnerContainer.v1(
      chapter: page, metadata_source: , append_to: answer_key,
      options: { solutions_plural: false, in_appendix: true }
    )
    Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
      within: page, append_to: answer_key_appendix_inner_container,
      section_class: 'knowledge-check', options: { in_appendix: true }
    )
  end

  BakeEquations.v1(book: book)
  BakeIframes.v1(book: book)
  BakeFootnotes.v1(book: book, number_format: :roman)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeUnitPageTitle.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
end
SOCIOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :sociology) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    page_summary: 'section.section-summary',
    reference: 'section.references'
  )

  book = doc.book
   = book.
  edition_symbol = book.first('head').first('title').text.match(/(\d)e$/).to_s
  # Some stuff just goes away
  book.search('cnx-pi').trash

  # Remove data-type="description" from body metadata placed in Sociology 2e
  if edition_symbol == '2e'
    book.body.search('div[data-type="metadata"] > div[data-type="description"]').trash
  end

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  # Bake NumberedTable in Preface
  book.pages('$.preface').tables('$:not(.unnumbered)').each do |table|
    BakeNumberedTable.v1(table: table, number: table.count_in(:page))
  end

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  # Bake EoC sections
  book.chapters.each do |chapter|
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: , klass: 'section-summary')
    MoveExercisesToEOC.v3(chapter: chapter, metadata_source: , klass: 'section-quiz')
    MoveExercisesToEOC.v3(chapter: chapter, metadata_source: , klass: 'short-answer')
    BakeFurtherResearch.v1(chapter: chapter, metadata_source: )
    chapter.composite_pages.each do |composite_page|
      composite_page.search('section.short-answer, section.section-quiz').exercises.each \
      do |exercise|
        BakeNumberedExercise.v1(
          exercise: exercise, number: exercise.count_in(:composite_page),
          options: { suppress_solution_if: :even?, note_suppressed_solutions: true }
        )
      end
    end
    BakeChapterReferences.v1(chapter: chapter, metadata_source: )
  end

  # Bake Answer Key
  if edition_symbol == '3e'
    solution_container = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)
    book.chapters.each do |chapter|
      inner_container = AnswerKeyInnerContainer.v1(
        chapter: chapter, metadata_source: , append_to: solution_container,
        options: { solutions_plural: false }
      )
      DefaultStrategyForAnswerKeySolutions.v1(
        strategy_options: { selectors: %w[section-quiz].prefix('section.') },
        chapter: chapter, append_to: inner_container
      )
    end
  end

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")

    end
  end

  BakeAutotitledNotes.v1(book: book, classes: %w[sociological-research
                                                 sociology-real-world
                                                 sociology-big-picture
                                                 sociology-policy-debate])
  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
U_PHYSICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :uphysics) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
  end

  # Bake the notes
  BakeAutotitledNotes.v1(book: book, classes: %w[media-2 problem-solving])
  BakeUnclassifiedNotes.v1(book: book)
  BakeNumberedNotes.v1(book: book, classes: %w[check-understanding])

  # Bake EOC sections
  solutions_container = BookAnswerKeyContainer.v1(book: book)
  book.chapters.each do |chapter|
    eoc_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    BakeChapterKeyEquations.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    BakeChapterKeyConcepts.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    # EoC sections with exercises
    MoveExercisesToEOC.v2(chapter: chapter, metadata_source: , append_to: eoc_wrapper,
                          klass: 'review-conceptual-questions')
    MoveExercisesToEOC.v2(chapter: chapter, metadata_source: , append_to: eoc_wrapper,
                          klass: 'review-problems')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper,
                          klass: 'review-additional-problems')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper,
                          klass: 'review-challenge')
    # In-place bake exercises & solutions
    exercise_selectors = 'section.review-conceptual-questions, section.review-problems, ' \
                         'section.review-additional-problems, section.review-challenge'
    chapter.search(exercise_selectors).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    # Bake answer key from chapter/ move solutions from eoc into answer key
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: solutions_container
    )
    Kitchen::Directions::MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'check-understanding'
    )
    exercise_section_classes = %w[review-conceptual-questions review-problems
                                  review-additional-problems review-challenge]
    exercise_section_classes.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  book.search('div[data-type="solution"]').each do |solution|
    # Add the 'has-first-element' class to elements that need it
    BakeFirstElements.v1(within: solution)
  end

  book.chapters.each do |chapter|
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeIframes.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ACCOUNTING_RECIPE =

spec input file contains test content from chapter 1 and 10 (needed for BakeFirstElemets in the AnswerKey) from Accounting vol2

Kitchen::BookRecipe.new(book_short_name: :accounting) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakePreface.v1(book: book)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives,
      bake_chapter_outline: true
    }
  )

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter, options: { custom_target_label: true })
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end

    # Eoc sections
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_sections = %w[multiple-choice
                      questions
                      exercise-set-a
                      exercise-set-b
                      problem-set-a
                      problem-set-b
                      thought-provokers]

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
      chapter.composite_pages.each do |composite_page|
        composite_page.search("section.#{section_key}").exercises.each do |exercise|
          BakeNumberedExercise.v1(exercise: exercise,
                                  number: exercise.count_in(:composite_page))
          BakeFirstElements.v1(within: exercise)
        end
      end
    end

    eoc_sections_prefixed = %w[exercise-set-a
                               exercise-set-b
                               problem-set-a
                               problem-set-b
                               thought-provokers]

    BakeExercisePrefixes.v1(
      chapter: chapter,
      sections_prefixed: eoc_sections_prefixed
    )

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )
    answer_key_classes_to_move = %w[multiple-choice questions]
    answer_key_classes_to_move.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  BakeAutotitledNotes.v1(book: book, classes: %w[your-turn
                                                 think-through
                                                 concepts-practice
                                                 continuing-application
                                                 ethical-considerations
                                                 ifrs-connection
                                                 link-to-learning])

  BakeStepwise.v1(book: book)
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeEquations.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeLOLinkLabels.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
AP_BIOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :ap_bio) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(exercise: exercise)
  end

  BakePreface.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[visual-connection
                ost-sciprac-scithink],
    options: { bake_subtitle: false }
  )
  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[interactive
                ost-sciprac-activity
                ap-science-practices
                os-teacher
                evolution
                ap-everyday
                career
                everyday
                experiment
                scientific]
  )
  BakeUnclassifiedNotes.v1(book: book)

  book.exercises('$.unnumbered').each do |exercise|
    exercise.problem.wrap_children(class: 'os-problem-container')
  end
  # Injected questions in notes should be treated as unnumbered questions
  book.notes.injected_questions.each do |question|
    question.wrap_children(class: 'os-problem-container')
  end

  book.chapters.each do |chapter|
    chapter.search('div[data-type="abstract"]').each(&:trash)
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    custom_sections = %w[review critical-thinking ap-test-prep science-practice]
    custom_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    # Bake both kinds of exercise
    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div.os-eoc'),
      exercise_options: { suppress_solution_if: true }
    )
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeIframes.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
AP_HISTORY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :ap_history) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeAutotitledNotes.v1(book: book, classes: %w[os-teacher])
  BakeUnclassifiedNotes.v1(book: book)
  BakeIframes.v1(book: book)
  BakeAccessibilityFixes.v1(section: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    # Bake & number exercises in place, within section
    chapter.pages.sections('$[data-depth="2"]').each do |section|
      section.exercises.each do |exercise|
        BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:section))
      end
      section.injected_questions.each do |question|
        BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:section))
      end
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
  end

  BakeUnnumberedTables.v1(book: book)

  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
AP_PHYSICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :ap_physics) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeUnclassifiedNotes.v1(book: book)
  BakeAutotitledNotes.v1(book: book, classes: %w[interactive])
  BakeIframes.v1(book: book)
  BakeMathInParagraph.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.exercises('$[data-element-type="check-understanding"]').each do |exercise|
    BakeAutotitledExercise.v3(exercise: exercise, title: I18n.t(:'check-understanding'))
  end

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    section_keys = %w[section-summary conceptual-questions problems-exercises ap-test-prep]
    section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
        section.prepend(child: title)
      end
    end

    chapter.sections('$.conceptual-questions').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    chapter.sections('$.problems-exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    chapter.sections('$.ap-test-prep').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    page.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{appendix_letter}#{example.count_in(:page)}",
                     title_tag: 'div')
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  book.chapters.each do |chapter|
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )

    classes = %w[problems-exercises ap-test-prep]
    classes.each do |klass|
      MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  book.search('section.problems-exercises',
              'section.ap-test-prep',
              'div.os-solutions-container').each do |within|
    BakeFirstElements.v1(within: within)
  end

  book.composite_pages.search('div[data-type="equation"]').each do |eq|
    eq.add_class('unnumbered')
  end

  BakeFootnotes.v1(book: book)
  BakeEquations.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
HS_PHYSICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :hs_physics) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  AddInjectedExerciseId.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[os-teacher
                boundless-physics
                worked-example
                virtual-physics
                snap-lab
                links-to-physics
                tips-for-success
                teacher-demonstration
                watch-physics
                work-in-physics
                fun-in-physics
                misconception]
  )
  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[learning-objectives],
    options: { bake_subtitle: false }
  )
  book.exercises('$.grasp-check').each do |exercise|
    BakeAutotitledExercise.v2(exercise: exercise, title: I18n.t(:'grasp-check'))
  end
  BakeUnclassifiedNotes.v1(book: book)
  book.notes('$.worked-example').exercises.each do |exercise|
    exercise.add_class('unnumbered')
  end
  book.exercises('$.unnumbered').each do |exercise|
    next if exercise.has_class?('grasp-check')

    BakeUnnumberedExercise.v1(exercise: exercise)
  end

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)
    # Check Your Understanding + Practice Problems sections come last in a chapter section
    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('section.check-understanding, section.practice-problems'),
      exercise_options: { solution_stays_put: true }
    )

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'key-equations',
      uuid_key: '.key-equations',
      section_selector: 'section.key-equations'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end
    chapter_review_container = ChapterReviewContainer.v1(
      chapter: chapter, metadata_source: 
    )
    cr_section_keys = %w[concept critical-thinking problems performance]
    cr_section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: chapter_review_container,
        wrap_section: true, wrap_content: true
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page), title_tag: 'h4')
        section.prepend(child: title)
      end
    end
    test_prep_container = ChapterReviewContainer.v1(
      chapter: chapter, metadata_source: , klass: 'test-prep'
    )
    tp_section_keys = %w[multiple-choice short-answer extended-response]
    tp_section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: test_prep_container,
        wrap_section: true, wrap_content: true
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page), title_tag: 'h4')
        section.prepend(child: title)
      end
    end
    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div[data-type="composite-chapter"]'),
      exercise_options: { suppress_solution_if: true }
    )
    BakeFirstElements.v1(within: chapter.search('div[data-type="composite-chapter"]').exercises)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeUnnumberedTables.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PHILOSOPHY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :philosophy) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: '.references'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true
    }
  )
  BakeUnnumberedFigure.v1(book: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'summary',
      uuid_key: '.summary',
      section_selector: 'section.summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterReferences.v3(chapter: chapter, metadata_source: )

    chapter.pages.search('section.review-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'review-questions',
      uuid_key: '.review-questions',
      section_selector: 'section.review-questions',
      wrap_section: true, wrap_content: true
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    sections = %w[further-reading]
    sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
  end

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[read-philosopher
                think-philosopher
                write-philosopher
                philo-connections
                time-line
                media-video
                media-podcast]
  )

  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PSYCHOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :psychology) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  BakeChapterTitle.v1(book: book)

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true
    }
  )

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'summary',
      uuid_key: '.summary',
      section_selector: 'section.summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_with_exercise = %w[review-questions critical-thinking personal-application]
    eoc_with_exercise.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div[data-type="composite-page"]'),
      exercise_options: { suppress_solution_if: true }
    )
  end

  notes = %w[link-to-learning dig-deeper everyday-connection what-do-you-think connect-the-concepts]
  BakeAutotitledNotes.v1(book: book, classes: notes)

  BakeReferences.v2(book: book, metadata_source: )
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
STATISTICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :statistics) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: '.references'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash
  book.body.search('div[data-type="metadata"] > div[data-type="description"]').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')
  BakeInlineLists.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)

    # EOC sections
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'formula-review',
      uuid_key: '.formula-review',
      section_selector: 'section.formula-review',
      append_to: chapter
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      section.prepend(child: EocSectionTitleLinkSnippet.v1(
        page: section.ancestor(:page)
      ))
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'practice',
      uuid_key: '.practice',
      section_selector: 'section.practice',
      append_to: chapter
    ) do |section|
      RemoveSectionTitle.v1(section: section, selector: 'h3')
      section.prepend(child: EocSectionTitleLinkSnippet.v1(
        page: section.ancestor(:page)
      ))
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'bring-together-exercises',
      uuid_key: '.bring-together-exercises',
      section_selector: 'section.bring-together-exercises',
      append_to: chapter
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    BakeFreeResponse.v1(chapter: chapter, metadata_source: )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'bring-together-homework',
      uuid_key: '.bring-together-homework',
      section_selector: 'section.bring-together-homework',
      append_to: chapter
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    BakeChapterReferences.v1(chapter: chapter, metadata_source: book.)

    exercise_selectors = 'section.practice, section.bring-together-exercises, ' \
                         'section.free-response, section.bring-together-homework'
    chapter.search(exercise_selectors).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    BakeChapterSolutions.v1(
      chapter: chapter, metadata_source: ,
      classes: %w[practice bring-together-exercises free-response bring-together-homework]
    ) # breaks when replaced by exercise_selectors

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3',
                     options: { add_problem_title: true })
    end
  end

  BakeNumberedNotes.v3(book: book, classes: %w[try], options: { suppress_solution: true })
  BakeAutotitledNotes.v1(book: book, classes: %w[lab calculator])
  BakeAutotitledNotes.v1(book: book, classes: %w[collab], options: { bake_subtitle: false })

  book.chapters.each do |chapter|

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  book.search('section.section-exercises',
              'section.free-response',
              'section.bring-together-homework',
              'div.os-solutions-container').each do |within|
    BakeFirstElements.v1(within: within)
  end

  BakeUnnumberedTables.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PRECALCULUS_COREQ_DELETE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :coreq_delete) do |doc|
  include Kitchen::Directions

  book = doc.book

  book.search('section.practice-perfect').each(&:trash)
  book.search('section.coreq-skills').each(&:trash)
end
PRECALCULUS_SHARED_RECIPE =

Used in precalculus (bakes precalculus, trigonometry, and college-algebra) and precalculus-coreq (bakes college-algebra-coreq)

Kitchen::BookRecipe.new(book_short_name: :precalculus) do \
  |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  book.search('section.coreq-skills').each do |coreq_section|
    coreq_section.tables.each { |table| table.add_class('os-coreq-element') }
    coreq_section.figures.each { |table| table.add_class('os-coreq-element') }
    coreq_section.examples.each { |table| table.add_class('os-coreq-element') }
  end

  BakePreface.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
  end

  BakeAutotitledNotes.v1(book: book, classes: %w[how-to-notitle qa media-notitle])
  BakeUnclassifiedNotes.v1(book: book)
  BakeNumberedNotes.v2(book: book, classes: %w[try])

  # Bake EOC sections
  book.chapters.each do |chapter|
    eoc_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    BakeChapterKeyEquations.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    BakeChapterKeyConcepts.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    # EoC sections with exercises
    eoc_exercises_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: ,
                                                      klass: 'exercises')
    %w[review-exercises practice-test].each do |klass|
      Kitchen::Directions::MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: klass,
        uuid_key: ".#{klass}",
        section_selector: "section.#{klass}",
        append_to: eoc_exercises_wrapper
      ) do |exercise_section|
        Kitchen::Directions::RemoveSectionTitle.v1(section: exercise_section)
        exercise_section.search('section').each do |section|
          section.first('h4')&.name = 'h5'
        end
      end
    end
    BakeChapterSectionExercises.v1(chapter: chapter, options: { trash_title: true })
    # In-place bake exercises & solutions
    chapter.search('section.review-exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end
    chapter.search('section.practice-test').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end
    chapter.pages.search('section.section-exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:page))
    end
  end

  book.search('div.try, section.section-exercises, section.review-exercises')\
      .search('div[data-type="solution"]').tables.each do |table|
    table.add_class('unnumbered')
  end

  # Tables and figures must be baked after EOC sections are created to preserve number ordering
  book.pages('$:not(.appendix)').each do |page|
    page.tables('$:not(.unnumbered):not(.os-coreq-element)').each do |table|
      BakeNumberedTable.v2(table: table, number: table.count_in(:page))
    end
    page.figures('$:not(.os-coreq-element)', only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: figure.count_in(:page))
    end
    page.examples('$:not(.os-coreq-element)').each do |example|
      BakeExample.v1(example: example, number: example.count_in(:page), title_tag: 'h3')
    end
  end

  BakeUnnumberedFigure.v1(book: book)

  book.composite_pages.each do |page|
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table, number: table.count_in(:composite_page))
    end
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: figure.count_in(:composite_page))
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
  end

  BakeUnnumberedTables.v1(book: book)

  solutions_container = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)
  book.chapters.each do |chapter|
    # BakeFirstElements is most efficiently called before solutions are separated from exercises
    # BakeFirstElements must also be called after tables are baked.
    chapter.search('section.review-exercises, section.practice-test, section.section-exercises,' \
      ' div[data-type="note"].try').exercises.each do |exercise|
      # Classes added: has-first-element; has-first-inline-list-element
      BakeFirstElements.v1(within: exercise, first_inline_list: true)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: solutions_container,
      options: { solutions_plural: false }
    )
    # Bake note solutions
    MoveSolutionsFromAutotitledNote.v2(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'try'
    )
    # Bake section exercise solutions
    chapter.non_introduction_pages.each do |page|
      number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: page, append_to: answer_key_inner_container, section_class: 'section-exercises',
        title_number: number
      )
    end
    classes = %w[review-exercises practice-test]
    classes.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  BakeScreenreaderSpans.v1(book: book)
  BakeInlineLists.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
WEB_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :web) do |doc, resources|
  include Kitchen::Directions

  book = doc.book

  BakeImages.v1(book: book, resources: resources)
end
ANTHROPOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :anthropology) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  note_classes = %w[ethnographic-sketches fieldwork-activity profiles-anthropology media-podcast
                    media-video]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end
    exercise_selectors = 'section.critical-thinking'
    chapter.pages.search(exercise_selectors).injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
    end
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: 'critical-thinking')
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'references',
      uuid_key: '.references',
      section_selector: 'section.references'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
  end

  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
MICROBIOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :microbiology) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[clinical-focus check-your-understanding micro-connection
                link-to-learning eye-on-ethics case-in-point disease-profile]
  )

  book_answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    eoc_wrapper = ChapterReviewContainer.v1(
      chapter: chapter,
      metadata_source: ,
      klass: 'review-questions'
    )

    exercise_section_classes = %w[multiple-choice true-false matching
                                  fill-in-the-blank short-answer critical-thinking]

    exercise_section_classes.each do |klass|
      MoveExercisesToEOC.v1(
        chapter: chapter,
        metadata_source: ,
        append_to: eoc_wrapper,
        klass: klass
      )
    end

    chapter.search(exercise_section_classes.prefix('section.').join(', ')).exercises
           .each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    # Bake answer key from chapter/ move solutions from eoc into answer key
    inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: book_answer_key,
      options: { solutions_plural: false }
    )
    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: { selectors: exercise_section_classes.prefix('section.') },
      chapter: chapter, append_to: inner_container
    )

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeUnnumberedTables.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
NEUROSCIENCE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :neuroscience) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise
    )
  end

  BakeUnitTitle.v1(book: book)
  BakeChapterTitle.v1(book: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeLearningObjectives.v2(chapter: chapter, add_title: false)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    # EOC
    sections_with_module_links = %w[section-summary key-terms references
                                    multiple-choice fillin-blank]

    sections_with_module_links.each do |eoc_section|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: eoc_section,
        uuid_key: ".#{eoc_section}",
        section_selector: "section.#{eoc_section}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
        section.prepend(child: title)
      end
    end

    # Exercises
    chapter.search('section.multiple-choice').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.fillin-blank').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end
  end

  BakeIframes.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)

  note_classes = %w[meet-author across-species inthe-lab]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)

  BakeCustomTitledNotes.v1(book: book, classes: %w[boxed-feature])
end
PL_ECONOMICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :pleconomics) do |doc, _resources|
  include Kitchen::Directions

  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash
  BakeListsWithPara.v1(book: book)

  BakePreface.v1(book: book, title_element: 'h1')
  BakeUnnumberedFigure.v1(book: book)
  BakeChapterIntroductions.v2(book: book, options: { cases: true })
  BakeChapterTitle.v1(book: book, cases: true)
  BakeUnclassifiedNotes.v1(book: book)
  BakeIframes.v1(book: book)
  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[linkup bringhome clearup workout learning-objectives],
    options: { cases: true }
  )
  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , has_para: true)
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )

    exercise_section_classes = %w[summary self-check-questions review-questions
                                  critical-thinking problems]

    chapter.search(exercise_section_classes.prefix('section.')).exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter),
        options: { cases: true }
      )
    end

    exercise_section_classes.each do |klass|
      MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: klass)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key,
      options: { cases: true }
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options:
        { selectors: %w[self-check-questions problems ap-test-prep].prefix('section.') },
      chapter: chapter,
      append_to: answer_key_inner_container
    )

    # Temporary fix for top-captioned tables breaking the baking (to be removed after content update)
    chapter.tables(only: :top_captioned?).each do |table|
      table.remove_attribute('class') unless table.first('caption')
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
                           cases: true)
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
                    cases: true)
    end

    chapter.exercises.each do |exercise|
      BakeFirstElements.v1(within: exercise)
    end

    BakeNonIntroductionPages.v1(chapter: chapter, options: { cases: true })
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    BakeAppendix.v1(page: page, number: appendix_letter, options: { cases: true })
    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}",
                    cases: true)
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}",
                           cases: true)
    end

    page.search('section').exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: "#{appendix_letter}#{exercise.count_in(:page)}",
        options: { cases: true }
      )
      BakeFirstElements.v1(within: exercise)
    end
  end

  BakeUnnumberedTables.v1(book: book)

  book.search('div.os-solutions-container').solutions.each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  BakeReferences.v2(book: book, metadata_source: )
  BakeEquations.v1(book: book)
  BakeIndex.v1(book: book, types: %w[name term foreign], uuid_prefix: '.')
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book, options: { cases: true })
  BakeFolio.v1(book: book)
  BakeLinkPlaceholders.v1(book: book, cases: true)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PL_MARKETING_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :plmarketing) do |doc, resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'aside.reference'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeListsWithPara.v1(book: book)
  BakeImages.v1(book: book, resources: resources)
  BakePreface.v1(book: book, cases: true)

  book.pages('$.preface').each do |page|
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: table.count_in(:page).to_s,
                           cases: true)
    end
  end

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true, introduction_order: :v3, cases: true
    }
  )
  BakeChapterTitle.v1(book: book, cases: true)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter, options: { cases: true })
    BakeLearningObjectives.v2(chapter: chapter, add_title: false, li_numbering: :count_only_li)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
                    cases: true)
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
                           cases: true)
    end

    chapter.pages.each do |page|
      BakeAllNumberedExerciseTypes.v1(
        within: page.search('section.knowledge-check'),
        exercise_options: { cases: true },
        question_options: { add_dot: true }
      )
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'chapter-summary',
      uuid_key: '.chapter-summary',
      section_selector: 'section.chapter-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , has_para: true)

    eoc_sections = %w[marketing-discussion critical-thinking marketing-plan company-case]

    eoc_sections.each do |section_key|
      BakeAllNumberedExerciseTypes.v1(
        within: chapter.pages.search("section.#{section_key}"),
        exercise_options: { cases: true }
      )

      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key,
      options: { solutions_plural: false, cases: true }
    )
    chapter.non_introduction_pages.each do |page|
      number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: page, append_to: answer_key_inner_container, section_class: 'knowledge-check',
        title_number: number
      )
    end
  end

  # References
  BakeFootnotes.v1(book: book, selector: '.reference')

  book.chapters.each do |chapter|
    BakeChapterReferences.v4(
      chapter: chapter,
      metadata_source: ,
      klass: 'references'
    )
  end

  # Notes
  notes = %w[marketing-practice companies-conscience link-to-learning]
  BakeAutotitledNotes.v1(book: book, classes: notes, options: { cases: true })
  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[marketing-dashboard],
    options: { bake_exercises: true, cases: true }
  )

  BakeEquations.v1(book: book)
  BakeIframes.v1(book: book)
  BakeFootnotes.v1(book: book, number_format: :roman, selector: ':not(.reference)')
  BakeIndex.v1(book: book, types: %w[name term foreign], uuid_prefix: '.')
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeUnitPageTitle.v1(book: book)
  BakeToc.v1(book: book, options: { cases: true })
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinkPlaceholders.v1(book: book, cases: true)
end
PL_U_PHYSICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :pluphysics) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash
  book.search('.check-understanding strong').trash

  BakePreface.v1(book: book)

  BakeChapterTitle.v1(book: book, cases: true)
  BakeUnitTitle.v1(book: book)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives,
      bake_chapter_outline: true,
      block_target_label: true,
      cases: true
    }
  )

  # Notes
  notes = %w[media-2 problem-solving]
  BakeAutotitledNotes.v1(book: book, classes: notes, options: { cases: true })
  BakeUnclassifiedNotes.v1(book: book)
  BakeNumberedNotes.v1(book: book, classes: %w[check-understanding], options: { cases: true })

  solutions_container = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter, options: { cases: true })
    BakeLearningObjectives.v1(chapter: chapter)

    # EOC
    eoc_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'key-equations',
      uuid_key: '.key-equations',
      section_selector: 'section.key-equations',
      append_to: eoc_wrapper
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    sections_with_links = %w[key-concepts review-conceptual-questions review-problems]

    sections_with_links.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: eoc_wrapper,
        wrap_section: true, wrap_content: true
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page), title_tag: 'h4')
        section.prepend(child: title)
      end
    end

    sections_without_links = %w[review-additional-problems review-challenge]
    sections_without_links.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: eoc_wrapper
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    exercise_selectors = 'section.review-conceptual-questions, section.review-problems, ' \
                         'section.review-additional-problems, section.review-challenge'
    chapter.search(exercise_selectors).exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter),
        options: { cases: true }
      )
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: solutions_container,
      options: { cases: true }
    )
    Kitchen::Directions::MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'check-understanding'
    )
    exercise_section_classes = %w[review-conceptual-questions review-problems
                                  review-additional-problems review-challenge]
    exercise_section_classes.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  book.search('div[data-type="solution"]').each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  book.search('div[data-type="problem"]').each do |problem|
    BakeFirstElements.v1(within: problem)
  end

  book.chapters.each do |chapter|
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
                           cases: true)
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3',
                     options: { cases: true })
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
                    cases: true)
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page,
                    number: appendix_letter,
                    options: {
                      block_target_label: true,
                      cases: true
                    }
    )

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}",
                           cases: true)
    end
  end

  BakeIframes.v1(book: book)
  BakeEquations.v1(book: book, cases: true)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book, types: %w[name term foreign], uuid_prefix: '.')
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeToc.v1(book: book, options: { cases: true })
  BakeLinkPlaceholders.v1(book: book, cases: true)
  BakeFolio.v1(book: book)
  BakeLinks.v1(book: book)
  BakeRexWrappers.v1(book: book)
end
PL_PSYCHOLOGY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :plpsychology) do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeListsWithPara.v1(book: book)

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true, block_target_label: true, cases: true
    }
  )

  BakeChapterTitle.v1(book: book, cases: true)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
                           cases: true)
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3',
                     options: { cases: true })
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
                    cases: true)
    end

    BakeNonIntroductionPages.v1(chapter: chapter, options: { block_target_label: true })

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: book., has_para: true)

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'summary',
      uuid_key: '.summary',
      section_selector: 'section.summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_with_exercise = %w[review-questions critical-thinking personal-application]
    eoc_with_exercise.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    selectors = 'section.review-questions, section.critical-thinking, section.personal-application'
    chapter.search(selectors).exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter),
        options: { suppress_solution_if: true, cases: true }
      )
    end
  end

  notes = %w[link-to-learning dig-deeper everyday-connection what-do-you-think connect-the-concepts]
  BakeAutotitledNotes.v1(book: book, classes: notes, options: { cases: true })

  BakeReferences.v2(book: book, metadata_source: book.)
  BakeIndex.v1(book: book, types: %w[name term foreign], uuid_prefix: '.')
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeToc.v1(book: book, options: { cases: true })
  BakeLinkPlaceholders.v1(book: book, cases: true)
  BakeFolio.v1(book: book)
  BakeLinks.v1(book: book)
  BakeRexWrappers.v1(book: book)
end
WORLD_HISTORY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :world_history) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(exercise: exercise)
  end

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives,
      bake_chapter_outline: true
    }
  )

  BakeUnitTitle.v1(book: book)

  book.chapters.each do |chapter|

    # Eoc sections
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_wrapper = ChapterReviewContainer.v1(
      chapter: chapter, metadata_source: , klass: 'assessments'
    )

    eoc_sections = %w[review-questions
                      check-understanding
                      reflection-questions
                      visual-questions
                      making-connections
                      thought-provokers
                      source-questions]

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: eoc_wrapper
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    # Bake both kinds of exercise
    chapter.composite_pages.search_with(Kitchen::ExerciseElementEnumerator,
                                        Kitchen::InjectedQuestionElementEnumerator)
           .each do |exercise|
      if exercise.instance_of?(Kitchen::ExerciseElement)
        BakeNumberedExercise.v1(
          exercise: exercise, number: exercise.count_in(:composite_page),
          options: { suppress_solution_if: true }
        )
      else
        BakeInjectedExerciseQuestion.v1(question: exercise,
                                        number: exercise.count_in(:composite_page))
      end
    end

    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end
  end

  BakeAutotitledNotes.v1(book: book, classes: %w[own-words
                                                 dueling-voices
                                                 beyond-book
                                                 past-present])

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[link-to-learning],
    options: { bake_subtitle: false }
  )

  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}")
    end
  end

  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
INTRO_BUSINESS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :intro_business) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  BakeChapterTitle.v1(book: book)

  BakeChapterIntroductions.v2(book: book)

  book.chapters.each do |chapter|

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_sections = %w[prep-workplace ethics-activity working-net critical-thinking hot-links]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
  end

  notes = %w[exploring-business-careers catching-spirit concept-check
             managing-change customer-satisfaction ethics-in-practice expanding-around-globe]
  BakeAutotitledNotes.v1(book: book, classes: notes)

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(
        table: table,
        number: "#{appendix_letter}#{table.count_in(:page)}"
      )
    end
  end

  BakeUnnumberedTables.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeReferences.v1(book: book, metadata_source: )
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
BUSINESS_ETHICS_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :business_ethics) \
do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  BakeIframes.v1(book: book)

  BakeChapterTitle.v1(book: book)

  BakeChapterIntroductions.v2(
    book: book, options: {
      strategy: :add_objectives, bake_chapter_outline: true
    }
  )

  answer_key = BookAnswerKeyContainer.v1(book: book, solutions_plural: false)

  book.chapters.each do |chapter|

    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    eoc_sections = %w[assessment-questions]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    BakeChapterReferences.v2(
      chapter: chapter,
      metadata_source: ,
      uuid_prefix: '.',
      klass: 'references'
    )

    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div[data-type="composite-page"]')
    )

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key,
      options: { solutions_plural: false }
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: { selectors: ['section.assessment-questions'] },
      chapter: chapter,
      append_to: answer_key_inner_container
    )
  end

  notes = %w[link-to-learning ethics-across real-world what-would]
  BakeAutotitledNotes.v1(book: book, classes: notes)

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}")
    end
  end

  AnswerKeyCleaner.v1(book: book)
  BakeFootnotes.v1(book: book, number_format: :roman)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
COLLEGE_PHYSICS_1E_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :college_physics) do |doc|
  include Kitchen::Directions

  book = doc.book

  book.chapters.each do |chapter|
    chapter.sections('$.problems-exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter),
        options: { suppress_solution_if: true }
      )
    end
    BakeLearningObjectives.v3(chapter: chapter)
  end

end
COLLEGE_PHYSICS_SHARED_RECIPE =
Kitchen::BookRecipe.new(
  book_short_name: :college_physics_recipe) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeUnclassifiedNotes.v1(book: book)
  BakeAutotitledNotes.v1(book: book, classes: %w[interactive])
  BakeIframes.v1(book: book)
  BakeMathInParagraph.v1(book: book)

  # Check Your Understanding exercises: titled unnumbered exercises
  book.exercises('$[data-element-type="check-understanding"]').each do |exercise|
    BakeAutotitledExercise.v2(exercise: exercise, title: I18n.t(:'check-understanding'))
  end

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    section_keys = %w[section-summary conceptual-questions problems-exercises]
    section_keys.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
        section.prepend(child: title)
      end
    end

    chapter.sections('$.conceptual-questions').exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter),
        options: { suppress_solution_if: true }
      )
      BakeFirstElements.v1(within: exercise)
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
    chapter.examples.each do |example|
      BakeExample.v1(
        example: example,
        number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
        title_tag: 'h3'
      )
    end
    chapter.tables.each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{appendix_letter}#{table.count_in(:page)}"
      )
    end
  end

  book.composite_pages.search('div[data-type="equation"]').each do |eq|
    eq.add_class('unnumbered')
  end
  BakeEquations.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
COLLEGE_SUCCESS_HS_DELETE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :hs_delete) do |doc|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('div.real-deal').each(&:trash)
  book.search('div.student-story').each(&:trash)
  book.search('section.family-friends').each(&:trash)
  book.search('section.checking-in').each(&:trash)

  book.chapters.each do |chapter|
    eoc_sections = %w[summary career-connection rethinking where-go]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
  end
end
COLLEGE_SUCCESS_SHARED_RECIPE =

Used in college success (bakes college-success and hs-college-success)

Kitchen::BookRecipe.new(
  book_short_name: :college_success) do |doc, _resources|
  include Kitchen::Directions

  book = doc.book

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[
      student-profile
      activity
      analysis-question
      what-students-say
      application
      get-connected
    ]
  )

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{appendix_letter}#{figure.count_in(:page)}"
      )
    end
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(
        table: table,
        number: "#{appendix_letter}#{table.count_in(:page)}"
      )
    end
  end

  # convert title tags
  book.sections('$[data-depth="3"]').each { |section| section.titles.first&.name = 'h5' }
  BakeUnnumberedTables.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
COMPUTER_SCIENCE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :computer_science) \
do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    page_summary: 'section.section-summary'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book, title_element: 'h1')
  BakeChapterIntroductions.v1(book: book)
  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(exercise: exercise)
  end
  BakeChapterTitle.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeUnitPageTitle.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[concepts-practice tech-everyday global-tech link-to-learning industry-spotlight]
  )

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[think-through],
    options: { bake_exercises: true }
  )

  BakeUnclassifiedNotes.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v2(chapter: chapter, add_title: false)
    BakeNonIntroductionPages.v1(chapter: chapter)

    # create Chapter Review EOC wrapper
    eoc_wrapper = ChapterReviewContainer.v1(chapter: chapter, metadata_source: )
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: , append_to: eoc_wrapper)
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary',
      append_to: eoc_wrapper
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end
    eoc_sections = %w[review-questions conceptual-questions practice-exercises
                      problem-set-a problem-set-b thought-provokers lab-assessments]

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: eoc_wrapper
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
      chapter.composite_pages.search("section.#{section_key}").injected_questions.each do |question|
        BakeInjectedExerciseQuestion.v1(
          question: question, number: question.count_in(:composite_page)
        )
      end
    end

    chapter.exercises('$.your-turn').each do |exercise|
      BakeAutotitledExercise.v1(exercise: exercise)
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeIframes.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ENTREPRENEURSHIP_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :entrepreneurship) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[
      are-you-ready
      what-can-do
      link-to-learning
      entrepreneur-in-action
      work-it-out
    ]
  )

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end
    eoc_sections = %w[review-questions discussion-questions case-questions]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
      chapter.sections("$.#{section_key}").exercises.each do |exercise|
        BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
      end
    end
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'suggested-resources',
      uuid_key: '.suggested-resources',
      section_selector: 'section.suggested-resources'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]
    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeFootnotes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
NURSING_EXTERNAL_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :nursing_external) \
do |doc, _resources|
  include Kitchen::Directions

  doc.selectors.override(
    reference: 'section.references'
  )
  book = doc.book
   = book.

  book.search('cnx-pi').trash

  # Your recipe code goes here
  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise
    )
  end

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v2(chapter: chapter, add_title: false)
    BakeNonIntroductionPages.v1(chapter: chapter)

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'chapter-summary',
      uuid_key: '.chapter-summary',
      section_selector: 'section.chapter-summary'
    )
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'section-summary',
      uuid_key: '.section-summary',
      section_selector: 'section.section-summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    sections_with_exercises = %w[review-questions suggested-reading]

    sections_with_exercises.each do |eoc_section|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: eoc_section,
        uuid_key: ".#{eoc_section}",
        section_selector: "section.#{eoc_section}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.search('section.review-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:chapter),
        options: { add_dot: true }
      )
      BakeFirstElements.v1(within: question)
    end

    chapter.pages.notes('$.unfolding-casestudy').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:chapter),
        options: { only_number_solution: false, add_dot: true }
      )
    end

    chapter.pages.notes('$.single-casestudy').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:chapter),
        options: { only_number_solution: false, add_dot: true }
      )
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )
    # Solutions from note
    Kitchen::Directions::MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'unfolding-casestudy'
    )
    Kitchen::Directions::MoveSolutionsFromNumberedNote.v1(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'single-casestudy'
    )
    # Solutions from other exercise sections
    Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
      within: chapter, append_to: answer_key_inner_container, section_class: 'review-questions'
    )
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeUnnumberedTables.v1(book: book)
  BakeTableColumns.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeReferences.v4(book: book, metadata_source: )
  BakeIframes.v1(book: book)
  BakeIndex.v1(book: book)
  BakeFolio.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeLinkPlaceholders.v1(book: book, replace_section_link_text: true)
  BakeUnitTitle.v1(book: book)
  BakeToc.v1(book: book)

  note_classes = %w[link-to-learning safety-alert clinical-tip health-alert healthy-people
                    trending-today culture-conversations theory-action special-considerations
                    black-box client-teaching practice-problems unfolding-casestudy
                    single-casestudy case-reflection]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)
  BakeCustomTitledNotes.v1(book: book, classes: %w[media-feature boxed-feature])
  # BakeCustomTitledNotes.v1(book: book, classes: %w[media-feature])
  BakeUnclassifiedNotes.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
NURSING_INTERNAL_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :nursing_internal) \
do |doc, _resources|
  include Kitchen::Directions

  doc.selectors.override(
    reference: 'section.references'
  )
  book = doc.book
   = book.

  book.search('cnx-pi').trash

  # Your recipe code goes here
  BakePreface.v1(book: book)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise
    )
  end

  answer_key = BookAnswerKeyContainer.v1(book: book)

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
                    )
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    # EOC
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'summary',
      uuid_key: '.summary',
      section_selector: 'section.summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    eoc_wrapper = ChapterReviewContainer.v1(
      chapter: chapter,
      metadata_source: 
    )

    sections_with_module_links = %w[review-questions check-understanding reflection-questions
                                    critical-thinking what-nurses-do competency-based]

    sections_with_module_links.each do |eoc_section|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: eoc_section,
        uuid_key: ".#{eoc_section}",
        section_selector: "section.#{eoc_section}",
        append_to: eoc_wrapper
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    BakeChapterReferences.v3(chapter: chapter, metadata_source: )

    # Exercises
    chapter.search('section.review-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.check-understanding').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.critical-thinking').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.competency-based').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.reflection-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    chapter.search('section.what-nurses-do').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end

    # Answer Key
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key
    )

    exercises = %w[review-questions check-understanding
                   reflection-questions critical-thinking
                   what-nurses-do competency-based]

    exercises.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  book.search('div[data-type="question-solution"]').each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  note_classes = %w[link-to-learning unfolding-casestudy rn-stories clinical-safety
                    cultural-context lifestage-context patient-conversations pharma-connections
                    legal-ethical multi-disciplinary clinical-judgment electronic-hr
                    psychosocial-considerations]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)

  # Appendix
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeUnitTitle.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
CONTEMPORARY_MATH_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :contemporary_math) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakePreface.v1(book: book)

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  AddInjectedExerciseId.v1(book: book)
  BakeUnclassifiedNotes.v1(book: book)
  note_classes =
    %w[people-mathematics who-knew tech-check check-point video work-out definition formula]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)
  BakeNumberedNotes.v1(book: book, classes: %w[your-turn], options: { bake_exercises: false })
  sections_with_unnumbered_tables_in_solutions = \
    'div.your-turn, section.section-exercises, section.chapter-review, section.chapter-test'
  book.search(sections_with_unnumbered_tables_in_solutions).solutions.each do |solution|
    solution.tables.each do |table|
      table.add_class('unnumbered')
    end
    solution.figures.each do |figure|
      figure.add_class('unnumbered')
    end
  end
  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(exercise: exercise)
  end
  answer_key = BookAnswerKeyContainer.v1(book: book)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    BakeChapterSectionExercises.v1(chapter: chapter, options: { trash_title: true })

    chapter.pages.sections('$.check-understanding').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end
    chapter.pages.search('section.section-exercises').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:page))
      BakeFirstElements.v1(within: question)
    end
    chapter.pages.search('section.chapter-review').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end
    chapter.pages.search('section.chapter-test').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
      BakeFirstElements.v1(within: question)
    end
    chapter.pages.notes('$.your-turn').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: question.count_in(:note),
        options: { only_number_solution: false }
      )
      BakeFirstElements.v1(within: question)
    end

    chapter_summary = \
      ChapterReviewContainer.v1(chapter: chapter, metadata_source: ,
                                klass: 'chapter-summary')
    eoc_sections = %w[key-terms key-concepts eoc-videos formula-review]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: chapter_summary,
        wrap_section: true, wrap_content: true
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
        section.prepend(child: title)
      end
    end
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'projects',
      uuid_key: '.projects',
      section_selector: 'section.projects',
      append_to: chapter_summary
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end
    eoc_with_exercise = %w[chapter-review chapter-test]
    eoc_with_exercise.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}",
        append_to: chapter_summary
      ) do |section|
        ChangeSubsectionTitleTag.v1(section: section)
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.search('div[data-type="exercise"]').each do |exercise|
      # Classes added: has-first-element
      BakeFirstElements.v1(within: exercise)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )
    # Bake solutions
    Kitchen::Directions::MoveSolutionsFromNumberedNote.v2(
      chapter: chapter, append_to: answer_key_inner_container, note_class: 'your-turn'
    )
    chapter.non_introduction_pages.each do |page|
      number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: page, append_to: answer_key_inner_container, section_class: 'section-exercises',
        title_number: number
      )
    end
    exercise_section_classes = %w[chapter-review chapter-test check-understanding]
    exercise_section_classes.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}",
                    label_class: 'figure-target-label')
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}",
                           label_class: 'table-target-label')
    end

    page.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{appendix_letter}#{example.count_in(:page)}",
                     title_tag: 'h3')
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeIframes.v1(book: book)
  BakeEquations.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ORGANIC_CHEMISTRY_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :organic_chemistry) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise,
      options: { alphabetical_multiparts: true, list_type: 'lower-alpha', add_brackets: true })
  end

  answer_key_wrapper = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'chemistry-matters',
      uuid_key: '.chemistry-matters',
      section_selector: 'section.chemistry-matters'
    )

    UseSectionTitle.v1(
      chapter: chapter,
      eoc_selector: '.os-chemistry-matters-container',
      section_selector: 'section.chemistry-matters'
    )

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'key-terms',
      uuid_key: '.key-terms',
      section_selector: 'section.key-terms'
    )

    BakeChapterKeyEquations.v1(chapter: chapter, metadata_source: )

    sections_without_subtitle = %w[summary summary-reactions]

    sections_without_subtitle.each do |eoc_section|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: eoc_section,
        uuid_key: ".#{eoc_section}",
        section_selector: "section.#{eoc_section}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: ,
                          klass: 'visualizing-chemistry')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: ,
                          klass: 'mechanism-problems')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: ,
                          klass: 'energy-reaction')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: ,
                          klass: 'additional-problems')
    MoveExercisesToEOC.v1(chapter: chapter, metadata_source: ,
                          klass: 'general-problems')
    BakeChapterSectionExercises.v1(
      chapter: chapter,
      options: {
        trash_title: true,
        create_title: false
      })

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'practice-scientific',
      uuid_key: '.practice-scientific',
      section_selector: 'section.practice-scientific'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'preview-carbonylchemistry',
      uuid_key: '.preview-carbonylchemistry',
      section_selector: 'section.preview-carbonylchemistry'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
    end

    exercise_selectors = 'section.section-exercises, section.visualizing-chemistry, ' \
                         'section.mechanism-problems, section.energy-reaction, ' \
                         'section.additional-problems, section.general-problems, ' \
                         'section.preview-carbonylchemistry'

    chapter.search(exercise_selectors).injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(
        question: question,
        number: "#{chapter.count_in(:book)}-#{question.count_in(:chapter)}",
        options: { problem_with_prefix: true }
      )
      BakeFirstElements.v1(within: question)
    end

    # Bake answer key sections
    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key_wrapper
    )
    chapter.non_introduction_pages.each do |page|
      page.search('div.os-eos.os-section-exercises-container').each do |section_wrapper|
        Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
          within: section_wrapper, append_to: answer_key_inner_container,
          section_class: 'section-exercises', options: { add_title: false }
        )
      end
    end
    %w[visualizing-chemistry additional-problems preview-carbonylchemistry].each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass,
        options: { add_title: false }
      )
    end
  end

  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
                           move_caption_on_top: true,
                           label_class: 'table-target-label')
    end

    chapter.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
                     title_tag: 'h3')
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
                    label_class: 'figure-target-label')
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{appendix_letter}#{figure.count_in(:page)}",
                    label_class: 'figure-target-label')
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{appendix_letter}#{table.count_in(:page)}",
                           move_caption_on_top: true,
                           label_class: 'table-target-label')
    end

    page.examples.each do |example|
      BakeExample.v1(example: example,
                     number: "#{appendix_letter}#{example.count_in(:page)}",
                     title_tag: 'div')
    end

    BakeAppendix.v1(page: page, number: appendix_letter, options: { add_title_label: false })
  end

  BakeUnnumberedTables.v1(book: book)

  book.search('div[data-type="question-solution"]').each do |solution|
    BakeFirstElements.v1(within: solution)
  end

  note_classes = %w[why-chapter chemistry-matters]
  BakeAutotitledNotes.v1(book: book, classes: note_classes)

  BakeCustomTitledNotes.v1(book: book, classes: %w[dedication-page])

  BakeUnclassifiedNotes.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  # flatten Chemistry Matters section
  book.first!('nav').search('ol.os-chapter').each do |toc_chapter|
    chemistry_matters_link = toc_chapter.first('li.os-toc-chapter-composite-page').first('a')
    chemistry_matters_link.replace_children(with:
      "<span class=\"os-text\">#{chemistry_matters_link.children.text.strip}</span>"
    )
  end
  BakeLinkPlaceholders.v1(book: book, replace_section_link_text: true)
  BakeFolio.v1(book: book, options: { new_approach: true })
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
POLITICAL_SCIENCE_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :political_science) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeUnitTitle.v1(book: book)
  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    # Eoc sections
    MoveCustomSectionToEocContainer.v1(
      chapter: chapter,
      metadata_source: ,
      container_key: 'summary',
      uuid_key: '.summary',
      section_selector: 'section.summary'
    ) do |section|
      RemoveSectionTitle.v1(section: section)
      title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
      section.prepend(child: title)
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    chapter.pages.search('section.review-questions').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:chapter))
    end

    eoc_sections = %w[review-questions suggested-readings]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    # Tables and figures
    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end
  end

  # Bake the notes
  autotitled_classes = %w[show-data connecting-courses meet-professional changing-political what-do
                          where-engage media-video media-podcast]
  BakeAutotitledNotes.v1(book: book, classes: autotitled_classes)

  BakeFootnotes.v1(book: book)
  BakeIframes.v1(book: book)

  # Eob sections
  BakeReferences.v1(book: book, metadata_source: , numbered_title: true)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PRECALCULUS_COREQ_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :precalculus_coreq) do |doc|
  include Kitchen::Directions

  book = doc.book

  book.chapters.pages.search('section.practice-perfect').exercises.each do |exercise|
    exercise.remove_class('material-set-2')
    exercise.add_class('os-coreq-exercises')
    BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:page))
    BakeFirstElements.v1(within: exercise)
    exercise.search('table').each do |table|
      table.add_class('os-coreq-element')
    end
  end

  book.pages.search('section.coreq-skills').each do |coreq_section|
    coreq_section.prepend(child:
      <<~HTML
        <h3 class="os-title">
          <span class="os-title-label">#{I18n.t(:'coreq-skills')}</span>
        </h3>
      HTML
    )
    coreq_section.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table, number: table.count_in(:page))
    end
    coreq_section.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: figure.count_in(:page))
    end
    coreq_section.examples.each do |example|
      BakeExample.v1(example: example, number: example.count_in(:page), title_tag: 'h3')
    end
  end
end
COLLEGE_PHYSICS_2E_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :college_physics_2e_delete) \
do |doc|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('section.ap-test-prep').each(&:trash)

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    chapter.sections('$.authentic-assessment').each do |section|
      section.prepend(child:
        <<~HTML
          <h3 data-type="title">#{I18n.t(:"exercises.authentic-assessment")}</h3>
        HTML
      )
      section.exercises.each do |exercise|
        BakeNumberedExercise.v1(
          exercise: exercise, number: exercise.count_in(:section))
        BakeFirstElements.v1(within: exercise)
      end
    end

    chapter.sections('$.problems-exercises').exercises.each do |exercise|
      BakeNumberedExercise.v1(
        exercise: exercise, number: exercise.count_in(:chapter))
      BakeFirstElements.v1(within: exercise)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )

    exercise_section_classes = %w[problems-exercises]
    exercise_section_classes.each do |klass|
      MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass
      )
    end
  end

  BakeCompositeChapters.v1(book: book)
  # Some target labels are created in this stage, but many won't be, so we silence the warning
  silenced do
    BakeLinkPlaceholders.v1(book: book)
  end
end
COLLEGE_SUCCESS_HIGH_SCHOOL_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :hs_college_success) \
do |doc|
  include Kitchen::Directions

  book = doc.book
   = book.

  book.search('cnx-pi').trash

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[
      real-deal
      student-story
    ]
  )

  book.chapters.each do |chapter|
    eoc_sections = %w[family-friends summary checking-in]
    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
  end
end
AMERICAN_GOVERNMENT_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :american_gov) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakePreface.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v2(
    book: book,
    options: {
      strategy: :add_objectives,
      bake_chapter_outline: true,
      introduction_order: :v2
    }
  )
  BakeUnclassifiedNotes.v1(book: book)
  BakeUnnumberedFigure.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: )
    BakeNonIntroductionPages.v1(chapter: chapter)

    exercise_section_classes = %w[review-questions critical-thinking]

    chapter.search(exercise_section_classes.prefix('section.')).exercises.each do |exercise|
      BakeNumberedExercise.v1(exercise: exercise, number: exercise.count_in(:chapter))
    end

    exercise_section_classes.each do |klass|
      MoveExercisesToEOC.v1(chapter: chapter, metadata_source: , klass: klass)
    end

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter, metadata_source: , append_to: answer_key
    )

    DefaultStrategyForAnswerKeySolutions.v1(
      strategy_options: { selectors: ['section.review-questions'] },
      chapter: chapter,
      append_to: answer_key_inner_container
    )

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(
        figure: figure,
        number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}"
      )
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}"
      )
    end
  end

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(
        table: table,
        number: "#{appendix_letter}#{table.count_in(:page)}"
      )
    end

    page.examples.each do |example|
      BakeExample.v1(
        example: example,
        number: "#{appendix_letter}#{example.count_in(:page)}",
        title_tag: 'div'
      )
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[link-to-learning
                middle-ground
                milestone
                get-connected
                insider-perspective]
  )

  BakeScreenreaderSpans.v1(book: book)
  BakeSuggestedReading.v1(book: book)
  BakeReferences.v1(book: book, metadata_source: )
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
ENGLISH_COMPOSITION_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :english_composition) \
do |doc, _resources|
  include Kitchen::Directions

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakeUnnumberedFigure.v1(book: book)
  BakePreface.v1(book: book)
  BakeHandbook.v1(book: book)

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)
  BakeUnitTitle.v1(book: book)
  BakeUnitPageTitle.v1(book: book)

  BakeAnnotationClasses.v1(book: book)

  # Bake EoC sections
  eoc_sections = %w[further-reading works-cited works-consulted]
  eoc_sections.each do |section_key|
    book.chapters.each do |chapter|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end
  end

  book.chapters.each do |chapter|
    chapter.pages.search('section').injected_questions.each do |question|
      BakeInjectedExerciseQuestion.v1(question: question, number: question.count_in(:section))
    end
    BakeLearningObjectives.v1(chapter: chapter)

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")

    end
  end

  book.pages('$.handbook').each do |page|
    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table,
                           number: "H#{table.count_in(:page)}")
    end
  end

  BakeScreenreaderSpans.v1(book: book)
  BakeIframes.v1(book: book)
  BakeStepwise.v1(book: book)
  BakeUnnumberedTables.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeToc.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)

  # Bake Custom Sections
  custom_sections_properties = {
    narrative_trailblazer: {
      class: 'narrative-trailblazer',
      inject: 'title'
    },
    living_words: {
      class: 'living-words',
      inject: 'subtitle'
    },
    quick_launch: {
      class: 'quick-launch',
      inject: 'title_prefix'
    },
    drafting: {
      class: 'drafting',
      inject: 'title_prefix'
    },
    peer_review: {
      class: 'peer-review',
      inject: 'title_prefix'
    },
    revising: {
      class: 'revising',
      inject: 'title_prefix'
    }
  }
  book.chapters.each do |chapter|
    BakeCustomSections.v1(
      chapter: chapter,
      custom_sections_properties: custom_sections_properties
    )
  end
end
LIFESPAN_DEVELOPMENT_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :lifespan_development) \
do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    reference: 'section.references'
  )

  book = doc.book

  book.search('cnx-pi').trash
   = book.

  BakePreface.v1(book: book)

  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  AddInjectedExerciseId.v1(book: book)
  book.injected_exercises.each do |exercise|
    BakeInjectedExercise.v1(
      exercise: exercise
    )
  end

  BakeChapterTitle.v1(book: book)
  BakeChapterIntroductions.v1(book: book)

  answer_key = BookAnswerKeyContainer.v1(book: book)

  book.chapters.each do |chapter|
    BakeNonIntroductionPages.v1(chapter: chapter)

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end

    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )

    sections_with_module_links = %w[summary references]

    sections_with_module_links.each do |eoc_section|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: eoc_section,
        uuid_key: ".#{eoc_section}",
        section_selector: "section.#{eoc_section}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
        title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
        section.prepend(child: title)
      end
    end

    sections_with_exercises = %w[review-questions check-understanding reflection-questions
                                 media-questions thought-provokers case-study]

    sections_with_exercises.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    BakeAllNumberedExerciseTypes.v1(
      within: chapter.search('div[data-type="composite-page"]')
    )

    answer_key_inner_container = AnswerKeyInnerContainer.v1(
      chapter: chapter,
      metadata_source: ,
      append_to: answer_key
    )

    sections_with_exercises.each do |klass|
      Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
        within: chapter, append_to: answer_key_inner_container, section_class: klass,
        options: { add_title: false }
      )
    end
  end

  # Appendix
  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end
    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  notes = %w[link-to-learning what-heard it-depends intersections-contexts life-hacks]
  BakeAutotitledNotes.v1(book: book, classes: notes)

  BakeIndex.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end
PRINCIPLES_MANAGEMENT_RECIPE =
Kitchen::BookRecipe.new(book_short_name: :principles_management) \
do |doc, _resources|
  include Kitchen::Directions

  # Set overrides
  doc.selectors.override(
    page_summary: 'section.section-summary'
  )

  book = doc.book
   = book.

  # Some stuff just goes away
  book.search('cnx-pi').trash

  BakePreface.v1(book: book, title_element: 'h1')
  BakeChapterIntroductions.v2(book: book)
  BakeChapterTitle.v1(book: book)

  BakeAutotitledNotes.v1(
    book: book,
    classes: %w[exploring-manager-careers concept-check
                sustainability-responsible managerial-leadership
                ethics-in-practice managing-change
                catching-spirit expanding-around-globe customer-satisfaction]
  )

  BakeReferences.v1(book: book, metadata_source: )

  book.chapters.each do |chapter|
    BakeLearningObjectives.v1(chapter: chapter)
    BakeNonIntroductionPages.v1(chapter: chapter)
    BakeChapterGlossary.v1(chapter: chapter, metadata_source: )
    BakeChapterSummary.v1(chapter: chapter, metadata_source: , klass: 'section-summary')

    BakeChapterReferences.v1(chapter: chapter, metadata_source: )

    eoc_sections = %w[section-summary chapter-review manage-skills
                      manage-exercises critical-thinking]

    eoc_sections.each do |section_key|
      MoveCustomSectionToEocContainer.v1(
        chapter: chapter,
        metadata_source: ,
        container_key: section_key,
        uuid_key: ".#{section_key}",
        section_selector: "section.#{section_key}"
      ) do |section|
        RemoveSectionTitle.v1(section: section)
      end
    end

    chapter.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure,
                    number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
    end

    chapter.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v2(table: table,
                           number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
    end
  end

  BakeUnnumberedFigure.v1(book: book)
  BakeUnnumberedTables.v1(book: book)

  book.pages('$.appendix').each do |page|
    appendix_letter = [*('A'..'Z')][page.count_in(:book) - 1]

    page.figures(only: :figure_to_number?).each do |figure|
      BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
    end

    page.tables('$:not(.unnumbered)').each do |table|
      BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
    end

    BakeAppendix.v1(page: page, number: appendix_letter)
  end

  BakeMathInParagraph.v1(book: book)
  BakeIndex.v1(book: book)
  BakeCompositePages.v1(book: book)
  BakeFootnotes.v1(book: book)
  BakeCompositeChapters.v1(book: book)
  BakeToc.v1(book: book)
  BakeLinkPlaceholders.v1(book: book)
  BakeFolio.v1(book: book)
  BakeRexWrappers.v1(book: book)
  BakeLinks.v1(book: book)
end

Instance Method Summary collapse

Instance Method Details

#file_glob(relative_folder_and_extension) ⇒ Object



12
13
14
# File 'lib/imports_for_recipes.rb', line 12

def file_glob(relative_folder_and_extension)
  Dir[File.expand_path("#{__dir__}/#{relative_folder_and_extension}")]
end

#require_all(relative_folder, file_matcher = '**/*.rb') ⇒ Object



16
17
18
# File 'lib/imports_for_recipes.rb', line 16

def require_all(relative_folder, file_matcher='**/*.rb')
  file_glob(relative_folder + "/#{file_matcher}").each { |f| require f }
end

#silencedObject

Takes a block and silences any ‘puts` from that block



8
9
10
11
12
13
14
# File 'lib/recipes/recipes_helper.rb', line 8

def silenced
  $stdout = StringIO.new

  yield
ensure
  $stdout = STDOUT
end