diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f6d1ada2..535cac2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix `index` to not generate empty module * Add dots to letter answers in `data-science` +* Add `BakeEmbeddedExerciseQuestion` for baking exercise-like things +* Bake ordered lists as embedded exercise questions in `computer-science` ## [v2.23.0] - 2024-09-09 diff --git a/lib/kitchen/directions/bake_embedded_exercise_question.rb b/lib/kitchen/directions/bake_embedded_exercise_question.rb new file mode 100644 index 000000000..63c15d187 --- /dev/null +++ b/lib/kitchen/directions/bake_embedded_exercise_question.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Kitchen + module Directions + module BakeEmbeddedExerciseQuestion + def self.v1(question:, number:, append_to:) + append_to.append(child: + <<~HTML +
+
+ #{number} + . +
#{question.cut.paste}
+
+
+ HTML + ) + end + end + end +end diff --git a/lib/recipes/computer-science/recipe.rb b/lib/recipes/computer-science/recipe.rb index 20818b850..9cde821c0 100644 --- a/lib/recipes/computer-science/recipe.rb +++ b/lib/recipes/computer-science/recipe.rb @@ -57,6 +57,25 @@ title = EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page)) section.prepend(child: title) end + + # Convert lab numbered lists to a series of exercise questions + lab_item_number = 1 + chapter.search('section.labs-assessments').each do |lab| + ordered_lists = lab.search('> ol') + next unless ordered_lists.any? + + ordered_lists.each do |list| + list.search('> li').each do |item| + item.name = 'span' + BakeEmbeddedExerciseQuestion.v1( + question: item, number: lab_item_number, append_to: list + ) + lab_item_number += 1 + end + list.name = 'span' + end + end + eoc_sections = %w[review-questions conceptual-questions practice-exercises problem-set-a problem-set-b thought-provokers labs-assessments] diff --git a/spec/kitchen_spec/directions/bake_embedded_exercise_question_spec.rb b/spec/kitchen_spec/directions/bake_embedded_exercise_question_spec.rb new file mode 100644 index 000000000..5d32c1e8d --- /dev/null +++ b/spec/kitchen_spec/directions/bake_embedded_exercise_question_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Kitchen::Directions::BakeEmbeddedExerciseQuestion do + let(:book_with_question) do + book_containing(html: + one_chapter_with_one_page_containing( + <<~HTML +
+
Question
+
+ HTML + ) + ) + end + + context 'when question and number provided' do + it 'bakes' do + section = book_with_question.search('section').first! + question = section.search('div').first! + described_class.v1(question: question, number: 1, append_to: section) + expect(book_with_question.pages.first).to match_snapshot_auto + end + end +end diff --git a/spec/recipes_spec/books/computer-science/expected_output.xhtml b/spec/recipes_spec/books/computer-science/expected_output.xhtml index fe99c112f..e461e898e 100644 --- a/spec/recipes_spec/books/computer-science/expected_output.xhtml +++ b/spec/recipes_spec/books/computer-science/expected_output.xhtml @@ -134,6 +134,11 @@ Thought Provokers +
  • + + Labs + +
  • @@ -147,8 +152,8 @@ Basic Functions We Expect Could Appear in Any Appendix -
  • - +
  • + Index
  • @@ -3058,6 +3063,130 @@ The amounts in raw material, work in process, and finished goods inventory maint +
    +

    + Labs +

    +
    +

    Labs

    + +
    + By: + + Edited by: + + Illustrated by: + + Translated by: + +
    +
    + Published By: +
    +
    + +

    + Licensed: + CC BY +

    +
    +
    Science and Technology
    +
    +
    + +
    +
    + 1 + . +
    + a +
    +
    +
    +
    +
    + 2 + . +
    + b +
    +
    +
    +
    +
    + 3 + . +
    + c +
    +
    +
    +
    +
    +
    + +
    +
    + 4 + . +
    + +
      +
    • d
    • +
    +
    +
    +
    +
    +
    +
    + 5 + . +
    + +
      +
    1. e
    2. +
    +
    +
    +
    +
    +
    +
    + 6 + . +
    + f +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +
    @@ -3330,7 +3459,7 @@ Three temperature scales are in general use:

    On the Fahrenheit scale, the difference between the freezing and boiling points of water is 180 degrees. Thus, to convert Celsius degrees or Kelvins to Fahrenheit degrees, it is necessary to multiply by 180/100 = 9/5. To convert from Fahrenheit degrees to Celsius degrees or Kelvins, it is necessary to multiply by 100/180 = 5/9.

    -
    +

    Index

    diff --git a/spec/recipes_spec/books/computer-science/input.xhtml b/spec/recipes_spec/books/computer-science/input.xhtml index 594fc291e..5ab347429 100644 --- a/spec/recipes_spec/books/computer-science/input.xhtml +++ b/spec/recipes_spec/books/computer-science/input.xhtml @@ -1642,6 +1642,37 @@ The amounts in raw material, work in process, and finished goods inventory maint
    +

    Assessment: Labss

    +
      +
    1. a
    2. +
    3. b
    4. +
    5. c
    6. +
    +
    + +

    Assessment: Labss

    +
      +
      • d
    1. +
      1. e
    2. +
    3. f
    4. +
    +
    + +

    Assessment: Labss

    + +
    + +

    Assessment: Labss

    + +

    Glossary

    diff --git a/spec/snapshots/Kitchen_Directions_BakeEmbeddedExerciseQuestion_when_question_and_number_provided_bakes.snap b/spec/snapshots/Kitchen_Directions_BakeEmbeddedExerciseQuestion_when_question_and_number_provided_bakes.snap new file mode 100644 index 000000000..bfc76f00f --- /dev/null +++ b/spec/snapshots/Kitchen_Directions_BakeEmbeddedExerciseQuestion_when_question_and_number_provided_bakes.snap @@ -0,0 +1,13 @@ +
    +
    + +
    +
    + 1 + . +
    Question
    +
    +
    +
    + +
    \ No newline at end of file